// JavaScript Document

$(document).ready(function() {
	navSetup();
	$("#emailNewsletter").focus(function() { if ($(this).val() == "Email Address") $(this).val('') });
	$("#emailNewsletter").blur(function() { if ($(this).val() == "") $(this).val("Email Address") });
	
	$(".activeImage").animate({"dummy":"false"}, 4000, function() { nextHomeImage(); });

	
});


function navSetup() {
	$(".navImage").each(function () {
		var img = jQuery("img", this);
		if (img.length > 0) {
			var src = img.attr("src");
			var pos = src.lastIndexOf(".");
			var str1 = src.substr(0, pos);
			var str2 = src.substr(pos, src.length);
			var roll = str1+"_f2"+str2;
			$(this).mouseover(function () { swapImage(img, roll) });
			$(this).mouseout(function () { swapImage(img, src); });
		}
	});
}

function swapImage(image, src) {
	$(image).attr("src", src);
}



function  nextHomeImage() {
	var countImages = $("#flash img").length;
	if (countImages > 1) {
		var active = $(".activeImage");
		var aId = active.attr("id");
		aId = parseInt(aId.replace("image", ""));
		if (!isNaN(aId)) {
			if (aId == countImages) {
				var next = 1;
			} else {
				var next = aId+1;
			}
			$("#image"+next).css({"display":"block", "zIndex": 2});
			active.fadeOut(1000, function() {
				active.attr("class", "");
				$("#image"+next).attr("class", "activeImage").css("zIndex", countImages);
				$("#flash img").not("#image"+next).css("zIndex", 1);
				
				
				$(".activeImage").animate({"dummy":"false"}, 4000, function() { nextHomeImage(); });
			});
		}	
	}
}
