var CurrentSection = 0;
var CurrentTab = 1;
var TotalTabs = 0;
var IsRotating = false;
var IsSwitchingSection = false;

function swapLogo() {
var numimages=4;
rndimg = new Array("/Branches/Victoria%20BID/inSW1/Files/images/headers/inSW1_Header1.jpg", "/Branches/Victoria%20BID/inSW1/Files/images/headers/inSW1_Header2.jpg", "/Branches/Victoria%20BID/inSW1/Files/images/headers/inSW1_Header3.jpg", "/Branches/Victoria%20BID/inSW1/Files/images/headers/inSW1_Header4.jpg"); 
x=(Math.floor(Math.random()*numimages));
randomimage=(rndimg[x]);
if(!($("#eform_237").length > 0))
{
      document.getElementById("containerheader").style.backgroundImage = "url("+ randomimage +")"; 
}
}

function NextRotate() {
  // Simple semaphore function for disabling section tabs
  // when auto-rotating. Otherwise collision of jQuery effects
  if(TotalTabs > 0) {
    if(CurrentTab < TotalTabs) {
      Rotate((parseInt(CurrentTab))+1);
    }
    else {
      Rotate(1);
    }
  }
  setTimeout("NextRotate()", 10000);
}

function Rotate(Rel) {
  if(IsRotating) {
    return false;
  }
  IsRotating = true;
  $(".HomepageRotatorLink[rel='"+CurrentTab+"']").removeClass("selected");
    $(".HomepageRotatorLink[rel='"+Rel+"']").addClass("selected");
        var ThisRel = Rel;
        $("#FaderImage").fadeOut("fast", function() {
      if($("#Fader_" + CurrentSection + "_" + CurrentTab).size() > 0) {
        $("#Fader_" + CurrentSection + "_" + CurrentTab).fadeOut(function () {
          $("#FaderImage").attr("src", "");
          $("#FaderImage").attr("alt", "");
          $("#FaderImage").attr("title", "");
          $("#FaderImage").attr("src", $("#Fader_" + CurrentSection + "_" + ThisRel).attr("rel"));
          $("#FaderImage").attr("alt", $("#Fader_" + CurrentSection + "_" + ThisRel).attr("rel2"));
          $("#FaderImage").attr("title", $("#Fader_" + CurrentSection + "_" + ThisRel).attr("rel2"));
          $("#Fader_" + CurrentSection + "_" + ThisRel).fadeIn();
          $("#FaderImage").fadeIn("fast", function() { IsRotating = false; });
          CurrentTab = ThisRel;
        });
      }
      else {
        $("#FaderImage").attr("src", "");
        $("#FaderImage").attr("alt", "");
        $("#FaderImage").attr("title", "");
        $("#FaderImage").attr("src", $("#Fader_" + CurrentSection + "_" + ThisRel).attr("rel"));
        $("#FaderImage").attr("alt", $("#Fader_" + CurrentSection + "_" + ThisRel).attr("rel2"));
        $("#FaderImage").attr("title", $("#Fader_" + CurrentSection + "_" + ThisRel).attr("rel2"));
        $("#Fader_" + CurrentSection + "_" + ThisRel).fadeIn();
        $("#FaderImage").fadeIn("fast", function() { IsRotating = false; });
        CurrentTab = ThisRel;
      }
    });
}

function MonthName(month) {
  switch(month) {
    case 0: return "January";
    case 1: return "February";
    case 2: return "March";
    case 3: return "April";
    case 4: return "May";
    case 5: return "June";
    case 6: return "July";
    case 7: return "August";
    case 8: return "September";
    case 9: return "October";
    case 10: return "November";
    case 11: return "December";
  }
}

