$(window).load(function(){
	/* Keep footer at bottom of page */
	footerHeight = parseInt( $("#wrapFooter").height() );
	paddingHeight = parseInt( $("#wrapMiddle").css("padding-bottom") );
	if ( footerHeight != paddingHeight ) {
		$("#wrapMiddle").css({"padding-bottom":footerHeight});
	}
});


$(document).ready(function(){
	
	/* Drop-down menus */
	$('#navTop .levelOneLiHasSubmenu .levelOneA').mouseenter(function(){
		// $(".submenuWrap").stop(false, true).hide();
		var thisParent = $(this).parent();
		var thisSubmenu = $(this).parent().find(".submenuWrap:first");
		// center position of submenu
		var leftPos = parseInt( (thisSubmenu.parent().width() / 2) - (thisSubmenu.width() / 2) );
		thisSubmenu.css({"left":leftPos});
		thisParent.hover(function() {
			thisParent.addClass("levelOneLiHover");
			thisSubmenu.slideDown(000);
		}, function(){				
			thisSubmenu.slideUp(000,function(){
				thisParent.removeClass("levelOneLiHover");
			});
		});
	});
	
	$(".showTooltipType01").tooltip({ 
	    bodyHandler: function() { 
	        return $($(this).attr("href")).html(); 
	    }, 
	    showURL: false,
		track: true,
		showBody: " - ",
		fixPNG: false,
		extraClass: "tooltipType01",
		delay: 0,
		fade: 0,
		top: -15,
		left: 15
	});
	
	
	
	/* expander */
	$('.showMore').click(function(){
		// $(".submenuWrap").stop(false, true).hide();
		$($(this).attr("href")).slideToggle();
		$(this).toggleClass("showMoreOpen");
	});
	
});





/** Validates the contact form **/
function validateContactForm() {
	var errorMessage = "";
	$(".validate").each(function() {
		if ( $(this).val() == "" ){
			$(this).addClass('highlight');
			errorMessage = "Please make certain you have completed all of the required fields.\n\nThey are marked with a star and highlighted in red.\n\n";
		}
		else {
			$(this).removeClass('highlight');
		}
	});
	$(".validateEmail").each(function() {
		if ( errorMessage=="" && $(this).val() != "" ){
			var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,6})+$/;
			if ( $(this).val().match(emailRegEx) == null ){			
				errorMessage = "Your email address is not valid.  Please try again.";
				$(this).addClass('highlight');
			}
		}
	});
	if (errorMessage != "") {
		alert(errorMessage);
		return false;
	}
}


jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
$.preloadImages(
	"/img/modal_top.png",
	"/img/modal_bottom.png",
	"/img/nav_top_submenu_bg_top.png",
	"/img/nav_top_submenu_bg_bottom.png"
);


