//rollover.js
/* 20100626 jun fujimura@COLORS for dom browser targetElement->//input[@class=className and @type='image'] //img[@class=className] */
function initRollovers() {
	if (!document.getElementById && document.createElement) return;
	var thc = document.getElementsByTagName('img');
	setEvent(thc, 'img');
	thc = document.getElementsByTagName('input');
	setEvent(thc, 'input');
	thc=null;
}
function setEvent(hc, el){
	var loader = new Array();
	var n = hc.length;
	for (var i = 0; i < n; i++) {
		if (hc[i].className.match(/\s?imgover\s?/)) {
			switch(el){
				case 'input':
					if(hc[i].getAttribute('type')!=='image') return;
					hc[i].onfocus = function (){ this.setAttribute('src', this.getAttribute('lsrc')); }
					hc[i].onblur  = function (){ this.setAttribute('src', this.getAttribute('lsrc')); }
				case 'img':
					var src = hc[i].getAttribute('src');
					var hsrc = src.replace(/^(.*)(\.[^.]*)$/,function(str, path, extension){ return path+"_r"+extension;});
					loader[loader.length] = new Image();
					loader[loader.length-1].src = hsrc;
					hc[i].setAttribute('lsrc', src);
					hc[i].setAttribute('osrc', hsrc);
					hc[i].onmouseover = function (){ this.setAttribute('src', this.getAttribute('osrc')); }
					hc[i].onmouseout  = function (){ this.setAttribute('src', this.getAttribute('lsrc')); }
					break;
			}
		}
	}
	n = null;
}
if(window.addEventListener) window.addEventListener("load",initRollovers,false);
else if(window.attachEvent) window.attachEvent("onload",initRollovers);
else window.onload = initRollovers;

