//- The Bravo Group - www.thebravogroup.net
//-Dynamic HTML Menu based on XML Data
//-==================================================================
//- Function List
//-==================================================================
//- function brInfo() - function used to get and determine Browser being used
//- function addMenuItem(lbl,subMenuArr,subw,sbar,altLbl)  - this function is used to add the menu item
//-  to the appropriate arrays for display later.
//- lib_obj.prototype.showIt = function(){this.css.visibility="visible"}
//- lib_obj.prototype.hideIt = function(){this.css.visibility="hidden"}
//- function lib_obj(obj,nest)
//- function libinit()
//- function displayChildNodes(o) => Displays the child nodes of a node
//-function getMenuData(f) 
//- function generateSubMenu(arr) 
//- function generateMenu
//----------------------------------------------------------------------------------------------------------------------------
function brInfo(){
    this.ver=navigator.appVersion;
    this.agent=navigator.userAgent;
    this.dom=document.getElementById?1:0;
    this.opera5=this.agent.indexOf("Opera 5")>-1;
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6;
    this.mac=this.agent.indexOf("Mac")>-1;
    this.ns6=(this.dom && parseInt(this.ver)>=5)?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5);
//    alert ("this object = " + this);
    return this;
}
function addMenuItem(lbl,subMenuArr,subW,sBar,altLbl,mLink) {
//- lbl - The is the Label
//- that will appear on the menu
//- subMenuArr - This is the subMenuArray including links for the subMenuItems
//- subW - This represents the width of the subMenu Item
//- sBar - The Label that will be displayed in the status bar
//- altLbl - The alternate label that will be displayed on hover
    idx=m.length;

    m[idx]=lbl;
    s[idx]=subMenuArr;
    sw[idx]=subW;
    su[idx]=sBar;
    st[idx]=altLbl;
    n[idx]=mLink;

    return;
}

function lib_doc_size(){
    this.x=0;
    this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
    this.y=0;
    this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
    this.x50=this.x2/2;
    this.y50=this.y2/2;
    return this;
}

lib_obj.prototype.showIt = function() {
//   alert(this.x+"\n"+this.y);
    this.css.left=120;
    this.css.visibility="visible"; 
//    alert("mouse X position is.."+window.event.clientX+"\n"+"mouse Y position is.."+window.event.clientY);
}

lib_obj.prototype.hideIt = function(){this.css.visibility="hidden"}

function libinit(){
    page=new lib_doc_size();
    o=new Array();
    for (i=0; i < ma; i++){
        o[i]=new lib_obj('sb'+i);
        o[i].hideIt();
     }
}
function lib_obj(obj,nest){
    nest=(!nest) ? "":'document.'+nest+'.';
    this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;
    this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;
    this.ref=bw.dom||bw.ie4?document:this.css.document;
    this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
    this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0;
    return this
}
function traverseArray(arr,lev) {
    var nexLevel, arrL;
    nextLevel=lev+1;
    arrL=arr.length;
    
    for(i=0;i<arrL;i++) {
        document.write(i+" - "+arr[i]);
    }
    
}
function getMenuData(f) {
    var numItem=0;
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.load(f);

    objNodeList = xmlDoc.documentElement.selectNodes("//mItem");
	if(objNodeList.length == 0) {
		document.getElementById("menu_so").style.height=0;
	} else {
		document.getElementById("menu_so").style.height=31;
	}	
//    alert(objNodeList.length);
    for (i=0;i<objNodeList.length;i++) {
       cn = objNodeList(i).childNodes;
       cnl=cn.length;
       ta=new Array();
       smStr="";
       for(j=0;j<cnl;j++) {
            if(cn(j).nodeName=="subMenu") {
                    subM=new Array();
                    var scn, scnl;
                    scn=cn(j).childNodes;
                    scnl=scn.length;
//                    alert("scnl = "+scnl);
                    for (k=0;k<scnl;k++) {
//                         alert(scn(k).nodeName+"\n"+scn(k).text);
                        subM[scn(k).nodeName]=scn(k).text;
                    }
                    smStr+=generateSubMenu(subM,ta["sWidth"]);
            } else {
                    ta[cn(j).nodeName]=cn(j).text;
//                    alert(cn(j).nodeName+" - "+cn(j).text);
            }
       }
       //Build Menu Item

    addMenuItem(ta["lbl"],smStr,ta["sWidth"],ta["sBar"],ta["altLbl"],ta["menuLink"]);
    }
}
function generateSubMenu(arr, sW) {
    var startAnchor,q, a, r, endAnchor,g,str, altLabel;

//    alert("generateSubMenu |"+sW+"|");
     g="";
    bw=new brInfo();
    if(bw.ie  && sW>0){
        g=" style='width: "+sW+"'";
    }else if (bw.ie){
        g=" style='width: 100%'";
    }else{
        z=6;
    }

    startAnchor="<a class='mi' "+g+" href='";
    q="' title='"+arr["subAltLbl"]+"' ";
//    altLabel=" alt='"+arr["sAltLabel"]+"' ";
    a="' onmouseover='window.status=\"";
    r="\"; return true' onmouseout='window.status=\"\"; return true'>";
    endAnchor="</a>";

    str=""+startAnchor+arr["subLink"]+q+altLabel+a+arr["subStatusLbl"]+r+arr["subLbl"]+endAnchor;
    
    return str;
}

