/*
	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);
			}
		}
	}
}
/*
	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"), "");
		}
	}
}

// sequencer for scriptaculous' imageswapping
function hedSwap() {
	if (!document.getElementById('sub_header')) { return; }
	if (document.getElementById('home')) {
		imgsrc = 'home_header_';
		dt = 5; // The delay timer. whole seconds value.
	} else {
		imgsrc = 'sub_header_';
		dt = 7; // The delay timer. whole seconds value.
	}
	hedqueue = new Array();
	for (a=0;a<1000;a++) { // Do not use more than 1,000 images!
		b = a + 1;
		thisimg = imgsrc + b;
		if (document.getElementById(thisimg)) {
			hedqueue[a] = document.getElementById(thisimg);
			if (a!=0) {
				new Effect.Opacity(thisimg,{duration:0,from:0,to:0,afterFinish:hedHider})
			} else {
				hedqueue[a].style.zIndex = 2;
			}
		} else {
			break;
		}
	}
	d = 0;
	for (a=0;a<40;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:0.5,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:0.5,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');
	return;
}
function launchAll() {
//	initRollovers();
//	sfHover();
	hedSwap();
}
window.onload = launchAll;

/* EOF */

