/* Initialisation ----------------------------------------------------------------------*/

var d = document, dE = d.documentElement, dB = d.body, dA = d.all;

var modules = new Object();
var library = new Object();

library={
	init:function(){
		if(d.getElementById){
			modules.stripeTable.init('stripeTable');
			modules.rollovers.init('_o','_h','globalNav');
			modules.disappearsMenu.init('searchMore','searchMoreActuator');
			modules.disappearsMenu.init('searchMore2','searchMoreActuator2');
			modules.ie.init();
			library.showPage();
		}
	},
	showPage:function(){ dE.style.visibility="visible"; },
	end:function(){ modules.ie.end(); }
};

window.onload = library.init;
window.onunload = library.end;


/* Functions --------------------------------------------------------------------------*/

if(!Array.prototype.push){
	Array.prototype.push = function(){
		for(var i = 0; i < arguments.length; i++){ this[this.length] = arguments[ i ]; }
		return this.length;
	}
}
function $($key, $parent){
	var elements = [];
	var tags = 'A LINK IMG P DIV OL UL LI DL DT DD SPAN EM STRONG LINK TABLE THEAD TBODY TR TD TH H5 H4 H3 H2 H1 OBJECT';
	$parent = (typeof $parent == 'undefined') ? false : $parent;
	keys = $key.split(',');
	for (var i = 0; i < keys.length; i++) {
		var key = keys[i];
		if(tags.match(key)){
			$parent = $parent ? $parent : d;
			elements = $parent.getElementsByTagName(key);
			return elements;
		} else if(d.getElementById(key)){
			element = d.getElementById(key);
			return element;
		} else {
			limit = 5;
			IE5 = navigator.userAgent.match('MSIE 5.');
			if(!IE5){
				$parent = $parent ? $parent : d;
				all = $parent.getElementsByTagName('*');
				for(var j=0, el; el=all[j]; j++){ if(el.className.match(' '+key) || el.className==key){ elements.push(el); } }
			} else {
				all = d.all;
				for(var j=0, el; el=all[j]; j++){ 
					if($parent){
						if(el.className.match(' '+key) || el.className==key){
							var $node = el;
							for(k=0; k<=limit; k++){ if($node.parentNode){ $node = $node.parentNode; } if($node == $parent){ elements.push(el); break; } }
						}
					} else { if(el.className.match(' '+key) || el.className==key){ elements.push(el); } }
				}
			}
		}
	}
	if(elements.length == 0){ return false }
	return elements;
}


/* Modules --------------------------------------------------------------------------*/

modules.stripeTable={
	init: function($idName){
		var tables = $idName ? $($idName) : $('TABLE');
		for(var i = 0, tables; table = tables[i]; i++){
			var tRows = $('TR',table);
			for(var j = 0; j<tRows.length; j++){
				if (tRows[j].parentNode.nodeName == 'TBODY') {
					tRows[j].onmouseover = function(){ this.className += (!this.className) ? 'over' : ' over'; }
					tRows[j].onmouseout = function(){ this.className = this.className.replace(' over', '').replace('over', ''); }
					tRows[j].className += (j%2) ? 'stripe' : '';
				}
			}
		}
	}
}


modules.rollovers = {
	init:function($ext, $hoverExt, $key){
		$key = $($key);
		$key[0]=!$key.length ? $key : $key[0];
		var rollElm = new Array();
		var preloadImg = new Array();
		for(var h=0, key; key=$key[h]; h++){
			rollElm[h] = $('IMG',key);
			j=0;
			for(var i=0, el; el=rollElm[h][i]; i++){
				j=0;
				if(el.src){
					j++;
					elExt = el.src.substring(el.src.length-4-$ext.length, el.src.length-4);
					if(elExt == $ext && !el.src.match($hoverExt+'.')){
						el.source = el.src;
						el.file = el.src.split('/')[el.src.split('/').length-1];
						el.fext = el.file.split('.')[1];
						el.hoverSrc = el.src.replace($ext+'.'+el.fext,$hoverExt+'.'+el.fext);
						preloadImg[j] = new Image();
						preloadImg[j].src = el.hoverSrc;
						j++;
						if(el.parentNode.nodeName == 'A'){
							el.parentNode.onfocus = function(){ this.firstChild.src = this.firstChild.hoverSrc; }
							el.parentNode.onblur = function(){ this.firstChild.src = this.firstChild.source; }
						}
						el.onmouseover = function(){ this.src = this.hoverSrc; }
						el.onmouseout = function(){ this.src = this.source; }
					}
				}
			}
		}
	}
}


modules.disappearsMenu = {
	init:function disappearsMenu(layerId, actuatorId){
		var layer = d.getElementById(layerId);
		var actuator = d.getElementById(actuatorId);

		if (layer == null || actuator == null) return;

		actuator.onclick = function(){
			var display = layer.style.display;
			this.style.backgroundPosition = (display == "none") ? "0 -88px" : "0 1px";
			this.style.backgroundPosition = (display == "block") ? "0 1px" : "0 -88px";
			layer.style.display = (display == "none") ? "block" : "none";
			layer.style.display = (display == "block") ? "none" : "block";
			return false;
		}
	}
}
















modules.ie={
	init:function(){
		this.flash();
	},
	flash:function(){
		if(navigator.userAgent.match('MSIE 6') ){
			$obj = $('OBJECT');
			for (var i=0,el; el=$obj[i]; i++){ el.outerHTML = el.outerHTML; }
		}
	},
	end:function(){
		if (d.all && window.attachEvent) {
			var elProps = [
				'data', 'onmouseover', 'onmouseout',
				'onmousedown', 'onmouseup', 'ondblclick',
				'onclick', 'onselectstart', 'oncontextmenu'
			];
			var all = d.all;
			for (var i = 0, el; el = all[i]; i++) {
				for (var j = 0, elProp; elProp = elProps[j]; j++) { el[elProp] = null; }
			}
		}
	}
}
