var Rollover = {
	
	main : function() {
		var img = document.images, ipt = document.getElementsByTagName('input'), i, preLoadImg = [];
		// img elements
		for (i = 0; i <img.length; i++) {
			if ((img[i].src.match(/.*_n\./))||(img[i].style.filter)){
				preLoadImg[preLoadImg.length] = new Image;
				preLoadImg[preLoadImg.length-1].src = img[i].src.replace('_n.', '_r.');

				img[i].onmouseover = Rollover.over;
				img[i].onmouseout  = Rollover.out;
				try {img[i].addEventListener('click', Rollover.click, false);}
				catch(e){img[i].attachEvent('onclick', (function(el){return function(){Rollover.click.call(el);};})(img[i]));}
			}
		}
		// input[image] elements
		for (i = 0; i <ipt.length; i++) {
			if ((ipt[i].src.match(/.*_n\./))&&(ipt[i].getAttribute('type')=='image')){
				preLoadImg[preLoadImg.length] = new Image;
				preLoadImg[preLoadImg.length-1].src = img[i].src.replace('_n.', '_r.');

				ipt[i].onmouseover = Rollover.over;
				ipt[i].onmouseout  = Rollover.out;
				try {ipt[i].addEventListener('click', Rollover.click, false);}
				catch(e){ipt[i].attachEvent('onclick', (function(el){return function(){Rollover.click.call(el);};})(ipt[i]));}
			}
		}
	}
	,
	
	over : function() {
		var imgSrc, preLoadImgSrc;
		if((this.style.filter)&&(this.style.filter.match(/_n\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('_n.png', '_r.png');
		else
			this.src = this.src.replace('_n.', '_r.');
	},

	out : function(){
		if((this.style.filter)&&(this.style.filter.match(/_r\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('_r.png', '_n.png');
		else
			this.src = this.src.replace('_r.', '_n.');
	},
	
	click : function(){
		if((this.style.filter)&&(this.style.filter.match(/_r\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('_r.png', '_n.png');
		else
			this.src = this.src.replace('_r.', '_n.');
	},

	addEvent : function(){
		try {
			window.addEventListener('load', this.main, false);
		} catch (e) {
			window.attachEvent('onload', this.main);
		}
	}
}

Rollover.addEvent();


//=============================================
// rollover
//=============================================

function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'over') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;
