// JavaScript Document
$(document).ready(function() {
	
	var menuRolloverArea = document.getElementById("menu");
	if(selectedBackground != null){
		menuRolloverArea.style.background = "url(images/" + selectedBackground + "_over_bg.gif) top left no-repeat";
	};
	var rememberOld = menuRolloverArea.style.background;
	
	// Preload all menu navigation rollovers
	$("#menu img").each(function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/.gif$/ig,"_over_bg.gif");
		$("<img>").attr("src", rollON);
	});
	
	// Navigation rollovers
	$("#menu a").mouseover(function(){
		rememberOld = menuRolloverArea.style.background;
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_over/);
		// don't do the rollover if state is already ON
		if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_over_bg.gif"); // strip off extension
			menuRolloverArea.style.background = "url(" + imgsrcON + ") top left no-repeat";
		}
	});
	$("#menu a").mouseout(function(){
		menuRolloverArea.style.background = rememberOld;
	});

	// Book rollover
	var bookRolloverArea = document.getElementById("bookInfo");
	$("#bookInfo a#book").mouseover(function(){
		bookRolloverArea.style.background = "url(images/buy_it_now_arrow.gif) top left no-repeat";
	});
	$("#bookInfo a#book").mouseout(function(){
		bookRolloverArea.style.background = "none";
	});
	
	// Testimonials sticky rollover
	$("#bookInfo a#sticky").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_over/);
		// don't do the rollover if state is already ON
		if (!matches) {
			imgsrcON = imgsrc.replace(/.gif$/ig,"_over.gif"); // strip off extension
			$(this).children("img").attr("src", imgsrcON);
		}
	});
	$("#bookInfo a#sticky").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});

});