// Handles Homepage - Rotator object
$(document).ready(function () {

  // Economic Report updates June 2011
  var d = new Date();
  //$(".economicMonth").text(MonthName(d.getMonth()-1));
  //$(".economicYear").text(d.getFullYear());
  
  // Countdown to Diamond Jubilee
  var DjHtml = "<div class=\"dj-countdownboxticker\">";
  DjHtml += "<span class=\"value\">%{d}</span><br /><span class=\"label\">Days</span>";
  DjHtml += "</div>";
  DjHtml += "<div class=\"dj-countdownbullet\"></div>";
  DjHtml += "<div class=\"dj-countdownboxticker\">";
  DjHtml += "<span class=\"value\">%{h}</span><br /><span class=\"label\">Hours</span>";
  DjHtml += "</div>";
  DjHtml += "<div class=\"dj-countdownbullet\"></div>";
  DjHtml += "<div class=\"dj-countdownboxticker\">";
  DjHtml += "<span class=\"value\">%{m}</span><br /><span class=\"label\">Mins</span>";
  DjHtml += "</div>";
  DjHtml += "<div class=\"dj-countdownbullet\"></div>";
  DjHtml += "<div class=\"dj-countdownboxticker\">";
  DjHtml += "<span class=\"value\">%{s}</span><br /><span class=\"label\">Secs</span>";
  DjHtml += "</div>";
  DjHtml += "<div style=\"clear: both;\"></div>";

  $("#djCountdown").countdown({
    date: 'June 2, 2012 01:00',
    updateTime: 1000,
    htmlTemplate: DjHtml,
    minus: false
  });

  $("#olympicCountdown").countdown({
    date: 'July 27, 2012 01:00',
    updateTime: 1000,
    htmlTemplate: DjHtml,
    minus: false
  });
  
  $("#paralympicCountdown").countdown({
    date: 'August 29, 2012 01:00',
    updateTime: 1000,
    htmlTemplate: DjHtml,
    minus: false
  });
  
  setTimeout("NextRotate()", 10000);
  
  //swap header image
  swapLogo();
  
    $(".bannerlist").first().fadeIn();
    $("#FaderImage").attr("src", $("div[id^=Fader_]").first().attr("rel"));
  $("#FaderImage").attr("alt", $("div[id^=Fader_]").first().attr("rel2"));
  $("#FaderImage").attr("title", $("div[id^=Fader_]").first().attr("rel2"));
    $("div[id^=Fader_]").first().fadeIn();
  $(".HomepageRotatorLink").first().addClass("selected");

    CurrentSection = $(".HomepageRotatorSectionLink").first().attr("rel");
  TotalTabs = $(".LinkList"+CurrentSection+" .HomepageRotatorLink").size();
  $(".HomepageRotatorSectionLink").first().addClass("selected");

    // Fade in separate sections on homepage rotator
    // News & Events, Images, Videos, etc.
    $(".HomepageRotatorSectionLink").click(function () {
    if(IsSwitchingSection) {
      return false;
    }
    if(IsRotating) {
      return false;
    }
    IsSwitchingSection = true;
    $(".HomepageRotatorLink").removeClass("selected");
    $(".LinkList" + $(this).attr("rel") + " .HomepageRotatorLink").first().addClass("selected");
  
    // Mark the new tab as selected
    $(".HomepageRotatorSectionLink[rel='"+CurrentSection+"']").removeClass("selected");
    $(this).addClass("selected");
    
        // Fade out the old section
        var ThisRel = $(this).attr("rel");
        $("div[id^=Fader_" + CurrentSection + "_]").fadeOut();
        $("#FaderImage").fadeOut();
    $("#Fader_" + CurrentSection + "_" + CurrentTab).fadeOut();
        $(".LinkList" + CurrentSection).fadeOut(function () {
            $("#FaderImage").attr("src", "");
      $("#FaderImage").attr("alt", "");
      $("#FaderImage").attr("title", "");
            $("#FaderImage").attr("src", $("div[id^=Fader_" + ThisRel + "_]").first().attr("rel"));
      $("#FaderImage").attr("alt", $("div[id^=Fader_" + ThisRel + "_]").first().attr("rel2"));
      $("#FaderImage").attr("title", $("div[id^=Fader_" + ThisRel + "_]").first().attr("rel2"));
            $("#FaderImage").fadeIn();
            $(".LinkList" + ThisRel).fadeIn();
            $("div[id^=Fader_" + ThisRel + "_]").first().fadeIn();
            CurrentTab = 1;
      IsSwitchingSection = false;
        });
        // Set the current section to the selected one
        CurrentSection = ThisRel;
    TotalTabs = $(".LinkList"+CurrentSection+" .HomepageRotatorLink").size();
    
    return false;
    });

    // Fade in separate news items within rotator
    // (Content Items, etc)
    $(".HomepageRotatorLink").click(function () {
    Rotate($(this).attr("rel"));
    
    return false;
    });
});

