function loadFeaturedHeader() {
	$("#header_content").load("load_featured_header_data.php?id="+$(this).attr("rel"));
}
$(function(){
	$("ul#sub_menu li span").each(function(){
		$(this).hoverIntent(function(){
				$(".open").animate({width: "175px"}, {queue:false, duration:450});
				$(this).addClass("open");
				$(this).animate({width: "575px"}, {queue:false, duration:450});
		},function() {
		});
	});
	//popup share window
    $("#inside_share a").click(function(event){
    	event.preventDefault();
    });
	$("#inside_share span#share-open").click(function(){
		var url = $(this).attr("href");
		if(!$(this).hasClass("share-opening")) {
			$(this).addClass("share-opening");
			$(this).load(url, function() {
				var height = $("#inside_share #share_content").height();
				var high = height + 20;
				var bottom = 118;
				$("#inside_share #share_popup").css('height', high);
				$("#inside_share #share_popup").css("bottom", bottom);
				$("#inside_share #share_popup").css("visibility","visible");
			});
		}
	});
	$("#inside_share span.share-close a").livequery('click', function(event){
		//$(this).load('share2.html');
		event.preventDefault();
		$("#inside_share span#share-open").removeClass("share-opening");
		$("#inside_share span#share-open").html('<img src="images/inside_share.gif" alt="" /><br />share');
		return false;
	});
	$("#logo_share a").click(function(event){
    	event.preventDefault();
    });
	$("#logo_share span#share-footer-open").click(function(){
		var url = $(this).attr("href");
		if(!$(this).hasClass("share-opening")) {
			$(this).addClass("share-opening");
			$(this).load(url, function() {
				var height = $("#logo_share #share_content").height();
				var high = height + 20;
				var top = -78;
				var left = 80;
				$("#logo_share #share_popup").css('height', high);
				$("#logo_share #share_popup").css("top", top);
				$("#logo_share #share_popup").css("left", left);
				$("#logo_share #share_popup").css("visibility","visible");
			});
		}
	});
	$("#logo_share span.share-close a").livequery('click', function(event){
		//$(this).load('share2.html');
		event.preventDefault();
		$("#logo_share span#share-footer-open").removeClass("share-opening");
		$("#logo_share span#share-footer-open").html('<img src="images/logo_share.gif" alt="" /><br />share');
		return false;
	});
	$("#archive-container").hide();
	$(".archive-link").click(function(event) {
		event.preventDefault();
		if($("#archive-container").css("display") == "none") {
			$("#archive-link-text").html("hide archive");
			$("#archive-container").slideDown();
		}
		else {
			$("#archive-link-text").html("view archive");
			$("#archive-container").slideUp();
		}
	});
	$(".archive-close").click(function(event) {
		event.preventDefault();
		$('#archive-container').slideUp();
	});
	$("a.recommendations").click(function(event) {
		event.preventDefault();
		$.get("page_recommendation.php?page_id="+$(this).attr("rel"), function(data) {
			if(data) {
				$("#recommendation-number").html(data);
			}
			else {
				alert('You have already recommended this.');
			}
		});
	});
	$("#panel-recommend-link").click(function(event) {
		event.preventDefault();
		$.get("recommend_mcentre.php?id="+$(this).attr("rel"),function(data) {
			if(data) {
				$("span#num").html(data);
			}
			else {
				alert("You have already recommended this.");
			}
		});
	});
	$("#primary_nav a").hover(function() {
		//if(!$("#sub-"+$(this).attr("rel")).hasClass("default") || $("#sub-"+$(this).attr("rel")).hasClass("active")) {
			$("#primary_nav a").removeClass("hovering");
			$(".sub_nav").removeClass("active");
			$(this).addClass("hovering");
			$("#sub-"+$(this).attr("rel")).addClass("active");
		//}
	});
	$("#primary_nav a").mouseleave(function() {
		if(!$(this).hasClass("default") && !$("#sub-"+$(this).attr("rel")).hasClass("sub_nav")) {
			$(".sub_nav").removeClass("active");
			$("#primary_nav a").removeClass("hovering");
			$("#sub-"+$("#primary_nav a.default").attr("rel")).addClass("active");
			return true;
		}
	});
	$(".sub_nav").mouseleave(function() {
		if($("#primary_nav a.default").hasClass("default")) {
			$(".sub_nav").removeClass("active");
			$("#primary_nav a").removeClass("hovering");
			$("#sub-"+$("#primary_nav a.default").attr("rel")).addClass("active");
			return true;
		}
		else {
			$(".sub_nav").removeClass("active");
			$("#primary_nav a").removeClass("hovering");
		}
	});
	$(".view-featured-video").click(function(event) {
		event.preventDefault(); 
		$(".video_main").load($(this).attr("href"));
	});
	
	$('div#pgal').jScrollPane({scrollbarWidth: 15});
	$('div#vgal').jScrollPane({scrollbarWidth: 15});
});
