// run on document ready
$(function() {
	// rollover image preload function
	var preloader = function()
	{
		// for each image path that is passed in create an image object with jQuery that will load the src
		for(var i = 0; i < arguments.length; i++)
		{
			$("<img>").attr("src", arguments[i]);
		}
	}
	
	// match pattern of dot and extension
	var hoverRegex = /(\.\w+)$/;
	// insert an "_r" before that match
	var hoverReplace = "_r$1";
	// find _r followed by a dot and extension
	var hoverOutRegex = /_r(\.\w+)$/;
	// replace match with just the dot and extension
	var hoverOutReplace = "$1";
	
	// swap images
	$("#header-links a:has(img), #content p.cart a:has(img)").hover(function () {
		// on mouse over
		var $img = $("img", this);
		var newSrc = $img.attr("src").replace(hoverRegex, hoverReplace);
		$img.attr("src", newSrc);
	}, function () {
		// on mouse out
		var $img = $("img", this);
		var newSrc = $img.attr("src").replace(hoverOutRegex, hoverOutReplace);
		$img.attr("src", newSrc);
	}).each(function () {
		// preload images
		preloader($("img", this).attr("src").replace(hoverRegex, hoverReplace));
	});
	
	// shopping cart link
	$('#header-links a:eq(1), #footer a:eq(2)').click(function() {
		$('#shoppingCartForm').remove();
		$(this).blur();
		$('<form id="shoppingCartForm" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="business" value="kangaroodyer@yahoo.com"/><input type="hidden" name="cmd" value="_cart"/><input type="hidden" name="display" value="1"/></form>').appendTo('body').submit();
	});
	// blog link
	$('#header-links, #footer p#links').append('|<a href="http://gailthekangaroodyer.blogspot.com/" target="_blank">Our Blog</a>');
});