// easyRollover.js
// rollover ON image -> xxx-on.jpg|.gif|.png
// rollover OFF image -> xxx-off.jpg|.gif|.png
// copyright 2008 Taira Mibu @ TransDesign+

var easyRollover = {
	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(/.*-off\./))||(img[i].style.filter)){
				preLoadImg[preLoadImg.length] = new Image;
				preLoadImg[preLoadImg.length-1].src = img[i].src.replace('-off.', '-on.');
				img[i].onmouseover = easyRollover.over;
				img[i].onmouseout  = easyRollover.out;
				try {img[i].addEventListener('click', easyRollover.click, false);}
				catch(e){img[i].attachEvent('onclick', (function(el){return function(){easyRollover.click.call(el);};})(img[i]));}
			}
		}

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

	over : function() {
		var imgSrc, preLoadImgSrc;
		if((this.style.filter)&&(this.style.filter.match(/-off\.png/)))//(IE5.5-6 && png)
			this.style.filter = this.style.filter.replace('-off.png', '-on.png');
		else
			this.src = this.src.replace('-off.', '-on.');
	},

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

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

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