/*
	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() {
	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.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);
			}
		}
	}
}
// a merger of initRollovers and sfHover to accommodate this site's list element behaviors.
function rollHover() {
	if (!document.getElementById("nav")) { return; }
	aPreLoad = new Array();
	navImg = '';
	navTops = document.getElementById("nav").getElementsByTagName("LI");
	for (a=0;a<navTops.length;a++) {
		if (!navTops[a].className) { navTops[a].className = ''; }
		// let's assume we will work with only one image in each qualifying LI element. otherwise, WORLD OF HURT
		for (e=0;e<navTops[a].getElementsByTagName('img').length;e++) {
			if (navTops[a].getElementsByTagName('img')[e].className.match('hover')) {
				navImg = navTops[a].getElementsByTagName('img')[e];
				src = navImg.getAttribute('src');
				ftype = src.substring(src.lastIndexOf('.'), src.length);
				hsrc = src.replace(ftype, '_over'+ftype);
				navImg.setAttribute('hsrc', hsrc);
				navImg.setAttribute('osrc', src);
				navTops[a].onmouseover = function() {
					thisImg = this.getElementsByTagName('img')[0];
					thisImg.setAttribute('src', thisImg.getAttribute('hsrc'));
					this.className += ' over';
					for (b=0;b<navTops.length;b++) { // This is redundant. Unfortunately, Safari 2 misbehaves without it.
						if (navTops[b].className.match('over') && navTops[b]!=this) {
							navTops[b].className = navTops[b].className.replace(/over\b/,'');
						}
					}
					return;
				}
				navTops[a].onmouseout = function() {
					thisImg = this.getElementsByTagName('img')[0];
					thisImg.setAttribute('src',thisImg.getAttribute('osrc'));
					this.className = this.className.replace(/over\b/, '');
					return;
				}
			}
			break;
		}
	}
}
// sequencer for scriptaculous' imageswapping
function hedSwap() {
	// the following function tests for MSIE 6, and prevents the function from executing if true (IE 6 is not playing nice).
	if (testForIE6()==1) { return; }
	if (!document.getElementById('header_banners')) { return; }
	document.getElementById('content').style.opacity = '0.99999';
	document.getElementById('footer').style.opacity = '0.99999';
	imgsrc = 'header_banner_right_'; // ID and filename fragment, not including number and filetype
	imgcount = 12; // the number of images to flip through.
	dt = 7; // The delay timer. whole seconds value.
	wt = 7; // Delay timer for the first fade - gives images some time to load before the flipping starts.
	ft = 0.5; // The fader timer (Time it takes an object to fade to the next one). Whole seconds value.
	hedqueue = new Array();
	for (a=0;a<imgcount;a++) {
		if (a==0) {
			hedqueue[a] = document.getElementById('header_banner_right_1');
			hedqueue[a].style.zIndex = 2;
		} else {
			b = a + 1;
			oldsrc = hedqueue[0].id;
			newsrc = hedqueue[0].id.replace(/\d/,b);
			hedqueue[a] = new Image();
			hedqueue[a].src = hedqueue[0].src.replace(oldsrc,newsrc);
			hedqueue[a].id = hedqueue[0].id.replace(oldsrc,newsrc);
			hedqueue[a].className = hedqueue[0].className + ' ';
			hq_last = hedqueue[0].id.replace(/\d/,a);
			new Insertion.After(hq_last,'<img src="' + hedqueue[a].src + '" id="' + hedqueue[a].id + '" class="' + hedqueue[a].className + '" usemap="#header_banner_map" />');
		}
	}
	if (hedqueue.length<=1) { return; } // there's nothing to swap.
	for (a=0;a<hedqueue.length;a++) {
		if (a!=0) {
			new Effect.Opacity(hedqueue[a].id,{duration:0,from:0,to:0,queue:'end',afterFinish:hedHider});
			hedqueue[a].className = hedqueue[a].className.replace(/hed_img_hid/,'');
		} else {
			new Effect.Opacity(hedqueue[a].id,{duration:wt,from:1,to:1,queue:'end'});
		}
	}
	document.getElementById('content').style.opacity='100%';
	d = 0;
	for (a=0;a<2;a++) { // can i has INFINITE LOOP?
		for (e=0;e<hedqueue.length;e++) {
			if (d==e) {
				hedqueue[e].style.zIndex = 1;
			} else {
				newimg = hedqueue[e].id;
				oldimg = hedqueue[d].id;
				if (e!=0) {
					new Effect.Opacity(newimg,{duration:ft,from:0,to:1,delay:dt,queue:'end'});
					new Effect.Opacity(oldimg,{duration:0,from:1,to:0,queue:'end'});
				} else {
					new Effect.Opacity(newimg,{duration:0,from:0,to:1,queue:'end'});
					new Effect.Opacity(oldimg,{duration:ft,from:1,to:0,delay:dt,queue:'end'});
				}
			}
			d = e; // cache the previous value of 'e' for the coming loop cycle
		}
//		a = 0; // INFINITE LOOP
	}
/*
*/
	return;
}
function hedHider(obj) {
	$(obj.element.id).removeClassName('hed_img_hid');
	$(obj.element.id).setStyle({zIndex:'1'});
	return;
}
// Tests for MSIE 6. Returns 1 if true.
function testForIE6() {
	z = 0;
	/*@cc_on
		if (@_jscript_version <= 5.6) { z = 1; }
	@*/
	return z;
}
function launchAll() {
	hedSwap()
	initRollovers();
//	sfHover();
	rollHover();
}
window.onload = launchAll;

/* EOF */
