
// #############################################################################

/* GLOBAL SCRIPTS */

// Function to safely register multiple functions with the onLoad browser event
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') window.onload = func;
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
// This is the implementation of SimpleSwap
// by Jehiah Czebotar
// Version 1.1 - June 10, 2005
// Distributed under Creative Commons
//
// Include this script on your page
// then make image rollovers simple like:
// <img src="/images/ss_img.gif" oversrc="/images/ss_img_over.gif">
//
// http://jehiah.com/archive/simple-swap
// 
function SimpleSwap(el,which) {
	el.src=el.getAttribute(which || "origsrc");
}
//// For IMG tags
function SimpleSwapSetup() {
	var x = document.getElementsByTagName("img");
	for (var i=0;i<x.length;i++) {
		var oversrc = x[i].getAttribute("oversrc");
		if (!oversrc) continue;     
		// preload image
		// comment the next two lines to disable image pre-loading
		x[i].oversrc_img = new Image();
		x[i].oversrc_img.src=oversrc;
		// set event handlers
		x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
		x[i].onmouseout = new Function("SimpleSwap(this);");
		// save original src
		x[i].setAttribute("origsrc",x[i].src);
	}
}
//// FOR INPUT-IMAGE tags
/*function SimpleSwapSetupFormImages() {
	var x = document.getElementsByTagName("input");
	for (var i=0;i<x.length;i++) {
		if (x[i].type == "image") {
			var oversrc = x[i].getAttribute("oversrc");
			if (!oversrc) continue;     
			// preload image
			// comment the next two lines to disable image pre-loading
			x[i].oversrc_img = new Image();
			x[i].oversrc_img.src=oversrc;
			// set event handlers
			x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
			x[i].onmouseout = new Function("SimpleSwap(this);");
			// save original src
			x[i].setAttribute("origsrc",x[i].src);
		}
	}
}
*/
addLoadEvent(SimpleSwapSetup);
//addLoadEvent(SimpleSwapSetupFormImages);
// End SimpleSwap

// Dynamic implementation of oversrc attribute for SimpleSwap
function setOverSrc(imgObj) {
	var _imgSrcPrefix = imgObj.src.substring( 0,imgObj.src.lastIndexOf('.') );
	var _imgSrcSuffix = imgObj.src.substring( imgObj.src.lastIndexOf('.') );
	imgObj.setAttribute("oversrc",_imgSrcPrefix + '-on' + _imgSrcSuffix);
}
// End Dynamic implementation of oversrc attribute
