//=====================================================================
//  DOM Image Rollover v3 (hover)
//
//  Demo: http://chrispoole.com/scripts/dom_image_rollover_hover
//  Script featured on: Dynamic Drive (http://www.dynamicdrive.com)
//=====================================================================
//  copyright Chris Poole
//  http://chrispoole.com
//  This software is licensed under the MIT License 
//  <http://opensource.org/licenses/mit-license.php>
//=====================================================================

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	//var imgarr=document.getElementsByTagName('img');
	var imgarr=new Array();
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	
	var imgs=document.getElementsByTagName('img');
	for (i=0;i<imgs.length;i++) { imgarr.push(imgs[i]); }
	
	var inputarr=document.getElementsByTagName('input');
	for (i=0;i<inputarr.length;i++) {
	    if (inputarr[i].type=="image") {   
	       imgarr.push(inputarr[i]);
	    }
	}
	
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
		    if (imgClass[i].match(/domroll (\S+)/)) {
			    var newPath;
			    if (imgClass[i].match(/domroll (\S+)/)[1].indexOf('http:') ==-1) {
			        var matchTo = imgClass[i].match(/domroll (\S+)/)[1].substr(0,6);
			        var appendIndex = imgSrc[i].indexOf(matchTo);
			        newPath = imgSrc[i].substr(0,appendIndex) + imgClass[i].match(/domroll (\S+)/)[1];
			    } else {
			        newPath = imgClass[i].match(/domroll (\S+)/)[1];
			    }
			    imgPreload[i].src = newPath;
			    imgarr[i].setAttribute('xsrc', imgSrc[i]);
		        imgarr[i].setAttribute('newPath', newPath);
			    imgarr[i].onmouseover=function(){
			        this.setAttribute('src',this.getAttribute('newPath'));
		        }
		        imgarr[i].onmouseout=function(){
			        this.setAttribute('src',this.getAttribute('xsrc'));
		        }
		        
		    }
		}
	}
}
domRollover();