//=====================================================================
//  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.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.


function domRollover() {
	hs=true;// hover state (true or false)
	ds=false; // down state (true or false)
	cn='domroll' // class name
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=new Array();
	var imagetags=document.getElementsByTagName('img');
	var inputarr=document.getElementsByTagName('input');
	for (var i in imagetags) imgarr.push(imagetags[i]);
	for (var i in inputarr) imgarr.push(inputarr[i]);
	var imgPreload=new Array();
	var imgSrc=new Array();
	var postStr=/(|_hover|_down)\.(jpg|gif|png)/
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className && 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,".$2"));
			}
		}
	}
}

var VA;
if (!VA) VA = {};
if (!VA.util) VA.util = {};

VA.util.addEventListener = function(eType,el,func) {
	if (window.addEventListener) { // W3C/Mozilla
		el.addEventListener(eType,func,false)
	} else if (window.attachEvent) { // IE
		el.attachEvent('on' + eType,func)
	}
}

VA.util.addEventListener('load', window, domRollover);