// popup menu support 
// Jamie Balling, Optimal Auctions Inc

// -------------------------- utility methods to determine object size, & position ------------------------------

var isNS = (navigator.appName == "Netscape");
var isMacIE = ( (navigator.userAgent.indexOf("IE 4") > -1) && (navigator.userAgent.indexOf("Mac")  > -1) );
var layerRef = (isNS) ? "document" : "document.all";
var styleRef = (isNS) ? "" : ".style";
var isDynamic = ( ((document.layers && document.layers['layerTest']) || (document.all && document.all['layerTest'])) && !isMacIE );


function getXCoord(imgID) {
    if (isNS) 
        xPos = document.images[imgID].x;
    else 
        xPos = getIEXCoord(imgID)
    return xPos;
}

function getYCoord(imgID) {
    if (isNS) 
        yPos = document.images[imgID].y;
    else 
        yPos = getIEYCoord(imgID);
    return yPos;
}

function getWidth(imgID) {
    if (isNS) 
        w = document.images[imgID].width;
    else 
        w = eval(imgID).offsetWidth;
    return w;
}

function getIEXCoord(imgElem) {
    xPos = eval(imgElem).offsetLeft;
    tempEl = eval(imgElem).offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}

function getIEYCoord(imgElem) {
    yPos = eval(imgElem).offsetTop;
    tempEl = eval(imgElem).offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    // to return the bottom edge of the image, add the height
    yPos += eval(imgElem).offsetHeight;
    return yPos;
}

// -------------------------- methods to draw menu items ------------------------------

function drawMenuDiv(menuId,x,y,width,height) {
    //var x = getXCoord(refImage);
    //var y = getYCoord(refImage);
    //divWidth = Math.max(getWidth(refImage)-2,200);
    document.write("<div id='" + menuId + "'" +
                       " class='menu' " +
                       " style='position:absolute; left:" + x + "px; top:" + y + "px; width:" + width + "px;height:" + height + "px; z-index:101;'" +
                       " onmouseover=\"setVisible('" + menuId + "',true)\"" +
                       " onmouseout=\"setVisible('" + menuId + "',false)\"" + 
                       ">");
}

function drawMenuItem(menuId,menuItem,menuLink,isHeading) {
    overClass="menuItemOver"; 
    outClass="menuItemOut";
    if (isHeading) {
        overClass="menuHeadingOver"; 
        outClass="menuHeadingOut";
    }
    document.write("<div class='" + outClass + "' " + 
                        " onmouseover=\"this.className='" + overClass + "';setVisible('" + menuId + "',true);\" " + 
                        " onmouseout=\"this.className='" + outClass + "';setVisible('"+ menuId +"',false);\">");
    document.write("<a class='menu' href='" + menuLink + "'>" + menuItem + "</a>");
    document.write("</div>");
}

function prepareMenu(menuId,menuArray,x,y,width,height) {
    // first draw the outer div for this element
    drawMenuDiv(menuId,x,y,width,height);
    // now create the menu items from the passed array
    for (var i=0; i<menuArray.length; i++) {
        drawMenuItem(menuId,menuArray[i][0],menuArray[i][1],false)	// menuArray[i][2]
    }
    document.write("</div>");
}


// this function accepts an array of menus and builds a summary menu
function prepareSummaryMenu(menuId,menuSumm,x,y,width,height) {
    // first draw the outer div for this element
    drawMenuDiv(menuId,x,y,width,height);
    // now create the menu items from the passed summary array
    for (var c=0; c<menuSumm.length; c++) {
        var menuArray = menuSumm[c][1];
        // if the menu item is an array (i.e. object) loop through displaying contents
        if (typeof(menuArray)=='object') {
            document.write("<div class='menuHeadingOut'>" + menuSumm[c][0] + "</div>");
            for (var i=0; i<menuArray.length; i++) {
                drawMenuItem(menuId,menuArray[i][0],menuArray[i][1],false);
            }
        } else {
            drawMenuItem(menuId,menuSumm[c][0],menuSumm[c][1],true);
        }
    }
    document.write("</div>");
}

function setVisible(menuId,isVisible) {
    var param = "hide";
    if (isVisible)
        param = "show";
    MM_showHideLayers(menuId,param);
}

function MM_findObj(n, d) { //v4.0
    var p,i,x;  
    if(!d) 
        d=document; 
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
     }
    if(!(x=d[n])&&d.all) 
        x=d.all[n]; 
    for (i=0;!x&&i<d.forms.length;i++) 
        x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
        x=MM_findObj(n,d.layers[i].document);
    if(!x && document.getElementById) 
        x=document.getElementById(n);
    return x;
}

function MM_showHideLayers() { //v3.0
    var i,p,v,obj,args=MM_showHideLayers.arguments;
    for (i=0; i<(args.length-1); i+=2) 
        if ((obj=MM_findObj(args[i]))!=null) { 
            v=args[i+1];
            if (obj.style) { 
                obj=obj.style; 
                v=(v=='show')?'visible':(v='hide')?'hidden':v; 
             }
            obj.visibility=v; 
         }
}







// -------------------------- misc utility methods ------------------------------

function MultiDimensionalArray(iRows,iCols)  { 
    var i; 
    var j; 
    var a = new Array(iRows); 
    for (i=0; i < iRows; i++) { 
        a[i] = new Array(iCols); 
        for (j=0; j < iCols; j++) { 
            a[i][j] = ""; 
        } 
    } 
    return(a); 
}

function setImage(img_name,img_file) {
    document[img_name].src = "images/" + img_file;
}

