/*	
 *    Significant credit is due to Aleksandar Vacic @ http://www.aplus.co.yu,
 *    for a great explanation of browser quirks, and javascript to get around
 *    the IE SELECT wierdness.
 */
 
var FRAMER_Constructor = function() {
	//	exit point for anything but IE5.0+/Win
	if ( !(document.all && document.getElementById && !window.opera && navigator.userAgent.toLowerCase().indexOf("mac") == -1) ) {
		this.Apply = function() {};
		this.Discard = function() {};
		return;
	}
	//	private properties
	var _bIE55 = false;
	var _bIE6 = false;
	var _oRule = null;
	var _bSetup = true;
	var _oSelf = this;
	//	public: hides windowed controls
	this.Apply = function(vLayer, vContainer, bResize) {
		if (_bSetup) _Setup();
		if ( _bIE55 && (oIframe = _Hider(vLayer, vContainer, bResize)) ) {
			oIframe.style.visibility = "visible";
		} else if(_oRule != null) {
			_oRule.style.visibility = "hidden";
		}
	};
	//	public: shows windowed controls
	this.Discard = function(vLayer, vContainer) {
		if ( _bIE55 && (oIframe = _Hider(vLayer, vContainer, false)) ) {
			oIframe.style.visibility = "hidden";
		} else if(_oRule != null) {
			_oRule.style.visibility = "visible";
		}
	};
	//	private: returns iFrame reference for IE5.5+
	function _Hider(vLayer, vContainer, bResize) {
		var oLayer = _GetObj(vLayer);
				
		var oContainer = ( (oTmp = _GetObj(vContainer)) ? oTmp : document.getElementsByTagName("body")[0] );
		
		if (!oLayer || !oContainer) return;
		//	is it there already?
		//		1. first check does the layer has an ID at all. if not, assign one, using current timestamp, so we avoid duplicates
		if (oLayer.id == "")
			oLayer.id = "flyid" + (new Date()).getTime();
		//		2. then try to locate the hiding iFrame
		var oIframe = document.getElementById("flyhider" + oLayer.id);		
		//	if not, create it
		if ( !oIframe ) {
			//	IE 6 has this property, IE 5 not. IE 5.5(even SP2) crashes when filter is applied, hence the check
			var sFilter = (_bIE6) ? "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--;
			var sHiderID = "flyhider" + oLayer.id;
			oContainer.insertAdjacentHTML("afterBegin", '<iframe class="flyiframe" src="javascript:false;" id="' + sHiderID + '" 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(sHiderID);
			//	then do calculation
			_SetPos(oIframe, oLayer);
		} else if (bResize) {
			//	resize the iFrame if asked
			_SetPos(oIframe, oLayer);
		}
		return oIframe;
	};
	//	private: set size and position of the Hider
	function _SetPos(oIframe, oLayer) {
		//	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";
	};
	//	private: returns object reference
	function _GetObj(vObj) {
		var oObj = null;
		switch( typeof(vObj) ) {
			case "object":
				oObj = vObj;
				break;
			case "string":
				oObj = document.getElementById(vObj);
				break;
		}
		return oObj;
	};
	//	private: setup properties on first call to Apply
	function _Setup() {		
		_bIE55 = (typeof(document.body.contentEditable) != "undefined");
		_bIE6 = (typeof(document.compatMode) != "undefined");
		if (!_bIE55) {
			if (document.styleSheets.length == 0)
				document.createStyleSheet();
			var oSheet = document.styleSheets[0];
			oSheet.addRule(".flyhider", "visibility:visible");
			_oRule = oSheet.rules(oSheet.rules.length-1);
		}
		_bSetup = false;
	};
};
var FRAMER = new FRAMER_Constructor();  
function xGetElementsByClassName(clsName, parentEle, tagName) {
	var elements = null;
	var found = new Array();
	var re = new RegExp('\\b'+clsName+'\\b');
	if (!parentEle) parentEle = document;
	if (!tagName) tagName = '*';
	if (parentEle.getElementsByTagName) {elements = parentEle.getElementsByTagName(tagName);}
	else if (document.all) {elements = document.all.tags(tagName);}
	if (elements) {
		for (var i = 0; i < elements.length; ++i) {
			if (elements[i].className.search(re) != -1) {
				found[found.length] = elements[i];
			}
		}
	} return found;
}
function attachFrames()
{	        
	FRAMER = new FRAMER_Constructor();              
		var aTmp2, i, j, oLI, aUL, aA;
		var applyHere = document.getElementById('lnav');
		var aTmp = xGetElementsByClassName("t1", applyHere, "ul"); 

	for (i=0;i<aTmp.length;i++) {
		aTmp2 = aTmp[i].getElementsByTagName("li");
		for (j=0;j<aTmp2.length;j++) {
			oLI = aTmp2[j];
			aUL = oLI.getElementsByTagName("ul");
			//	if item has submenu, then make the item hoverable
			if (aUL && aUL.length) {
				oLI.UL = aUL[0];	//	direct submenu
				aA = oLI.getElementsByTagName("a");
				if (aA && aA.length)
					oLI.A = aA[0];	//	direct child link
				//	li:hover
				oLI.onmouseenter = function() {
					this.className += " flyhover";
					this.UL.className += " flyhoverUL";
					if (this.A) this.A.className += " flyhoverA";
					if (FRAMER) FRAMER.Apply( this.UL, this, true );
					//alert(this.className);
				};
				//	li:blur
				oLI.onmouseleave = function() {
					this.className = this.className.replace(/flyhover/,"");
					this.UL.className = this.UL.className.replace(/flyhoverUL/,"");
					if (this.A) this.A.className = this.A.className.replace(/flyhoverA/,"");
					if (FRAMER) FRAMER.Discard( this.UL, this );
				};
			}
		}	//for-li.submenu
	}	//for-ul.menu
	
	aTmp = xGetElementsByClassName("t2", applyHere, "ul"); 

	for (i=0;i<aTmp.length;i++) {
		aTmp2 = aTmp[i].getElementsByTagName("li");
		for (j=0;j<aTmp2.length;j++) {
			oLI = aTmp2[j];
			aUL = oLI.getElementsByTagName("ul");
			//	if item has submenu, then make the item hoverable
			if (aUL && aUL.length) {
				oLI.UL = aUL[0];	//	direct submenu
				aA = oLI.getElementsByTagName("a");
				if (aA && aA.length)
					oLI.A = aA[0];	//	direct child link
				//	li:hover
				oLI.onmouseenter = function() {
					this.className += " flyhover";
					this.UL.className += " flyhoverUL";
					if (this.A) this.A.className += " flyhoverA";
					if (FRAMER) FRAMER.Apply( this.UL, this, true );
					//alert(this.className);
				};
				//	li:blur
				oLI.onmouseleave = function() {
					this.className = this.className.replace(/flyhover/,"");
					this.UL.className = this.UL.className.replace(/flyhoverUL/,"");
					if (this.A) this.A.className = this.A.className.replace(/flyhoverA/,"");
					if (FRAMER) FRAMER.Discard( this.UL, this );
				};
			}
		}	//for-li.submenu
	}	//for-ul.menu
}