/*
	App Name: onoff.js
	App URI: None
	Description: A way easily to make roll over actions
	Version: 0.1.0
	Author: Takuma Ando
	Author URI: None
	license: Dual licensed under the MIT or GPL Version 2 licenses.
	Created: 2011-03-13
	Modified: 2011-03-13
*/
(function(){
	function setRollOver(){
		if(document.getElementsByTagName){
			var images=document.getElementsByTagName("img");
			for(var i=0; i<images.length; i++){
				var src=images[i].getAttribute("src");
				if(src&&src!=null){
					if(src.match("_off\.")){
						var img=new Image();
						img.src=src.replace(/_off\./,'_on.');
						images[i].onmouseover=function(){
							if(isRollOverable(this)){
								this.setAttribute("src",this.getAttribute("src").replace("_off\.","_on."));
							}
						};
						images[i].onmouseout=function(){
							if(isRollOverable(this)){
								this.setAttribute("src",this.getAttribute("src").replace("_on\.","_off."));
							}
						};
						images[i].onmouseup=function(){
							if(isRollOverable(this)){
								this.setAttribute("src",this.getAttribute("src").replace("_on\.","_off."));
							}
						};
					}
				}
			}
			
		}
	}
	function isRollOverable(elem){
		var className = elem.className;
		if(className&&className!=null){
			if(className.match(/disableOnOff/)){
				return false;
			}
		}
		return true;
	}
	if(window.addEventListener){
		window.addEventListener("load",setRollOver,false);
	}else if(window.attachEvent){
		window.attachEvent("onload",setRollOver);
	}
})();
