function hideOverlay(){
	if($("#mask").length > 0){
		$('#mask_overlay').fadeOut();
		$('#mask').fadeOut();
		// $("body").animate({backgroundColor: "#eff0f0"});
		$("#mask").unbind("click");
	}
	return false;
}

$(document).ready(function(){
	$("#logo").ifixpng(); //fix pngs
	$("#accordion h3 a").click(function(){ return false; });
	
	//custom scrollbar on index page
	$('.scroll-pane').jScrollPane({dragMinHeight:"52", dragMaxHeight: "52", scrollbarWidth: "11"});
	
	//activate index page accordion
	$("#accordion").accordion({event: 'mouseover'});




	//set up modal window for certain links
	$("a[rel=overlay]").each(function(){
		$(this).click(function(){
			var link = $(this);
			if($("#mask").length < 1){
				var mask = $("<div>").attr("id", "mask");
				$(mask).prependTo("body");
			}

			//Get the screen height and width  
			var maskHeight = $(document).height();  
			var maskWidth = $(document).width();  

			//Set heigth and width to mask to fill up the whole screen  
			$('#mask').css({'width':maskWidth,'height':maskHeight});  
			// $('#mask').css({'width':"100%",'height':"100%"});  
			
			//overlay div
			var overlay = $("<div>").attr("id", "mask_overlay");
			$("#mask").after(overlay);
			// $('#mask_overlay').css({'left':maskWidth/2-375,'top':maskHeight/2-154});  
			// $('#mask_overlay').css({'left':"50%",'top':"50%", "margin-left": "-375px", "margin-top":"-154px", "position":"fixed"});  
			

			//transition effect       
			$('#mask').fadeIn("normal", function(){
				if(!$.support.opacity){
					$(this).css("filter", "alpha(opacity=80)");
				}
				$('#mask_overlay').fadeIn();
				
				// get the HTML for the overlay they clicked
				$.ajax({
					type: "post",
					url: $(link).attr("href"),
					// data: "",
					dataType: "html",
					success: function(data){
						$("#mask_overlay").html("<p id='overlay_close'><a href=''>Close x</a></p>" + data); //insert into overlay div
						$("#overlay_close a").click(hideOverlay);
					}
				});
				
			});      
			$("#mask").click(hideOverlay);

			return false;
		});
	});
	
	//menu nav animation
	$(".menu_nav a").each(function(){
		$(this).click(function(){
			var menudiv = $(this).parent().attr("id").replace("link","menu_content");
			$(this).parent().parent().next().scrollTo($("#"+menudiv), 400, {axis:'x'});
			// console.log($(this).parent().attr("id").replace("link","menu_content"));
			$(this).parent().parent().find(".active").each(function(){
				$(this).removeClass("active");
			});
			$(this).addClass("active");
			return false;
		});
	});
	
});