/*
	ShowHideLayer Script
	Author: Warwick Adderley: warwick@pretzel.com.au
	Version: 2.3
	Version History:
		2.1 - Added function mouseOff() and var popup.mouseOffAnchor
		2.2 - Added var doc to increase performance.
		2.3 - Added function _resetMenu for dropmenu.js compatibility
		2.4 - Added cascade property and modified menuClose() and hide() functions
*/
var lshowhide = true;

var doc = document;
var isNav = (!(!doc.layers));
var version = parseFloat(navigator.appVersion);
var isIE = (!(!doc.all));
var isDOMCompliant = (!(!document.addEventListener))
var hasLayers = ((isNav && version >= 4.04) || isIE || isDOMCompliant);
var _definedpopUps = new Array();
var mouseX, mouseY;

if (isIE)
	doc.onmousemove = updateCursorIE;

if (isDOMCompliant)
	doc.addEventListener('mousemove', updateCursorDOMCompliant, false);

if (isNav) {
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove = updateCursorNS;
}

function updateCursorIE() {
	mouseX = event.clientX + doc.body.scrollLeft;
	mouseY = event.clientY + doc.body.scrollTop;
}

function updateCursorDOMCompliant(e) {
	mouseX = e.pageX;
	mouseY = e.pageY;
}

function updateCursorNS(e) {
	mouseX = e.pageX;
	mouseY = e.pageY;
}

function hideAll() {
	if (hasLayers) {
		if (!(!popUp.prototype.hideAll)) {
			popUp.prototype.hideAll();
		}
	}
}

function showHide(theLayer) {
	if (hasLayers) {
		if (!(!_definedpopUps[theLayer])) {
	 		_definedpopUps[theLayer].showHide();
	 	}
	}
}

function mouseOff(theLayer) {
	if (hasLayers) {
		if (!(!_definedpopUps[theLayer])) {
	 		_definedpopUps[theLayer].mouseOffAnchor = true;
	 	}
	}	
}

function menuClose(thePopUp) {
	var mw = thePopUp.mouseWithin();
	
	if (thePopUp.mouseOffAnchor) {
		if (mw == -1) {
			thePopUp.hide();
			thePopUp.resetMenu();
		}
		else if (thePopUp.cascade) {
			thePopUp.hide(mw + 1);
		}
	}
}

function applyFilters(theElement) {
	if (theElement.filters.length > 0) {
		for (var e in theElement.filters) {
			if (typeof(theElement.filters[e]) == "object" && typeof(theElement.filters[e].Apply) != "undefined") {
				theElement.filters[e].Apply();
				theElement.filters[e].Play();
			}
		}
	}
}

function _showHide() {
	this.hideAll();
	
	this.show();
}
	
function _show() {
	for (var i in this.elements) {
		if (isIE)
			applyFilters(this.elements[i].el);
		
		this.elements[i].st.visibility = 'visible';
		
		if (this.menu)
			this.menuClose();
	}
}

function _hide(fromIndex) {
	var fi = (fromIndex) ? fromIndex : 0;
	
	for (var i = fi; i < this.elements.length; i++) {
		if (this.elements[i].st.visibility != 'hidden' && this.elements[i].st.visibility != 'hide') {
			if (isIE)
				applyFilters(this.elements[i].el);
			
			this.elements[i].st.visibility = 'hidden';
		}
	}
	
	if (this.menu && !this.cascade || this.cascade && fi == 0)
		this.resetMenu();
}

function _resetMenu() {
	clearInterval(this.timer);
	this.mouseOffAnchor = false;	
}

function _hideAll() {
	for (var i in _definedpopUps) {
		if (!(!_definedpopUps[i])) {
			_definedpopUps[i].hide();
		}
	}
}

function _menuClose() {
	this.resetMenu();
	this.timer = setInterval("menuClose(_definedpopUps['" + this.name + "'])", 700);
}

function _mouseWithin() {
	var retVal = -1;
	
	for (var i in this.elements) {
		var e = this.elements[i];
		var x, y, w, h;
		
		if (isIE || isDOMCompliant) {
			x = e.el.offsetLeft;
			y = e.el.offsetTop;
			r = e.el.offsetWidth + x;
			b = e.el.offsetHeight + y;
		}
		else if (isNav) {
			x = e.st.left;
			y = e.st.top;
			r = e.el.document.width + x;
			b = e.el.document.height + y;
		}
		
		if (x < mouseX && y < mouseY && r > mouseX && b > mouseY)
			retVal = parseInt(i);
	}
	
	return retVal;
}

function getLayerName(theString) {
	var retStr = new String();
	
	if (theString.indexOf(".") != -1)
		retStr = theString.substring(theString.lastIndexOf(".") + 1);
	else
		retStr = theString;
	
	return retStr;
}
	
function popUp() {
	if (hasLayers) {
		this.elements			= new Array();
		this.name				= null;
		this.menu				= false;
		this.cascade			= false;
		this.timer				= null;
		this.mouseOffAnchor		= false;
		
		for (var i = 0; i < popUp.arguments.length; i++) {
			this.elements[i] = new Object();
			
			if (isNav) {
				this.elements[i].st = (typeof(popUp.arguments[i]) == "string") ? eval('doc.layers.' + popUp.arguments[i]) : popUp.arguments[i];
				this.elements[i].el = this.elements[i].st;
			}
			else if (isIE) {
				this.elements[i].st = (typeof(popUp.arguments[i]) == "string") ? doc.all[getLayerName(popUp.arguments[i])].style : popUp.arguments[i].style;
				this.elements[i].el = (typeof(popUp.arguments[i]) == "string") ? doc.all[getLayerName(popUp.arguments[i])] : popUp.arguments[i];
			}
			else if (isDOMCompliant) {
				this.elements[i].st = (typeof(popUp.arguments[i]) == "string") ? doc.getElementById(getLayerName(popUp.arguments[i])).style : popUp.arguments[i].style;
				this.elements[i].el = (typeof(popUp.arguments[i]) == "string") ? doc.getElementById(getLayerName(popUp.arguments[i])) : popUp.arguments[i];
			}
		}
		
		this.name = (isNav) ? this.elements[0].el.id : this.elements[0].el.id;
		
		_definedpopUps[this.name] = this;
		
		popUp.prototype.showHide = _showHide;
		popUp.prototype.hideAll = _hideAll;
		popUp.prototype.hide = _hide;
		popUp.prototype.show = _show;
		popUp.prototype.menuClose = _menuClose;
		popUp.prototype.mouseWithin = _mouseWithin;
		popUp.prototype.resetMenu = _resetMenu;
	}
}