/*
-----------------------------------------------
washington life ui javascript
version:  0.1
----------------------------------------------- */

/** Popup window **/
function popup(id, url) {
	window.open(url, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=278,height=325');
}


/** Temporary string manipulation result **/
var tmpSrc;

function newRollover(preload, object, index) {
	cls = object[index].className;
	
	if(cls.indexOf("imageOver") != -1) {
		var src = object[index].getAttribute('src');
		
		/** Check to see if active image type or normal image type 
		*** Replace "_a" with "" for rollover functionality **/
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var itype = src.substring(src.lastIndexOf('_'), src.length);
		
		if(src != itype) {
			src = src.replace(itype, ftype);
		}
		
		var hsrc = src.replace(ftype, '_o' + ftype);
		
		object[index].setAttribute('hsrc', hsrc);
		
		preload[index] = new Image();
		preload[index].src = hsrc;
		
		object[index].onmouseover = function() {
			tmpSrc = this.getAttribute('src');
			this.setAttribute('src', this.getAttribute('hsrc'));
		}
		
		object[index].onmouseout = function() {
			if (!tmpSrc) {
				tmpSrc = this.getAttribute('src').replace('_o' + ftype, ftype);
			}
			else {
				this.setAttribute('src', tmpSrc);
			}
		}
	}
}

function initRollovers() {
	if (document.getElementById) {
		/** Storage variables for preload images **/
		var imgPreload = new Array();
		var inputPreload = new Array();
	
		/** DOM object arrays for each preload type **/
		var images = document.getElementsByTagName('img');
		var inputs = document.getElementsByTagName('input');
		
		/** Loop over each object array to set up rollover effects **/
		for (var i = 0; i < images.length; i++) {
			newRollover(imgPreload, images, i);
		}
		
		for (var j = 0; j < inputs.length; j++) {
			newRollover(inputPreload, inputs, j);
		}
	}
}

window.onload = initRollovers;