$(document).ready(function(){
	$.preloadImages("images/btn_home_over.gif",
								"images/btn_about_over.gif",
								"images/btn_services_over.gif",
								"images/btn_offers_over.gif",
								"images/btn_testimonials_over.gif",
								"images/btn_contact_over.gif");

	// set active
	$(".btn[class*=active]").each(function(){
		var tmpSrc = $(this).css("background-image");
		if (tmpSrc.indexOf("_over.") == -1) {
			$(this).css({
				"background-image":tmpSrc.replace(".gif","_over.gif")
			});
		}
	});

	// hover bg replacement
	$(".btn").hover(function(){
		var tmpSrc = $(this).css("background-image");
		if (tmpSrc.indexOf("_over.") == -1 && !$(this).hasClass("active")) {
			$(this).css({
				"background-image":tmpSrc.replace(".gif","_over.gif")
			}).stop().animate({top:"30px"},250);
		}
	},
	function(){
		var tmpSrc = $(this).css("background-image");
		if (!$(this).hasClass("active")) {
			$(this).css({
				"background-image":tmpSrc.replace("_over.gif",".gif")
			}).stop().animate({top:"23px"},250);
		}
	});

	setInputAnimations();

});

function checkContactForm(formid,simpleform) {
	if (typeof(simpleform) == 'undefined') {
		simpleform = false;
	}
	f = document.getElementById(formid);
	$("#"+formid+" input").css({border:"none"});
	var msg = "";
	if (f.FirstName.value == "") {
		msg = msg + "Please enter a first name.\n";
		f.FirstName.style.border = "2px solid red";
	}
	if (f.LastName.value == "") {
		msg = msg + "Please enter a last name.\n";
		f.LastName.style.border = "2px solid red";
	}
	if (f.Email.value == "") {
		msg = msg + "Please enter an email address.\n";
		f.Email.style.border = "2px solid red";
	}
	if (!simpleform && f.Phone.value == "") {
		msg = msg + "Please enter a phone number.\n";
		f.Phone.style.border = "2px solid red";
	}
	if (msg == "") {
		f.submit();
	}
	else {
		alert(msg);
	}
}

function setInputAnimations() {
	$("input:text").each(function(){
		$(this).attr("origbg",$(this).css("background-color"));																
	});
	// input field highlight animation
	$("input:text").focus(function(){
		if(!$(this).attr("readonly") && ! $(this).hasClass("NoInputHover")) {
			$(this).animate({backgroundColor:"yellow"},50).animate({backgroundColor:"#FFFF99"},500);
		}
	});
	$("input:text").blur(function(){
		if(!$(this).attr("readonly") && ! $(this).hasClass("NoInputHover")) {
			$(this).animate({backgroundColor:$(this).attr("origbg")},50);
		}
	});
}

jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
    jQuery("<img>").attr("src", arguments[i]);
  }
}


