//=====================================================================
//  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(hs, ds, cn) {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var defaultOn=new Array();
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var postStr=/(_off|_hover|_down)\.(jpg|gif|png)/
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf(cn)!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			if (hs) {
				imgPreload[i]=new Image();
				imgPreload[i].src = imgSrc[i].replace(postStr,"_hover.$2");	
				imgarr[i].onmouseover=function(){
					if (this.src.indexOf("_hover") != -1) {
						defaultOn[i] = 1;
					} else {
						defaultOn[i] = 0;
					};
					this.setAttribute('src',this.src.replace(postStr,"_hover.$2"));
				}
			}
			if (ds){
				imgPreload[i]=new Image();
				imgPreload[i].src = imgSrc[i].replace(postStr,"_down.$2");
				imgarr[i].onmousedown=function(){
					this.setAttribute('src',this.src.replace(postStr,"_down.$2"));
				}
				imgarr[i].onmouseup=function(){
					this.setAttribute('src',this.src.replace(postStr,"_hover.$2"));
				}
			}
			imgarr[i].onmouseout=function(){
				if (defaultOn[i] == 1) {
					this.setAttribute('src',this.src.replace(postStr,"_hover.$2"));
				} else {
					this.setAttribute('src',this.src.replace(postStr,"_off.$2"));
				}
			}
		}
	}
}
window.onload=function(){domRollover(true, false, 'roll');}
