$(document).ready(function() {												   
	$.preloadImages("/images/search-home-inspectors-2.gif");

	$(".presentation-links").animate({ opacity:.65 });
	
	$("#presentation-menu ul li a").attr("href", "#");
	
	function hideShow(hide, show, menu) {
			$(hide).css("display","none");
			$(show).css("display","block");
			$("#presentation-menu ul li a").css("background", "url(/images/presentation-menu-bg.gif)");
			$("#presentation-menu ul li a").css("color", "#F2F2F2");
			$("#presentation-menu ul li a").removeClass("clicked");
			$(menu).css("background", "url(/images/presentation-menu-bg-2.gif)");	
			$(menu).css("color", "#000");	
			$(menu).addClass("clicked");		
	}
	
	
	$("#presentation-menu ul li a").mouseover(function(){
		var theColor = $(this).css('color');
		if ( theColor == "rgb(242, 242, 242)" ) {
				$(this).css("background", "url(/images/presentation-menu-bg-2.gif)");	
				$(this).css("color", "#000");
				$(this).addClass("active");
		}
	});
	
	$("#presentation-menu ul li a").mouseout(function(){
		var theColor = $(this).css('color');
		if ( (theColor == "rgb(0, 0, 0)") && ($(this).hasClass("active")) ) {
				$(this).css("background", "url(/images/presentation-menu-bg.gif)");	
				$(this).css("color", "#F2F2F2");
				$(this).removeClass("active");
				if ($(this).hasClass("clicked")) {
						$(this).css("background", "url(/images/presentation-menu-bg-2.gif)");	
						$(this).css("color", "#000");	
					}
		}
	});
	
	$("#presentation-menu ul li a").css("cursor", "pointer");
	
	$("#menu1 a").css("background", "url(/images/presentation-menu-bg-2.gif)");
	$("#menu1 a").css("color", "#000");

	$("#menu1 a").click(function() {
		hideShow(".presentation-item","#presentation-display-1","#menu1 a");
	});
	$("#menu2 a").click(function() {
		hideShow(".presentation-item","#presentation-display-2","#menu2 a");
	});
	$("#menu3 a").click(function() {
		hideShow(".presentation-item","#presentation-display-3","#menu3 a");
	});
	$("#menu4 a").click(function() {
		hideShow(".presentation-item","#presentation-display-4","#menu4 a");
	});

//POPUP CODE
	
	$(".popup").css({
		"display": "none",
		"position": "fixed",
		"width": "275px",
		"background": "#FFF",
		"border": "3px solid #000",
		"z-index": "600",  
		"top": "50px"	
	});

	$(".hgnetworksearch").attr("href", "#");

	// prepares the popup background
	$("#footer").after('<div id="backgroundPopup"></div>');
	var docHeight = $(document).height();
	$("#backgroundPopup").css({  "height": docHeight }); 

	//popup code 
	 var popupStatus = 0; 

	 function closePopup(){  
		 if(popupStatus==1){  
			 $("#backgroundPopup").hide();  
			 $(".popup").fadeOut("fast");  
			 popupStatus = 0;  
		 }  
	 } 

	function centerPopup(){  	
		var windowWidth = document.documentElement.clientWidth;  
//		var windowHeight = document.documentElement.clientHeight;  
		var windowHeight = $(window).height();  
		var popupHeight = 250;
		var popupWidth = $(".popup").width();  
		 $(".popup").css({  		   
		 "top": "50px",   
		 "left": windowWidth/2-popupWidth/2-15, 
		 "height": popupHeight
		 });  	   	  
	 }  

	$(".hgnetworksearch").click(function() {
		centerPopup();
		if(popupStatus==0){  
			$(".popupcloser").show();
			$("#backgroundPopup").css({ "opacity": "0.6" });  
			$("#backgroundPopup").fadeIn("slow");  
			$(".popup").fadeIn("slow");  
			popupStatus++;  
		}  
	});
	$("#backgroundPopup, .popupcloser").click(function() {
		closePopup()
	});

});
