/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	WCH.js - Windowed Controls Hider v2.02 - 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
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Credits: Mike Foster for x functions (cross-browser.com): fetching padding and border values
	- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	Based on idea presented by Joe King. Works with IE5.5+/Win
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	return the reference to Hider iFrame object
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_Hider(oLayer, vContainer) {
	//	if oLayer is not passed do nothing
	if ( typeof(oLayer) == "undefined" ) return null;
	//	proceed only with IE 5.0+
	var bBrowserOk = (document.all && document.getElementById && !window.opera);
	if ( !bBrowserOk ) return null;
	//	proceed only with IE 5.5+
	bBrowserOk = (bBrowserOk && typeof(document.body.contentEditable) != "undefined");
	if ( !bBrowserOk ) return null;

	oIframe = document.getElementById("hider" + oLayer.id);

	//	create iFrame Hider object, if it does no exist already
	if ( !oIframe ) {
		//	if containing element for Hider is not passed, default to body
		if ( typeof(vContainer) == "undefined" )
			oContainer = document.getElementsByTagName("BODY")[0];
		else if ( typeof(vContainer) == "string" )
			oContainer = document.getElementById(vContainer);
		else
			oContainer = vContainer;

		//	IE 6 has this property, IE 5 not. IE 5.5(even SP2) crashes when filter is applied, hence the check
		var sFilter = (typeof(document.compatMode) != "undefined") ? "filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);" : "";
		
		//	get z-index of the object
		var zIndex = oLayer.style.zIndex;
		if ( zIndex == "" ) zIndex = oLayer.currentStyle.zIndex;
		zIndex = parseInt(zIndex);

		//	if no z-index, do nothing
		if ( isNaN(zIndex) ) return null;
		//	if z-index is below 2, do nothing (no room for Hider)
		if (zIndex < 2) return null;

		//	go one step below for Hider
		zIndex--;
		oContainer.insertAdjacentHTML("afterBegin", '<iframe src="javascript:false;" id="hider' + oLayer.id + '" scroll="no" frameborder="0" style="position:absolute;visibility:hidden;' + sFilter + 'border:0;top:0;left;0;width:0;height:0;background-color:#ccc;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, vContainer) {
	oIframe = WCH_Hider(oLayer, vContainer);
	if (oIframe) {
		//	fetch and set size
		oIframe.style.width = oLayer.offsetWidth + "px";
		oIframe.style.height = oLayer.offsetHeight + "px";

		//	move to specified position
		oIframe.style.left = oLayer.offsetLeft + "px";
		oIframe.style.top = oLayer.offsetTop + "px";

		//	finally show
		oIframe.style.visibility = "visible";
	}
}

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	hide Hider (to see the windowed controls again)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
function WCH_ShowWndCtrl(oLayer, vContainer) {
	oIframe = WCH_Hider(oLayer, vContainer);
	if (oIframe) 
		oIframe.style.visibility = "hidden";
}

