$(function(){
	Navigation.enableSubmenu($("#header ol.navigation"));
	Navigation.enableDatePickers($("#apply input.DATE"));
	
	Utils.elevateServiceBanners();
	Utils.enablePlaceholders();
	Utils.enableLightbox();
});

var Navigation = {
		
	enableSubmenu : function(mainmenu){
		
		mainmenu.find("> li").each(function(){
						
			$(this).bind("mouseenter", function(){
				
				$(this).stop();
				$(this).addClass("hover");
				$(this).find("div.submenu").slideDown(110);

			}).bind("mouseleave", function(){
				$(this).removeClass("hover");
				$(this).find("div.submenu").slideUp(80);
			});
			
			$(this).find("div.submenu").hide();
		});
	}
	
	,enableDatePickers: function(elements){
		
		elements.each(function(){
			
			$(this).datepicker({
				changeMonth: true,
				changeYear: true,
				showAnim: ''
			});
		});		
	}
};

var Utils = {

	elevateServiceBanners : function(){
	
		banners = $(".service-categories li.service");
		if(banners.length > 0){
			
			height = 0;
			banners.each(function(){				
				h = $(this).height();
				height = (h > height)? h: height;				
			});
			banners.each(function(){				
				$(this).height(height);				
			});			
		}
	}
		
	,enablePlaceholders : function(){
		
		$("form[id*='sitesearch']").each(function(){
						
			$(this).find("input[type='text']").each(function(){

				if(this.value == ""){
					var plc = $(this).attr("placeholder");
					if( plc){					
						this.value = plc;
							
						$(this).bind("focus", function(){
							this.value = "";
						});
					}
				}
			});
			
			$(this).submit(function(){
				
				$(this).find("input[placeholder]").each(function(){
					
					var plc = $(this).attr("placeholder");					
					if( plc && this.value == plc){					
						this.value = "";
					}
				});
			});
		});
	}
	
	,enableLightbox : function(){
		
		$("a[rel=prettyPhoto]").prettyPhoto();
	}
}