//=====================================================================
//  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>
//=====================================================================
//
// Note: Filenames must have same base and use these standard postfixes:
//	 home_off.jpg    -> for when button is inactive
//   home_hover.jpg  -> for when mouse is over button
//   home_down.jpg   -> while mouse is pushed down, but before released
//	.jpg, .gif, and .png are all acceptable extensions, but you must be
//  consistent in which one you use.

// The class given to images where you want the rollover effect applied
class_name = 'domroll'
// Set to false if NO images have postfix '_hover.jpg'
hover_state = true
// Set to true if images with postfix '_down.jpg' are available
down_state = false

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 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(){
					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(){
				this.setAttribute('src',this.src.replace(postStr,"_off.$2"));
			}
		}
	}
}
window.onload=function(){domRollover(hover_state, down_state, class_name);}