// MouseOver.js
// This file will produce dynamic mouse-overs for images with appropreate attributes:
//
// oversrc="" - REQUIRED - the source file for the mouse over
// pageid="" - OPTIONAL - the string to match in the URL for highlight effect
// highsrc="" - OPTIONAL - use this image instead of over image for highlight
//
//First check the name space...

var com;
if (!com || !com.jchristy) { throw new Error("com.jchristy: Required object 'com.jchristy.Support' does not exist."); }
if (!com.jchristy.Handler) { throw new Error("com.jchristy: Required object 'com.jchristy.Handler' does not exist."); }

//Name space is ready.

com.jchristy.MouseOver = {}; 
com.jchristy.MouseOver.addMouseOvers = function() {
	if (!com.jchristy.Support.features.HTML1) { return; }
	
	var imgs = document.getElementsByTagName("img");
	
	for (var i = 0; i < imgs.length; i++) {
		var img = imgs[i];
		var oversrc = img.getAttribute("oversrc");
		var pageid = img.getAttribute("pageid");
		
		if (oversrc && pageid && window.location.href.indexOf(pageid) != -1) {
			var highsrc = img.getAttribute("highsrc");
			img.src = (highsrc) ? highsrc : oversrc;
			continue;
		}
		
		if (oversrc) { 
			(new Image()).src = oversrc;
			img._mo = {
				enabled: true,
				outsrc: img.src,
				oversrc: oversrc
				};
			com.jchristy.Handler.add(img, "mouseover", function() { if (this._mo.enabled) { this.src = this._mo.oversrc; } } );
			com.jchristy.Handler.add(img, "mouseout", function() {  if (this._mo.enabled) { this.src = this._mo.outsrc; } } );
		}	
	}
}
com.jchristy.Handler.add(window, "load", com.jchristy.MouseOver.addMouseOvers);