var bgImages = new Array("fishing.jpg","kids.jpg","canoes.jpg");
var currentImage = 0;
var slideshowDelay = 8;

$(document).ready(function() {
	$("#header a").click(function() {
		clickedID=$(this).attr("id");
		showBlurb(clickedID);
		return false;
	});
	$("#product_map area").click(function() {
		clickedID=$(this).attr("title");
		showBlurb(clickedID);
		return false;
	});
	if($.browser.msie && $.browser.version=="6.0") {
		$(".blurbs img").each(function() {
			oldSrc=$(this).attr("src");
			newSrc=oldSrc.replace(/.png/, ".gif");
			$(this).attr("src", newSrc);
		});
	}
	$("#footer a, #copyright a").click(function() {
		clickedID=$(this).attr("id");
		
		$("#productshot").attr("src","images/product-images/pharmacal.png");
		
		$("#footer a").removeClass("footernav_active");
		$(this).addClass("footernav_active");
		
		//If the text box is already showing animate it down first
		if($("#blurb").is(":hidden")) {
			$("#page_text").slideUp("normal", function() {
				$("#page_text div").hide();
				$("#"+clickedID+"_text").css("display","block");
			});
		} else {		//Otherwise hide the blurb box first
			$("#blurb").slideUp("normal");
			$("#"+clickedID+"_text").css("display","block");
		}
		$("#page_text").slideDown("slow");
		return false;
	});
	setInterval("swapImage()", slideshowDelay * 1000);
});

function showBlurb(blurbID) {
	$(".blurb_hidden").slideUp("normal");
	//Blurb box is already showing, just change the text inside
	if($("#page_text").is(":hidden")) {
		$(".blurbs").slideUp("normal");
		$("#"+blurbID+"_blurb").slideDown("normal");
	} else {		//Blurb box is hidden, hide the page text, and then show the blurb box
		$("#footer a").removeClass("footernav_active");
		$("#page_text").slideUp("fast");
		$(".blurbs").hide();
		$("#"+blurbID+"_blurb").show();
		$("#blurb").slideDown("normal");
	}
	$("#productshot").attr("src","images/product-images/"+blurbID+".png");
}

function swapImage() {
	if(currentImage >= bgImages.length) {
		currentImage=0;
	}
	$("#content").css("background","url('images/home/"+bgImages[currentImage]+"')");
	$("#content_bg").fadeOut("slow", function() {
		//alert(currentImage+"\n"+bgImages[currentImage]);
		newAlt=bgImages[currentImage].split(".");
		newAlt=newAlt[0];
		$("#content_bg").attr("src","images/home/"+bgImages[currentImage]).show();
		$("#content_bg").attr("alt",newAlt);
		$("#content").css("background","none");
		currentImage++;
	});
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    tmpImage=new Image();
	tmpImage.src=arguments[i];
  }
}