// 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 id  = img.getAttribute("id")
		var isOver = (id) ? id.indexOf("_over") : -1;
		
		if (isOver != -1) { 
			var oversrc = img.src.substr(0, img.src.lastIndexOf(".")) + "_over" + img.src.substr(img.src.lastIndexOf("."));
			newImage = new Image();
			newImage.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);
