/*
	display.js
	
	Javascripts for ~~ website
*/
/*
	initRollovers(): Generic image rollover script
	Source:
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
	Modified with info from http://www.wandforge.com/rollover/
	Other modifications per site.
*/
function initRollovers() {
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');
	for (var i = 0; i < aImages.length; i++) {
		if (aImages[i].className.match("rollover")) {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+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('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}
/*
	Source:
	Suckerfish Dropdowns
	Authors : PATRICK GRIFFITHS, DAN WEBB
	http://www.alistapart.com/articles/dropdowns/
	Other modifications per site.
*/
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}

/*
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
*/
function pngFix(){var arVersion=navigator.appVersion.split("MSIE");var version=parseFloat(arVersion[1]);if((version>=5.5) && (document.body.filters)){for(var i=0;i<document.images.length;i++){var img=document.images[i];var imgName=img.src.toUpperCase();if(imgName.substring(imgName.length-3, imgName.length)=="PNG"){var imgID=(img.id) ? "id='"+img.id+"' " : "";var imgClass=(img.className) ? "class='"+img.className+"' " : "";var imgTitle=(img.title) ? "title='"+img.title+"' " : "title='"+img.alt+"' ";var imgStyle="display:inline-block;"+img.style.cssText;if(img.align=="left"){imgStyle="float:left;"+imgStyle;}if(img.align=="right"){imgStyle="float:right;"+imgStyle;}if(img.parentElement.href){imgStyle="cursor:hand;"+imgStyle;}var strNewHTML="<span "+imgID+imgClass+imgTitle +" style=\""+"width:"+img.width+"px;height:"+img.height+"px;"+imgStyle+";" +"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" +"(src=\'"+img.src+"\', sizingMethod='scale');\"></span>";img.outerHTML=strNewHTML;i=i-1;}}}return;}

// Tests for MSIE version. Returns version whole number
function isIE() {/*@cc_on
if(@_jscript_version < 5.6){return 5;}if(@_jscript_version < 5.7){return 6;}if(@_jscript_version < 5.8){return 7;}if(@_jscript_version < 5.9){return 8;}
@*/ return 0;}

function launchAll() {
//	initRollovers();
	if (!document.getElementById) { return; }
	if (isIE() && isIE()<7) {
		sfHover();
		pngFix();
	}
	jQuery(':first-child').addClass('first-child');
	initRollovers();
}
window.onload = launchAll;

// home banner rotator
jQuery(document).ready(function($) {
	if (!document.getElementById('home_banner')) { return; }
	tick = 5; // number of seconds between image changes.
	fade = 500; // duration of fade-in, in milliseconds
	var comment = $('#home_banner').html();
	var bgurl = $('#home_banner').css('background-image');
	if (!bgurl) { return; }
	// an awkward way to strip bgurl down to the URL itself.
	if (bgurl.match('"')) {
		var quotepos = bgurl.indexOf('"')+1;
	} else if (bgurl.match("'")) {
		var quotepos = bgurl.indexOf("'")+1;
	} else {
		var quotepos = bgurl.indexOf("(")+1;
	}
	var imgpath = bgurl.substring(quotepos,bgurl.lastIndexOf('/'));
	var imgstr = comment.substring(5,comment.indexOf(' -->',6));
	imgstr = jQuery.trim(imgstr);
	imglist = imgstr.split(','); // should be a list of the actual imgs to be used. Roll with it.);
	if (!imgstr || imglist.length<1) { return; }
	preloader = [];
	var hbhtml = $('#home_banner').html();
	hbhtmlarr = [];
	for (var a=0;a<imglist.length;a++) { // create a list of images for the preloader
		preloader[a] = document.createElement('img');
		preloader[a].src = imgpath + '/' + imglist[a];
		var lastimg = '#home_banner_'+a;
		hbhtmlarr[a] = '<img src="' + imgpath + '/' + imglist[a] + '" id="home_banner_'+a+'" class="slideshow" style="display:none;" width="860" height="278" />';
	}
	// rotate the stack by one to make the second image in queue the first one to rotate.
	var hbhtmlimg = hbhtmlarr.shift();
	hbhtmlarr.push(hbhtmlimg);
	hbhtml = hbhtmlarr.join('');
	$('#home_banner').html(hbhtml);
	$(lastimg).load(function(){setInterval(slides,tick*1000)});
	function slides() {
		var $active = $('#home_banner img.live');
		if ($active.length==0) { $active = $('#home_banner img:last'); }
		var $next = $active.next().length ? $active.next() : $('#home_banner img:first');
		$active.css('z-index',1).addClass('remove').removeClass('live');
		$next.css('z-index',2).fadeIn(fade,function() { $('#home_banner img.remove').css('display','none').removeClass('remove'); }).addClass('live');
	}
});
/* EOF */
