/*
	display.js
	
	Javascripts for ~~ website
*/
/*
	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+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
// inserts an INPUT field's TITLE into its VALUE
//    Any input field with a reflexive self-label will behave appropriately when focused or blurred.
//    The form element containing the self-labeling input will clear any input which contains only a self-label
//    To make this work: Give the field classname 'autofill' and put the default content in an ALT attribute.
function formFill() {
	for (a=0;a<document.getElementsByTagName('input').length;a++) {
		if (document.getElementsByTagName('input')[a].className.match('autofill')) {
			thisform = document.getElementsByTagName('input')[a];
			if (thisform.value=='') {
				thisform.value = thisform.getAttribute('alt');
			}
			thisform.onfocus = function() {
				if (this.value==this.getAttribute('alt')) {
					this.value = '';
				}
				return;
			}
			thisform.onblur = function() {
				if (this.value=='') {
					this.value = this.getAttribute('alt');
				}
				return;
			}
		}
	}
	for (a=0;a<document.getElementsByTagName('form').length;a++) {
		document.getElementsByTagName('form')[a].onsubmit = function() {
			for (e=0;this.getElementsByTagName('input').length;e++) {
				if (this.getElementsByTagName('input')[e].className.match('autofill')) {
					autofillform = this.getElementsByTagName('input')[e];
					if (autofillform.value==autofillform.getAttribute('alt')) {
						autofillform.value = '';
					}
				}
			}
			return;
		}
	}
	return;
}

// homepage banner animation. Requires jQuery.
function homeAnim() {
	// first, collect the info out of the current banner image and the string of names in the HTML comment.
	
}

/*
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('header')) { return; }
	if (isIE() && isIE()<7) {
		pngFix();
		sfHover();
	}
	formFill();
}
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; }
	var imgpath = bgurl.substring(bgurl.indexOf('(')+1,bgurl.lastIndexOf('/')+1) + 'homebanner/';
	if (isIE()>=6) { // IE inserts extra quotemarks into the background-image value. Or moz/saf strip them. Hard to say.
		var imgpath = bgurl.substring(bgurl.indexOf('(')+2,bgurl.lastIndexOf('/')+1) + 'homebanner/';
	} else {
		var imgpath = bgurl.substring(bgurl.indexOf('(')+1,bgurl.lastIndexOf('/')+1) + 'homebanner/';
	}
	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 lastimg = imglist.length - 1;
	var hbhtml = $('#home_banner').html();
	for (var a=0;a<imglist.length;a++) { // preload the images in the rotator.
		preloader[a] = new Image();
		preloader[a] = imgpath + imglist[a];
		hbhtml += '<img src="' + imgpath + imglist[a] + '" id="home_banner_'+a+'" class="slideshow" style="display:none;" width="980" height="180" />';
	}
	$('#home_banner').html(hbhtml);
	$(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 */
