$(function() {
	// GLOBAL PANEL SCRIPTS
	$("a.globalNetwork").toggle(function() {
		$(this).addClass("globalOpen");
		$("div.globalBox").animate( { marginTop: "0" }, { duration: 500, easing: 'easeOutSine' });
	}, function() {
		$(this).removeClass("globalOpen");
        $("div.globalBox").animate( { marginTop: "-355px" }, { duration: 500, easing: 'easeOutSine' });
    });	
	$("a.tabGlobal").click(function() {
		$(this).parent("li").removeClass("region").addClass("active");
		$(this).parent("li").siblings(".active").removeClass("active").addClass("region");
		$(".locsAustralia, .locsNewzealand, .locsUnitedkingdom, .locsUnitedstates").hide();
		$(".locsGlobal").fadeIn("fast");
	});
	$("a.tabAustralia").click(function() {
		$(this).parent("li").removeClass("region").addClass("active");
		$(this).parent("li").siblings(".active").removeClass("active").addClass("region");
		$(".locsGlobal, .locsNewzealand, .locsUnitedkingdom, .locsUnitedstates").hide();
		$(".locsAustralia").show("slow");		
	});
	$("a.tabNewzealand").click(function() {
		$(this).parent("li").removeClass("region").addClass("active");
		$(this).parent("li").siblings(".active").removeClass("active").addClass("region");
		$(".locsGlobal, .locsAustralia, .locsUnitedkingdom, .locsUnitedstates").hide();
		$(".locsNewzealand").show("slow");
	});
	$("a.tabUnitedkingdom").click(function() {
		$(this).parent("li").removeClass("region").addClass("active");
		$(this).parent("li").siblings(".active").removeClass("active").addClass("region");
		$(".locsGlobal, .locsAustralia, .locsNewzealand, .locsUnitedstates").hide();
		$(".locsUnitedkingdom").show("slow");
	});
	$("a.tabUnitedstates").click(function() {
		$(this).parent("li").removeClass("region").addClass("active");
		$(this).parent("li").siblings(".active").removeClass("active").addClass("region");
		$(".locsGlobal, .locsAustralia, .locsNewzealand, .locsUnitedkingdom").hide();
		$(".locsUnitedstates").show("slow");
	}); 
	$(".ausNetwork").hover(function() {
		$(this).css("backgroundPosition", "0 -41px");
		$(".ausOn").fadeIn();
	}, function() {
		$(this).css("backgroundPosition", "0 0");
		$(".ausOn").fadeOut();
	});
	$(".nzNetwork").hover(function() {
		$(this).css("backgroundPosition", "0 -41px");
		$(".nzOn").fadeIn();
	}, function() {
		$(this).css("backgroundPosition", "0 0");
		$(".nzOn").fadeOut();
	});
	$(".ukNetwork").hover(function() {
		$(this).css("backgroundPosition", "0 -41px");
		$(".ukOn").fadeIn();
	}, function() {
		$(this).css("backgroundPosition", "0 0");
		$(".ukOn").fadeOut();
	});
	$(".usNetwork").hover(function() {
		$(this).css("backgroundPosition", "0 -42px");
		$(".usOn").fadeIn();
	}, function() {
		$(this).css("backgroundPosition", "0 0");
		$(".usOn").fadeOut();
	});
	$("a.tabGlobal, a.tabAustralia, a.tabNewzealand, a.tabUnitedkingdom, a.tabUnitedstates").live('click', function() {
		$("div.locScroll").jScrollPane();
	});
	// END
	
	// SHARE LINKS
		$(".shareLinks li:first a").addClass("borderTop");
		$(".shareLinks li:last a").addClass("borderBot");
		$(".shareHover").mouseover(function() {
			$(".shareBox").show(0)
			$(".shareLinks").animate( {
				top: "0"
			}, { duration: 500, easing: "easeOutSine" }).animate( { width: "127px" }, { duration: 1000, easing: "easeOutQuad" });
			$(".shareBox").delay(500).animate( { left: "-33px" }, { duration: 1000, easing: "easeOutQuad" }); 
			$(".shareClose").delay(1500).fadeIn();
		});
		$("a.shareClose").click(function() {
			$(".shareClose").hide(0);
			$(".shareBox").animate( { left: "14px" }, { duration: 500, easing: "easeOutQuad" }).delay(750).hide(0)
			$(".shareLinks").animate( { width: "27px" }, { duration: 500, easing: "easeOutQuad" }).animate({
				top: "314px",
			}, { duration: 500, easing: "easeOutSine" });
		});
	// END
	
	// HOME NEWS TABS
		$("a.tabNews").click(function() {
			if($(this).hasClass("active")) { return false; }
			else {
				$("ul.whatsOn").hide();
				$("ul.news").fadeIn("slow");
				$("a.tabWhatson").removeClass("active");
				$(this).addClass("active");
			}
		});
		$("a.tabWhatson").click(function() {
			if($(this).hasClass("active")) { return false; }
			else {
				$("ul.news").hide();
				$("ul.whatsOn").fadeIn("slow");
				$("a.tabNews").removeClass("active");
				$(this).addClass("active");
			}
		});
	// END
	
	// HOVER EFFECTS
	$(".applyNow a").hover(function() {
		$(".applyNow").stop().animate( {
			top: "70px"
		}, { duration: 1500, easing: "easeOutElastic" });
	}, function() {
		$(".applyNow").stop().animate( {
			top: "90px"
		}, { duration: 750, easing: "easeOutBounce" });
	});
	$("a.villageLogo, a.villageLogoTwo").hover(function() {
		$(this).stop().animate({ opacity: "1" }); }, function() { $(this).stop().animate({ opacity: "0.3" }); 
	});
	
	$("#galleryscrollable .item").hover(function() {
		$(this).children("span").stop().animate({ bottom: "0" }, { duration: 500, easing: "easeOutBounce"});
	}, function() {
		$(this).children("span").stop().animate({ bottom: "-3px" }, { duration: 500, easing: "easeOutBounce"});
	});
	$("#galleryscrollable .item ").click(function() {
		$("#galleryscrollable").find(".active").removeClass("active");
		$(this).addClass("active");
	});
	
	$(".landingBox").hover(function() {
		$(".imageOver").fadeOut("slow");
	}, function() {
		$(".imageOver").fadeIn("slow");
	});
	
	if($("#contentNav li").hasClass("level01On")) {
		$(this).find("#contentNav li.level01On ul").show();
	}
	$(".columnNav ul.level02 li:first, .columnNav li.level01On ul li:first a, .columnNav li.level01On ul li:first").css("border-top", "none");
	
	$(".mainNav ul li.level01, .columnNav ul li.level01, .mainNav ul li.level01On, .columnNav ul li.level01On").hover(function() {
		if($(this).has("ul")) {
			$(this).children(".level02").show();
			$(this).addClass("level01Hover");
		}
	}, function() {
		if($(this).find(".subNav").children("li").hasClass("level02On")) {
			$(this).removeClass("level01Hover");
		}
		else {
			$(this).children(".level02").hide();
			$(this).removeClass("level01Hover");
		}
	});
	
	$(".galleryListing li a").hover(function() {
		$(this).append("<span class=\"overlay\"></span>");
		$(".overlay").show().animate( {
			top: "0"
		}, { duration: 500, easing: "easeOutBounce" });
	}, function() {
		$(".overlay").remove();
	});
	// END
	
	$(".shareLinks a[href]").click(function(){
   		var rel = $(this).attr("href");
   		var url = encodeURIComponent(self.location.href);
   		var title = encodeURIComponent($("title:first").html());
   		rel = rel.replace("{url}",url);
   		rel = rel.replace("{title}",title);
   		self.location.href = rel;
   		return false;
	});
	$(".shareBox a").attr("target", "_blank");
	
	$(".prevFalse, .nextFalse").parent("div").fadeTo("fast", 0.3);
	
	$(".quickLinks div:last").css("border-right", "none");
	$("#content").after("<div id=\"gradientStrip\"></div>");
	$(".listingItem:last").css("border-bottom", "none");
	
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
	
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/applyNow/close.png" class="btn_close" title="Close Window" alt="Close" /></a>');
	
		//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
	
		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
	
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
	
		return false;
	});
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#fade , .applyBlock').fadeOut(function() {
			$('#fade, a.close').remove();  //fade them both out
		});
		return false;
	});

});

