// John's jQuery replacement for MM_preload and MM_mouseover
//
// Any IMG tag with DATA-PRELOAD="1" will be preloaded.
// Any IMG tag with DATA-OVERSRC will initialize as a rollover with DATA-OVERSRC as the over image.
// Can optionally include DATA-ORIGINALSRC to specify the base image, but not necessary.

jQuery(document).ready(function() {
	jQuery("body")
		.bind("preload",function() {
			var rollovers   = jQuery("img[data-oversrc],input[type='image'][data-oversrc]");
			var preloads    = jQuery("img[data-oversrc],img[data-preload],input[type='image'][data-oversrc],input[type='image'][data-preload]");
			var preloadhtml = '<DIV STYLE="opacity:0;filter:alpha(opacity = 0);width:1px;height:1px;position:absolute;top:0;overflow:hidden">\n'; 

			jQuery(preloads).each(function() {
				var over = (typeof jQuery(this).attr("data-oversrc") != "undefined" && jQuery(this).attr("data-oversrc") != "" && jQuery(this).attr("data-oversrc") != "undefined") ? jQuery(this).attr("data-oversrc") : "";
				var out  = (typeof jQuery(this).attr("data-originalsrc") != "undefined" && jQuery(this).attr("data-originalsrc") != "" && jQuery(this).attr("data-originalsrc") != "undefined") ? jQuery(this).attr("data-originalsrc") : "";

				if(out == "") {
					out = jQuery(this).attr("src");
					jQuery(this).attr("data-originalsrc",out);
				}

				if(over != "") { preloadhtml += '<IMG SRC="' + over + '" BORDER="0">'; } 
				preloadhtml += '<IMG SRC="' + out + '" BORDER="0">';
			});

			preloadhtml += '</DIV>\n';

			jQuery("head").append(preloadhtml);

			jQuery(rollovers)
				.mouseover(function() {
					var anim   = (typeof jQuery(this).attr("data-overanim") != "undefined" && jQuery(this).attr("data-overanim") != "") ? jQuery(this).attr("data-overanim").toLowerCase() : "flip";
					var freeze = (typeof jQuery(this).attr("data-freeze") != "undefined" && jQuery(this).attr("data-freeze") == 1) ? true : false;
					var over   = jQuery(this).attr("data-oversrc");

					if(freeze) { return true; }

					// Default is Flip
					jQuery(this).attr("src",over);
				})
				.mouseout(function() {
					var anim   = (typeof jQuery(this).attr("data-overanim") != "undefined" && jQuery(this).attr("data-overanim") != "") ? jQuery(this).attr("data-overanim").toLowerCase() : "flip";
					var freeze = (typeof jQuery(this).attr("data-freeze") != "undefined" && jQuery(this).attr("data-freeze") == 1) ? true : false;
					var out    = jQuery(this).attr("data-originalsrc");

					if(freeze) { return true; }

					// Default is Flip
					jQuery(this).attr("src",out);
				});
		})
		.trigger("preload");
});
