/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/
function initRollovers() {
	if (!document.getElementById) return

	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);

			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;

			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}

			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}


/*

	Use Javascript to open the browser in a new window instead of "_target" so it will validate in XHTML

*/
function externalLinks() {
if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
	var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
			anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}


/*

	Add load events to have multiple onloads
	
*/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

/*

	To fix a strange IE bug not being able to click on a link
		
	
*/
function setHand(el) {
    if (el.className.length > 0) {
        el.className += " hand";
    }
    else {
        el.className = "hand";
    }
}
function removeHand(el) {
    if (el.className.length == 4) {
        el.className=el.className.replace("hand", "");
    }
    else {
        el.className=el.className.replace(" hand", "");
    }
}
function initHand() {
	
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	if (!isIE) return;
	if (!document.getElementById) return;
	
	var aLinks = document.getElementsByTagName('a');
	for (var i = 0; i < aLinks.length; i++) {
		if (aLinks[i].className == 'product-img') {
			
			aLinks[i].onmouseover = function() {
				setHand(this);
			}
			aLinks[i].onmouseout = function() {
				removeHand(this);
			}
			aLinks[i].onclick = function() {
				var source = this.getAttribute("href");
				window.location=source;
			}
			
		}
	}
}
addLoadEvent(initHand);

//add functions to onload
addLoadEvent(initRollovers);
addLoadEvent(externalLinks);