function generateMenu(f) {
    bw=new brInfo();
    z=0;
    b=0;
    g="";

    if(bw.opera5||bw.ns6){
        b=2;
    }

    if(bw.ie){
        g=" style='width: 100%'";
    }else{
        z=6;
    }

    mt=10;  //Margin Top
    ml=50;  //Margin Left
    w=150;  //table Width
    mh=30;  //Cell Spacing- Margin Height
    mw=ml-w;
    k=0; // Vertical(k=0) or Horizontal(k=1)
    mt=mt-z;

    startAnchor="<a class='mi'"+g+" href='";
    q="' title='";
    a="' onmouseover='window.status=\"";
    r="\"; return true' onmouseout='window.status=\"\"; return true'>";
    endAnchor="</a>";

    div="<div class=sp></div>"

    m=new Array();  // Main Menu Label Array
    n=new Array();
    s=new Array();  // Sub Menu Array
    sw=new Array();  //Sub Menu Width Array - the width of the submenu item
    su=new Array();  // Status Bar Message Array
    st=new Array();  // Alternate Message Array

    mList=getMenuData(f);
    ma=m.length;   //- Length of Main Menu Array

if (k==1) {  // Horizontal Menu
    mw2=ml-w;
    for (i=0; i < ma; i++){

        document.write("<div id='sb"+i+"' class='mn' style='position: absolute; top:"+(mt+mh)+";left:"+(mw+=w+2)+";width:"+(sw[i]-b)+"' onmouseover='o["+i+"].showIt()' onmouseout='o["+i+"].hideIt()'>"+s[i]+"</div>")
    }
    for (i=0; i < ma; i++){
        document.write("<div style='position: absolute; top:"+mt+";left:"+(mw2+=w+2)+";width:"+w+"' onmouseover='o["+i+"].showIt()' onmouseout='o["+i+"].hideIt()'><a class='bi' "+g+" href='"+n[i]+q+st[i]+a+su[i]+r+m[i]+t+"</div>")
    }
} else { // Vertical Menu
    mw2=mt-mh;mt2=mt-mh+2
    for (i=0; i < ma; i++){
        //- Write SubMenu Code
        document.write("<div id='sb"+i+"' class='mn' style='position: absolute; top:"+(mt2+=(mh+1))+";left:"+(ml+w-10)+";width:"+sw[i]+"' onmouseover='o["+i+"].showIt()' onmouseout='o["+i+"].hideIt()'>"+s[i]+"</div>")
    }
    
    for (i=0; i < ma; i++){
        //- Write Menu Code
//        document.write("<div class='bi' style='position: absolute; top:"+(mw2+=(mh+1))+";left:"+ml+";width:"+w+"' onmouseover='o["+i+"].showIt()' onmouseout='o["+i+"].hideIt()'><a class='bi'"+g+" href='"+n[i]+q+st[i]+a+su[i]+r+m[i]+endAnchor+"</div>")

//        document.write("<div class='bi' style='position:absolute;' onmouseover='o["+i+"].showIt()' onmouseout='o["+i+"].hideIt()'><a class='bi' "+g+" href='"+n[i]+q+st[i]+a+su[i]+r+m[i]+endAnchor+"</div>")
	    img="<img border='0' src='http://www.daystar.com/images/specialoffers.gif' width='150' height='31'>";
        document.write("<div class='bi' style='position:absolute;' onmouseover='o["+i+"].showIt()' onmouseout='o["+i+"].hideIt()'><a class='bi' "+g+" href='"+n[i]+q+st[i]+a+su[i]+r+img+endAnchor+"</div>")

    }
}
libinit()
}
//-->
function showElements(o) {
    alert("Left = |"+o.css.left+"|");
}