/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	navigation
   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
var defaultNav = null;
var currentNav = null;
var killTimer = null;

function onNavOver() {
	var liEl = this.parentNode;

	keepNavOpen();
	if (currentNav)
		hideSubNav(currentNav);

	showSubNav(liEl, true);
	currentNav = liEl;
}

function onNavOut() {
	keepNavOpen();
	killTimer = setTimeout('doHideCurrent()',200);
}

function keepNavOpen() {
	if (killTimer)
		clearTimeout(killTimer);
	killTimer = null;
}

function doHideCurrent() {
	// make sure there's something open
	if (! currentNav) return;
	
	hideSubNav(currentNav);
	
	if (defaultNav) {
		showSubNav(defaultNav, true);
		currentNav = defaultNav;
	} else {
		currentNav = null;
	}
}

function showSubNav(el,showRoll) {
	if (showRoll)
		el.className += ' rollover';
	
	el.onmouseout = onNavOut;
	el.onmouseover = keepNavOpen;
}

function hideSubNav(el) {
	var classIndex = el.className.indexOf('rollover');
	if (classIndex != -1)
		el.className = el.className.substring(0,classIndex - 1);
		
	el.onmouseout = null;
	el.onmouseover = null;
}

function initNav() {
	// we need DOM-compatibility
	if (! document.getElementById) return;
	
	// grab the UL element in the navigation DIV
	var rootEl = document.getElementById('navigation').firstChild;
	while (rootEl.tagName != 'UL')
		rootEl = rootEl.nextSibling;
		
	// loop through the root elements child nodes looking for LI tags
	for (var i = 0; i < rootEl.childNodes.length; i++) {
		if (rootEl.childNodes[i].tagName == 'LI') {
					
			// save the default nav, if there is one
			if (rootEl.childNodes[i].className.indexOf('rollover') != -1) {
				currentNav = defaultNav = rootEl.childNodes[i];
			}

			// add the event to each main nav item
			var linkEl = rootEl.childNodes[i].firstChild;
			while (linkEl.tagName != 'A')
				linkEl = linkEl.nextSibling;
			
			linkEl.onmouseover = onNavOver;
			
			// look for a subnav div
			linkEl.hasSub = false;
			var subEl = linkEl;
			while (subEl = subEl.nextSibling) {
				if ((subEl.tagName == 'DIV') && (subEl.className.indexOf('sub') != -1)) {
					linkEl.hasSub = true;
				}
			}
		}
	}
}


/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/
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 == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+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('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}

			aImages[i].onclick = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}

		}
	}
}


/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	site search
   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

	function searchFocus(box, text) {
		if (box.value == text) {
			box.value = '';
		}
	}
	
	function searchBlur(box, text) {
		if (box.value == '') {
			box.value = text;
		}
	}

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
	popup window functions
   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */


	var myWin = null;
	
	function gen_popup(theUrl, width, height) {
		
		theTitle = 'WinName';
		if ((! myWin) || (myWin.closed)) {
			
			theDim = 'width='+width+',height='+height+',left=10,top=10,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,';
	
			myWin = window.open(theUrl, theTitle, theDim);
			myWin.opener = window;
		} else {
			myWin.location = theUrl;
			myWin.focus();
			myWin.opener = window;
		}
	}
	
	
	function p_link(mylink, closeme){
	
		if ( (window.focus && window.opener)){
			window.opener.focus();
			window.opener.location.href=mylink;
		}
		if (closeme){
			window.close();
		}
	}


	
	



window.onload = function() {
	initNav();
	initRollovers();
}




