// JavaScript Document

	$(document).ready(function(){
	
						   
	    //default form fields clear on click. Nice bit of UX.
		$("#search").click(function(){
		var varSelection = String($(this).val());
		if(varSelection=="SEARCH"){$(this).val('');}
		return false;			
		}); //close $("#search").click	
		
		$("#btnSearchSubmit").click(function(){
		$varSearch = "http://djhconstructioninc.blogspot.com/search?q=" + $("#search").val();
		window.open($varSearch);
		//alert($varSearch);
		return false;			
		}); //close $("#btnSearchSubmit").click	
						   
	var hoverText = $(this).attr("title");
	
	//check for # and display appropriate section
	var hash = window.location.hash.substr(1);
	//alert (hash);
	//var href = $('#nav li a').each(function(){
//		var href = $(this).attr('href');
//		if(hash==href.substr(0,href.length-5)){
//			var toLoad = hash+'.html #content';
//			$('#content').load(toLoad)
//		} 
		if(hash!=""){
		$(".contentBox").hide();
		switch (hash)
			{
			case "home":
			 $("#bgTest").animate({left: "0"}, 2500, function() {$("#contentBoxHome").fadeIn("slow");}   )
			 break;
			 case "news":
			  $("#bgTest").animate({left: "-1000"}, 2500, function() {$("#contentBoxNews").fadeIn("slow");}   )
			 break;
			 case "about":
			 $("#bgTest").animate({left: "-2000"}, 2500, function() {$("#contentBoxAbout").fadeIn("slow");}   )
			 break;
			 case "services":
			 $("#bgTest").animate({left: "-3000"}, 2500, function() {$("#contentBoxServices").fadeIn("slow");}   )
			 $("#servicesMenu").slideDown();
			 $(".subContent").fadeOut();
			 $("#commercial").fadeIn();
			 break;
			 case "gallery":
			 $("#bgTest").animate({left: "-4000"}, 2500, function() {$("#contentBoxGallery").fadeIn("slow");}   )
			 break;
			 case "resources":
			 $("#bgTest").animate({left: "-5000"}, 2500, function() {$("#contentBoxResources").fadeIn("slow");}   )
			 break;
			}
		}
//	});


	
	
	$("a").click(function(){ 
						  
		//track click with google analytics
		var varSelection = String($(this).attr("href"));
		varSelection = varSelection.replace(/^\s+|\s+$/g, '') ;
		pageTracker._trackPageview("/" + varSelection);		
		
		if ( $(this).hasClass("mainMenu") )
		{
		var navTarget = $(this).attr("href");	
		window.location.hash = "#"+navTarget; 
		//alert(navTarget);
		$("a").removeClass("current");
		$(this).addClass("current");
		$(".contentBox").hide();
		$("#servicesMenu").slideUp();
		switch (navTarget)
			{
			case "home":
			 $("#bgTest").animate({left: "0"}, 2500, function() {$(".contentBox").hide();$("#contentBoxHome").fadeIn("slow");}   )
			 break;
			 case "news":
			 $("#bgTest").animate({left: "-1000"}, 2500, function() {$(".contentBox").hide();$("#contentBoxNews").fadeIn("slow");}   )
			 break;
			 case "about":
			 $("#bgTest").animate({left: "-2000"}, 2500, function() {$(".contentBox").hide();$("#contentBoxAbout").fadeIn("slow");}   )
			 break;
			 case "services":
			 $("#bgTest").animate({left: "-3000"}, 2500, function() {$(".contentBox").hide();$("#contentBoxServices").fadeIn("slow");}   )
			 $("#servicesMenu").slideDown();
			 $(".subContent").fadeOut();
			 $("#commercial").fadeIn();
			 break;
			 case "gallery":
			 $("#bgTest").animate({left: "-4000"}, 2500, function() {$(".contentBox").hide();$("#contentBoxGallery").fadeIn("slow");}   )
			 break;
			 case "resources":
			 $("#bgTest").animate({left: "-5000"}, 2500, function() {$(".contentBox").hide();$("#contentBoxResources").fadeIn("slow");}   )
			 break;
			}
		}
		
		if ( $(this).hasClass("servicesMenu") )
		{
			var navTarget = $(this).attr("href");	
			//alert(navTarget);
			$("a").removeClass("current");
			$(this).addClass("current");
			$(".subContent").fadeOut();
			$("#"+navTarget).fadeIn();
		}
		
		if ( $(this).hasClass("localResource") )
		{
			$("#servicesMenu").slideUp();
			var navTarget = $(this).attr("href");	
			//alert(navTarget);
			$(".contentBox").fadeOut();
			$("#"+navTarget).fadeIn();
		}
		
		if ( $(this).hasClass("resource") )
		{
			//alert('elsed!');
			window.open(this.href); return false;
		}
		
		
		
								  		
			return false;			
	});
	
	$(".gallery").click(function(){  	
	var galleryTarget = $(this).attr("name");
	galleryTarget = "#" + galleryTarget;
	$("#solarGallery, #greenGallery, #constructionGallery").hide();
	$(galleryTarget).show();
	return false;			
	});
						   
						   
	$("#menu1").click(function(){  
									
			
		  $("#bgTest").animate({left: "0"}, 2500)
		  //$("#bgTestSky").animate({left: "0"}, 2500)
		  //$("#bgTestForeGround").animate({left: "0"}, 2500)
	  
			
			return false;			
	});

$("#menu2").click(function(){  
									
			
		  $("#bgTest").animate({left: "-1000"}, 2500)
		  //$("#bgTestSky").animate({left: "-100"}, 2500)
		  //$("#bgTestForeGround").animate({left: "-1250"}, 2500)
	  
			
			return false;			
	});

$("#menu3").click(function(){  	
	$("#bgTest").animate({left: "-2000"}, 2500)
	return false;			
	});

$("#menu4").click(function(){  	
	$("#bgTest").animate({left: "-3000"}, 2500)
	return false;			
	});

$("#menu5").click(function(){  	
	$("#bgTest").animate({left: "-4000"}, 2500)
	return false;			
	});
	
			
});
