/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	WindCtrlHider.js - Windowed Controls Hider v1.12 - uses iFrame to hide windowed controls and thus allow layers to draw over them
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	(c) Copyright 2003, Aleksandar Vacic, aleck@sezampro.yu, www.aplus.co.yu
	## This work is licensed under the Creative Commons Attribution-ShareAlike License.
	## To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Based on idea presented by Joe King.
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Uses following functions from X v3.12DOM
	xWidth, xHeight, xPageX, xPageY, xMoveTo, xResizeTo, xShow, xHide, xDef, xGetElementById
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	(possibly) uses AttachEvent.js, InsertElement.js
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

var WCH_bReady = false;
var WCH_oHiderContainer = null;
var WCH_bSupportHider = false;
var WCH_bSupportHiderFilter = false;
var WCH_aDropDown;

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Based on Browser Detect Lite  v2.1.4, http://www.dithered.com/javascript/browser_detect/index.html
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_BrowserDetect() {
	var ua = navigator.userAgent.toLowerCase();
	// browser name
	this.isIE = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) );
	// browser version
	this.versionMinor = parseFloat(navigator.appVersion);
	if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	this.versionMajor = parseInt(this.versionMinor);
	// specific browser shortcuts
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isMac   = (ua.indexOf('mac') != -1);
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	call this one in the window.onload
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_Initialize() {
	if (!document.getElementById && !document.documentElement) return;
	var oBrowser = new WCH_BrowserDetect();
	if ( !oBrowser.isIE || oBrowser.isMac ) return;

	WCH_oHiderContainer = document.getElementsByTagName("BODY")[0];
	WCH_bSupportHider = true;
	WCH_bSupportHiderFilter = true;

	if (!WCH_oHiderContainer)
		WCH_bSupportHider = false;

	if (WCH_bSupportHider) {
		//	neccesary browser-detection :(
		//	- detect IE 5.5, since it can't handle filter property as it should (even SP2 crashes)
		//	- detect IE 5.0x, since it have old-style iFrame object (windowed control) - and use control.style.visibility hiding for it
		if (oBrowser.isMac) {
			WCH_bSupportHiderFilter = false;
		} else {
			WCH_bSupportHider = !( oBrowser.isIE5x && !oBrowser.isIE55 );
			WCH_bSupportHiderFilter = ( WCH_bSupportHider && !oBrowser.isIE55 );
		}
	}

	//	this is out-of-this-script array that will actually collect pointers to windowed controls - CHANGE to accomodate your page
	if ( !WCH_bSupportHider && xDef(SG_aDDs) ) {
		WCH_aDropDown = SG_aDDs;
	}

	WCH_bReady = true;
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	return the reference to Hider iFrame object
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_Hider(oLayer, oNewHiderContainer) {
	if (!WCH_bSupportHider || !oLayer)
		return null;

	var sFilter = "";
	//	IE 5.5 SP2 crashes if filter is applied.
	if (WCH_bSupportHiderFilter) {
		sFilter = "filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);";
	}
	
	//	get z-index of the object
	var zIndex = oLayer.style.zIndex;
	if (zIndex == "")
		zIndex = xGetAnyCS(oLayer, "z-index");
	zIndex = parseInt(zIndex);
	if ( isNaN(zIndex) ) {
		zIndex = 2;
	}

	//	use hider container if passed
	var oHiderContainer;
	if ( (oNewHiderContainer = xGetElementById(oNewHiderContainer)) ) {
		oHiderContainer = oNewHiderContainer;
	} else {
		oHiderContainer = WCH_oHiderContainer;
	}

	//	create hiding iFrame object
	oIframe = document.getElementById("hider" + oLayer.id);
	if (!oIframe) {
		zIndex--;
		oHiderContainer.insertAdjacentHTML("afterBegin", '<iframe id="hider' + oLayer.id + '" scroll="no" frameborder="0" src="about:blank" style="position:absolute;visibility:hidden;border:0px;' + sFilter + 'top:0px;left;0px;width:0px;height:0px;background-color:#999;z-index:' + zIndex + ';"></iframe>');
		oIframe = document.getElementById("hider" + oLayer.id);
	}
	return oIframe;
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	show Hider (to hide the windowed controls and allow menu to overlap them)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_HideWndCtrl(oLayer, oNewHiderContainer) {
	if (!WCH_bReady) return;

	oIframe = WCH_Hider(oLayer, oNewHiderContainer);
	if (oIframe) {
		xMoveTo( oIframe, xLeft(oLayer), xTop(oLayer) );
		xResizeTo( oIframe, xWidth(oLayer), xHeight(oLayer) );
		xShow( oIframe );
	} else {
		WCH_HideWndCtrl4Oldies();
	}
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	hide Hider (to see the windowed controls again)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_ShowWndCtrl(oLayer, oNewHiderContainer) {
	if (!WCH_bReady) return;

	oIframe = WCH_Hider(oLayer, oNewHiderContainer);
	if (oIframe) 
		xHide( oIframe );
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Hide all windowed controls on the page.	Usage:  WCH_HideWndCtrl4Oldies()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_HideWndCtrl4Oldies() {
	if (!WCH_bReady) return;

	if (xDef(WCH_aDropDown)) {
		var oControl;
		for (var j=0;j<WCH_aDropDown.length;j++) {
			oControl = eval(WCH_aDropDown[j]);
			if (oControl)
				xHide( oControl );
		}
	}
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Show all windowed controls on the page.	Usage:  WCH_ShowWndCtrl4Oldies()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_ShowWndCtrl4Oldies() {
	if (!WCH_bReady) return;

	if (xDef(WCH_aDropDown)) {
		var oControl;
		for (var j=0;j<WCH_aDropDown.length;j++) {
			oControl = eval(WCH_aDropDown[j]);
			if (oControl)
				xShow( oControl );
		}
	}
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Initializator must be called on window.onload. Adjust this code to accomodate your web page needs
	(this script is useless if you are not using some other DHTML scripts, and than you will probably have several onload functions.
		one solution: www.aplus.co.yu/sparks/attachevent/)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
AE_AttachEvent("onload", "WCH_Initialize");