/*
	=========================================
	linkClass() is for the images with a link
	class, it loops thru all images and find 
	the ones with a class=link. Then the 
	imgOver, imgOff functions are attached
	to them, they use RegEx to add/remove
	"_on" on image scr.
	=========================================
	Notes
	25 May 2006 Started source code
	
	2 June 2006 Optimized linkClass() and
	For iteration
	
	4 June 2006 Changed code to be unobtrusive
	and include the main navigation links, too
	
	6 June 2006 Added DOM scripting to create
	rotating effects that degrade gracefully
	
	16 Aug 2006 Added pre-loading of 
	onmouseover image
	=========================================
*/

/*	add onmouseover and onmouseout events to images, and pre-load alternate images
-----------------------------------------------------*/
function linkClass() {
	// test for browser compatibility
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("primaryContent")) return false;
	
	var container = document.getElementById( "primaryContent" );
	var imgs = container.getElementsByTagName( "img" ), loop, img, j, loop, img_alternate;
	for (loop = 0, j = imgs.length; loop < j; loop++) {
		img = imgs[loop];
		
		if (img.className.search(/link/) == -1) continue;
		
		// preload the OVER state
		img_alternate = new Image();
		img_alternate.src = img.src.replace(/(\.[a-z0-9]+)$/i,'_on$1')

		img.onmouseover=imgOver;
		img.onmouseout=imgOff;
	}
}


function imgOver() {
	this.src = this.src.replace(/(\.[a-z0-9]+)$/i,'_on$1');
}

function imgOff() {
	this.src = this.src.replace(/_on(\.[a-z0-9]+)$/i,'$1');
}

// ON LOAD
addLoadEvent(linkClass);


