window.onerror = new Function("return true");

if (!window.saveInnerWidth) {
	window.onresize = sub_resize;
	window.saveInnerWidth = window.innerWidth;
	window.saveInnerHeight = window.innerHeight;
}
if (document.all) { 
  window.onscroll = sub_setPosition;
}

// fuer Scrollbalken-Bug bei Mac IE 5.0
if ((navigator.userAgent.indexOf("MSIE 5.0") != -1) && (navigator.userAgent.indexOf("Mac_PowerPC") != -1)) {
   window.resizeBy(-1,-1);
}

function sub_main() {
    sub_setPosition();
    for (var i=0; i<menu.length;i++){menu[i].CloseUp();}
    if (window.fusObject) {
        Init_Fus(); // Farben und Stoffe initialisieren!
    }
    initok = true;
    // Call our popup function
    showPopup();
}

/*#############################################################################
#                                                                             #
#   Allgemeine Funktionen                                                     #
#                                                                             #
#############################################################################*/


function mnuLink(/*String*/ url, /*String*/ target) {
    window.open(url, (target!="")? target:"_self");
}

function mnuStatus(/*String*/ text) {
    window.status = text;
    return true;
}
/*#############################################################################
#                                                                             #
#   Funktionen für den Zusammenbau des Menue                                  #
#                                                                             #
#############################################################################*/
function Menu(/*String*/ bgColor, /*String*/ spacer) {
    this.bgColor = bgColor;                         // String[] Backgroundcolor
    this.spacer = 'i/dot_trans.gif';                           // String[] Placeholder
    this.addItem = addItem;                         // Sub addItem()
    this.addSubItem = addSubItem;                   // Sub addSubItem()
    this.CloseUp = CloseUp;                         // Sub CloseUP()
    this.HTMLstr = '';                              // String[] Global Table
    this.MENUstr = '';                              // String[] Menu's
    this.SUBMstr = '';                              // String[] SubMenu's
    this.subitems = 0;                              // Int Count of SubMenu's
      
    this.HTMLstr+= '<!-- MENU PANEL DECLARATION BEGINS -->\n';
    this.HTMLstr+= '<table cellspacing="0" cellpadding="0" border="0" width="<!-- IMGWIDTH -->">\n';
    this.HTMLstr+= '<tr>\n';
    this.HTMLstr+= ' <td rowspan="4" valign="top"><a href="javascript://" onmouseover="mnuClose(\'<!-- MNUID -->\')"><img src="'+this.spacer+'" width="30" height="<!-- IMGHEIGHT -->" border="0"></a></td>';
    this.HTMLstr+= ' <td valign="top"><a href="javascript://" onmouseover="mnuClose(\'<!-- MNUID -->\')"><img src="'+this.spacer+'" width="<!-- IMGWIDTH -->" height="30" border="0"></a></td>';
    this.HTMLstr+= ' <td rowspan="4" valign="top"><a href="javascript://" onmouseover="mnuClose(\'<!-- MNUID -->\')"><img src="'+this.spacer+'" width="30" height="<!-- IMGHEIGHT -->" border="0"></a></td>';
    this.HTMLstr+= '</tr>\n';
    this.HTMLstr+= '<tr>\n';
    this.HTMLstr+= ' <td valign="top" height="<!-- REFHEIGHT -->" width="<!-- IMGWIDTH -->"><!-- HIGHLINK_S --><img src="<!-- HIGHIMAGE -->" width="<!-- IMGWIDTH -->" height="<!-- REFHEIGHT -->" border="0" style="cursor:<!-- POINTER -->; cursor:<!-- HAND -->;"><!-- HIGHLINK_E --></td>';
    this.HTMLstr+= '</tr>\n';
    this.HTMLstr+= '<!-- SUB_MENU -->\n';
    
    this.SUBMstr+= '<tr>\n';
    this.SUBMstr+= ' <td align="left" valign="top" bgcolor="'+ this.bgColor +'" width="<!-- IMGWIDTH -->">\n';
    this.SUBMstr+= ' <table border="0" cellpadding="0" cellspacing="0" width="100%">\n';
    this.SUBMstr+= ' <tr><td height="5"><img src="'+this.spacer+'" width="1" height="5" border="0"></td></tr>\n';
    this.SUBMstr+= '<!-- MAIN_MENU -->\n';
    this.SUBMstr+= ' <tr><td height="5"><img src="'+this.spacer+'" width="1" height="5" border="0"></td></tr>\n';
    this.SUBMstr+= ' </table>\n';
    this.SUBMstr+= ' </td>\n';
    this.SUBMstr+= '</tr>\n';
    
    this.HTMLstr+= '<tr>';
    this.HTMLstr+= ' <td valign="bottom"><a href="javascript://" onmouseover="mnuClose(\'<!-- MNUID -->\')"><img src="'+this.spacer+'" width="<!-- IMGWIDTH -->" height="30" border="0"></a></td>';
    this.HTMLstr+= '</tr>\n';
    this.HTMLstr+= '</table>\n';
    this.HTMLstr+= '<!-- MENU PANEL DECLARATION ENDS -->\n';
}

