/*
	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, '_r'+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);
			}
		}
	}

	if (checkForPrintable() == true) {
		changeToPrintStylesheet();
	}
}

window.onload = initRollovers;

function changeBG(id,suffix) {
	if (!document.getElementById) return
	
	var class_name = "mainNavItem "+id+suffix; 
	document.getElementById(id).setAttribute("class", class_name);
}

function emailFriend() {
 var doc = "mailto:" + "?subject=" + escape(document.title) + "&body=" + location.href;
 window.location = doc;
} 

function popen(){
 var temp = window.location.href.split('?');
 var theFile = temp[0] + '?printable=true';
 var theWindow = '';
 var theAttributes = 'toolbar=no,menubar=no,status=no,resizable=no,location=no,scrollbars=yes,height=500,width=700';
 var popWindow = window.open(theFile,theWindow,theAttributes);
 popWindow.focus();
} 

function checkForPrintable() {
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	
	if (vars['printable'] == "true") {
		return true;
	} else {
		return false;
	}
}

function changeToPrintStylesheet() {
	var currentStylesheet = document.getElementById("mainStyle");
	currentStylesheet.href = "/assets/css/print.css";
	window.print();
}