$(document).ready(function() {
  $(".homepagetranslated").first().fadeIn();
  $(".homepagetranslated").first().addClass("selected");
  $(".contentbannerlanguages ul li a").first().addClass("selected");
  
  $(".contentbannerlanguages ul li a").click(function() {
    $(".contentbannerlanguages ul li a[class$='selected']").removeClass("selected");
    $(this).addClass("selected");
    var ThisRel = $(this).attr("rel");
    $(".homepagetranslated[class='homepagetranslated selected']").fadeOut(function() {
      $(this).removeClass("selected");
      $(".homepagetranslated[rel='"+ThisRel+"']").addClass("selected");
      $(".homepagetranslated[rel='"+ThisRel+"']").fadeIn();
    });
    return false;
  });
});

    $(document).ready(function() {
  $(".selected > .selected > a").attr({href : "javascript:;"});
  
     /* $(".eventsBox").hover(
  function(){
    $('#eventText').fadeIn(200);
  },
  function(){
    $('#eventText').fadeOut(200);
  });

  $(".stayingBox").hover(
  function(){
    $('#stayingText').fadeIn(200);
  },
  function(){
    $('#stayingText').fadeOut(200);
  });

  $(".shoppingBox").hover(
  function(){
    $('#shoppingText').fadeIn(200);
  },
  function(){
    $('#shoppingText').fadeOut(200);
  });

  $(".funBox").hover(
  function(){
    $('#funText').fadeIn(200);
  },
  function(){
    $('#funText').fadeOut(200);
  });

  $(".visitorBox").hover(
  function(){
    $('#visitorText').fadeIn(200);
  },
  function(){
    $('#visitorText').fadeOut(200);
  });

  $(".businessBox").hover(
  function(){
    $('#businessText').fadeIn(200);
  },
  function(){
    $('#businessText').fadeOut(200);
  });*/
  
  $(".contentbox").hover(
  function(){
    $(this).children('.hoverText').slideDown('slow');
    
  },
  function(){
    $(this).children('.hoverText').slideUp('slow');
  });
     
   
  $("ul.selected").click(function(){
    if ($(".sidebarsubmenu").css("display") != "none") 
    {
      $("ul.selected + ul").hide("slow");
      $("ul.selected a").css("background", "url('./branches/victoria bid/insw1/files/images/buttons/arrow-right.gif') no-repeat scroll left center transparent");
    }
    if ($(".sidebarsubmenu").css("display") == "none") 
    {
                $("ul.selected + ul").show("slow");
          $("ul.selected a").css("background", "url('./branches/victoria bid/insw1/files/images/buttons/arrow-down.gif') no-repeat scroll left center transparent");
        }    
    });
    });
  

  
function mailpage()
{
mail_str = "mailto:?subject=Check out the " + document.title;
mail_str += "&body=I thought you might be interested in the " + document.title;
mail_str += ". You can view it at, " + location.href;
location.href = mail_str;
}


// !Temporary hack for Register box on Special Offers page!
$(document).ready(function() {
  $(".offers .SummaryContent span").removeClass("InControlContent");
});

// Press Lightbox
$(document).ready(function() {
  $("#safesecure_gallery a").lightBox({
  imageLoading: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-ico-loading.gif',
  imageBtnClose: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-close.gif',
  imageBtnPrev: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-prev.gif',
  imageBtnNext: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-next.gif'
  });
  
  $("#cleangreen_gallery a").lightBox({
  imageLoading: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-ico-loading.gif',
  imageBtnClose: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-close.gif',
  imageBtnPrev: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-prev.gif',
  imageBtnNext: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-next.gif'
  });
  
  $("#visitor_gallery a").lightBox({
  imageLoading: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-ico-loading.gif',
  imageBtnClose: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-close.gif',
  imageBtnPrev: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-prev.gif',
  imageBtnNext: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-next.gif'
  });
  
  $("#prosperous_gallery a").lightBox({
  imageLoading: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-ico-loading.gif',
  imageBtnClose: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-close.gif',
  imageBtnPrev: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-prev.gif',
  imageBtnNext: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-next.gif'
  });
  
  $("#showcase_gallery a").lightBox({
  imageLoading: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-ico-loading.gif',
  imageBtnClose: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-close.gif',
  imageBtnPrev: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-prev.gif',
  imageBtnNext: '/Branches/Victoria BID/inSW1/Files/Images/lightbox-btn-next.gif'
  });

});

//$(document).ready(function(){
  //$("#economicsales .ffstat").html('&nbsp');
  //$("#economicsales .fffooter").html('Sales figures will be published soon');
  //$("#ContentHolder73336").prepend("<h2 class='botm-title'>Footfall and Sales Figures</h2>");
  //$(".botm-title").css("margin-top", "15px");  
//});

$(document).ready(function() {
	$(".choir-submitbutton a").click(function() {
		$("#eform_177 .eform_button input").click();
	});
	$(".shine-submitbutton a").click(function() {
		$("#eform_178 .eform_button input").click();
	});
	$(".shine-submitbutton a").click(function() {
		$("#eform_179 .eform_button input").click();
	});
	if($(".choirContainer .successmessage").length) {
		$(".choir-submitbutton").addClass("choir-submitfiller");
	}
	if($(".shineContainer .successmessage").length) {
		$(".shine-submitbutton").css("visibility", "hidden");
	}
	$("#eform_179 input").keypress(function(e) {
		if (e.keyCode == '13') {
			$("#eform_179 .eform_button input").click();
			e.preventDefault();
		} 
	});
	$("#eform_178 input").keypress(function(e) {
		if (e.keyCode == '13') {
			$("#eform_178 .eform_button input").click();
			e.preventDefault();
		} 
	});
	$("#eform_177 input").keypress(function(e) {
		if (e.keyCode == '13') {
			$("#eform_177 .eform_button input").click();
			e.preventDefault();
		} 
	});
});