function addItem(/*String*/ idContainer, /*String*/ idImage, /*String*/ highImage, /*String [optional]*/ link_href, /*String [optional]*/ link_target, /*String [optional]*/ link_text) {
    this.idContainer = idContainer;                 // String[] Name of Div-TAG
    this.idImage = idImage;                         // String[] Name of Image-TAG ID
    this.hImage = highImage;                        // String[] Path Highlight-Image
    
    this.HTMLstr = replaceIt(this.HTMLstr, "<!-- MNUID -->", this.idContainer);
    if (link_href != '') {
        if (link_target == '' || !link_target) link_target = "_self";
        var tmp = '<a href="javascript:mnuLink(\''+link_href+'\',\''+link_target+'\')" [S]>';
        var lnk = (link_text != '') ? 'onMouseOver="return mnuStatus(\''+link_text+'\')"' : '';
        if (lnk) tmp = replaceIt(tmp, "[S]", lnk);
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- HIGHLINK_S -->", tmp);
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- HIGHIMAGE -->", this.hImage);
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- HIGHLINK_E -->", "</a>");
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- POINTER -->", "pointer");
    }
    else {
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- HIGHLINK_S -->", "");
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- HIGHIMAGE -->", this.hImage);
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- HIGHLINK_E -->", "");
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- POINTER -->", "default");
    }
}

function addSubItem(/*String*/ highColor, /*String*/ lowColor, /*String*/ link_href, /*String*/ link_target, /*String*/ style_class, /*String*/ link_text) {
    if (this.MENUstr.indexOf('<!-- NEXT ITEM OF SUB MENU -->')>-1) {
        var MENUItem = '<tr><td height="15" onMouseOver="mnuChangeW3Cbg(this, \''+highColor+'\');mnuStatus(\''+link_text+'\')" onMouseOut="mnuChangeW3Cbg(this, \''+lowColor+'\')" onclick="mnuLink(\''+link_href+'\',\''+link_target+'\')" style="cursor:pointer; cursor:hand;"><img src="'+this.spacer+'" width="12" height="1" border="0"><a href="javascript:mnuLink(\''+link_href+'\',\''+link_target+'\')" class="'+style_class+'" onmouseover="return mnuStatus(\''+link_text+'\')">'+link_text+'</a></td></tr>\n';
        this.MENUstr = replaceIt(this.MENUstr, "<!-- NEXT ITEM OF SUB MENU -->", MENUItem);
        this.MENUstr += '<!-- NEXT ITEM OF SUB MENU -->';
    }
    else {
        this.MENUstr += '<tr><td height="15" onMouseOver="mnuChangeW3Cbg(this, \''+highColor+'\');mnuStatus(\''+link_text+'\')" onMouseOut="mnuChangeW3Cbg(this, \''+lowColor+'\')" onclick="mnuLink(\''+link_href+'\',\''+link_target+'\')" style="cursor:pointer; cursor:hand;"><img src="'+this.spacer+'" width="12" height="1" border="0"><a href="javascript:mnuLink(\''+link_href+'\',\''+link_target+'\')" class="'+style_class+'" onmouseover="return mnuStatus(\''+link_text+'\')">'+link_text+'</a></td></tr>\n';
        this.MENUstr += '<!-- NEXT ITEM OF SUB MENU -->';
    }
    this.subitems = this.subitems + 1;
}


function CloseUp() {
    var oL = getLayerRef(this.idContainer);         // get Object Div-TAG
    var oI = getImageRef(this.idImage);             // get Object IMG-TAG
    var oIP = getImagePos(oI);                      // get Coord from Object IMG-TAG
    this.HTMLstr = replaceIt(this.HTMLstr, "<!-- IMGWIDTH -->", oIP.width);
    this.SUBMstr = replaceIt(this.SUBMstr, "<!-- IMGWIDTH -->", oIP.width);
    this.HTMLstr = replaceIt(this.HTMLstr, "<!-- REFHEIGHT -->", oIP.height);
    if (this.subitems > 0) {
        this.SUBMstr = replaceIt(this.SUBMstr, "<!-- MAIN_MENU -->", this.MENUstr);
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- SUB_MENU -->", this.SUBMstr);
    }
    else {
        this.HTMLstr = replaceIt(this.HTMLstr, "<!-- SUB_MENU -->", "");
    }
    changeLayerContent(oL,this.HTMLstr);
    var oLC = getLayerCanvas(this.idContainer);
    this.HTMLstr = replaceIt(this.HTMLstr, "<!-- IMGHEIGHT -->", oLC.height);
    changeLayerContent(oL,this.HTMLstr);
}


function sub_resize() {
    if (!initok) return;
    sub_setPosition();
    if (window.fusObject) {// Farben und Stoffe
        fus_setPosition();
    }
}

function sub_setPosition() {
    if (!initok) return
    setLayerVisibilityByPrefix('mnu_', false);
}


/*##############################################################################
#                                                                              #
#  Mouseover / Mouseout Function                                               #
#  Steuerung der Aufklappmenu's                                                #
#                                                                              #
##############################################################################*/

function mnuOpen(/*String*/nameLayer, /*String*/nameImage) {
    if (!nameLayer || !initok) return
    mnuClose();
    var objLay = getLayerRef(nameLayer);
    var objImg = getImageRef(nameImage);
    var objImgPos = getImagePos(objImg);
    var objLayCoord = new Coord(objImgPos.x -30, (objImgPos.y + objImgPos.height) -50);
    setLayerPos(objLay,objLayCoord);
    setLayerVisibility(objLay, true);
}

function mnuClose(/*String [optional]*/ nameLayer) {
    if (nameLayer) {
        var objLay = getLayerRef(nameLayer);
        setLayerVisibility(objLay, false);
    }
    else {
        setLayerVisibilityByPrefix('mnu_', false);
    }
}

function mnuChangeW3Cbg(obj, Color) {
    /* Bei Links hat Opera Probleme den Clip-Bereich einzuhalten */
    if (!document.getElementById) return;
    obj.style.backgroundColor = Color
}

