// simple popup
function doPopup(url) {
    var w = arguments[1] ? arguments[1] : 565;
    var h = arguments[2] ? arguments[2] : 525;
    // this *should* work, but it won't unless we explicitly check for 0
    var scr = arguments[3] == 0 ? arguments[3] : 1;
    var name = "popup";
    var args = "toolbar=0,scrollbars="+scr+",location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left=10,top=10"
    if (typeof(popupWin) != "object"){
        popupWin = window.open(url,name,args);
    } else {
        if (!popupWin.closed){
            popupWin.location.href = url;
        } else {
        popupWin = window.open(url, name,args);
        }
    }
    popupWin.focus();
}

// IE incorrectly displays alt text on mouseover for images, kill it.
function suppressAltTxt(){ 
    var imgNodeList = document.body.getElementsByTagName("img");
    for (var i=0; i < imgNodeList.length; i++) {
        imgNodeList[i].setAttribute("alt", "");
    }
}

// sets table cells to have normalized width, regardless of how many columns.
function doCellNormalize() {
    var tableNodes = document.getElementsByTagName("table");
    if( tableNodes == "undefined" || tableNodes == null ){ return; }
    var thNodes = null;
    for (var i=0; i < tableNodes.length; i++) { 
	    var cellWidth = getPercentage( getNodeLength( tableNodes[i] ) );
        for (var j=0; j < thNodes.length; j++) {
            thNodes[j].style.width = cellWidth + "%";
        }
    }
    function getNodeLength(tblNode){
        var tableNode = tblNode;
        thNodes = tableNode.getElementsByTagName("th");
        return thNodes.length;
    }
    function getPercentage(lgth){
        return Math.floor(100 / lgth);
    }
}

// flash detection. if flash, display flash launcher image, else, nothing.
function checkFlash(){
    if( document.getElementById("right-flash-launcher") && detectFlash() ){
        document.getElementById("right-flash-launcher").style.display="block";
    }
}

// initialize when we have a DOM
function init(){
    if(browserFilter.Opera){ setNavWidth('listroot','img'); }
    doNavOnState();
    doNavEffects('listroot','li','ul');
    if(browserFilter.IE5up){ suppressAltTxt(); }
    doCellNormalize();
    checkFlash();
    createLayers("div","layerParent","div", 0, 20);
}

// funtion for dhtml layer
function createLayers(triggerElem, triggerClass, lyrElem, lyrOffsetX, lyrOffsetY){
	function wireTriggersByClassName(){
		var triggers = document.getElementsByTagName( triggerElem );
		for(var i=0; i < triggers.length; i++){
			if(triggers[i].className == triggerClass ){
				triggers[i].onmouseover=showLayer;
				triggers[i].onmouseout=hideLayer;
			}
		}
	}
	function showLayer(){ 
		var obj = this.getElementsByTagName( lyrElem )[0]; obj.style.display="block"; 
		}
	function hideLayer(){ 
		var obj = this.getElementsByTagName( lyrElem )[0]; obj.style.display="none"; 
		}
	wireTriggersByClassName();
}

window.onload=init;
