/** Version       : 1.0
  * Last modified : (K. Breynck) 06.12.2005
  * Author        : Interone Hamburg (K. Breynck)
  * Copyright     : BMW Group 2002-2004
  *
  * Unique scripting solutions that are provided for BMW Group sites are for use exclusively
  * within BMW Group projects. No other use of these solutions is permitted.
  *
  **/

/*************************
 * START main navigation *
 *************************/
var currentMenuId;
var menuAmount;

var currentHighlightedMenuId;
var screenResolution = (((window.screen) && (screen.width < 1024)) ? 800 : "");

function getTdIdByMenuId(MenuId) {
  for (var i = 0; i < document.getElementsByTagName("td").length; i++) {
    if(document.getElementsByTagName("td")[i].id == 'content'+MenuId) {
      return i;
    }
  }
}

function setBorderColor (MenuId, HighlightMode) {
  borderColor = (HighlightMode)? "#ffffff" : "#666666";
  bottomBorderColor = (HighlightMode)? "#dddddd" : "#666666";
  
  var menuTdId = getTdIdByMenuId(MenuId);

  document.getElementsByTagName("td")[(menuTdId-1)].bgColor = borderColor;
  document.getElementsByTagName("td")[(menuTdId+1)].bgColor = borderColor;

  firstBottomNr = (document.getElementsByTagName("td").length/2) + (2*MenuId) -2;
  for (var j=firstBottomNr; j < firstBottomNr+3; j++) {
    document.getElementsByTagName("td")[j].bgColor = bottomBorderColor;
  }
}

function intitMainMenu(MenuId) {
  var logoDynLayer           = DynLayer.getInline("logoLayer");
  var mainNavigationDynLayer = DynLayer.getInline("mainNavigationLayer");
  var logoId                 = ((location.query.logoId) ? parseInt(location.query.logoId) : -1 );
  var specialLogoDataX;
  var specialLogoDataY;
  
  if(screenResolution == 800) {
    document.getElementsByTagName("td")[1].width = 176;
    mainNavigationDynLayer.setX(-1);
    logoDynLayer.setY(35);
  }

  if((logoId > -1) && (logoId < specialLogoData.length)) {
    specialLogoDataX = ((screenResolution == 800) ? specialLogoData[logoId]['x_800'] : specialLogoData[logoId]['x_1024']);
    specialLogoDataY = ((screenResolution == 800) ? specialLogoData[logoId]['y_800'] : specialLogoData[logoId]['y_1024']);
    logoDynLayer.setHTML("<img src=\"" + specialLogoData[logoId]['path'] + "\" />");
    logoDynLayer.setX(specialLogoDataX);
    logoDynLayer.setY(specialLogoDataY);
  }

  if(currentMenuId > 0) {
    setBorderColor (MenuId, 1);
    setPermanentHigh("menu"+MenuId);
  }
  mainNavigationDynLayer.setVisible(1);
  logoDynLayer.setVisible(1);
}

function mainMouseOver(MenuId) {
  mouseOver("menu"+MenuId);
  if(currentMenuId > 0) {
    setBorderColor (currentHighlightedMenuId, 0);
  }
  setBorderColor (MenuId, 1);
  currentHighlightedMenuId = MenuId;
}

function mainMouseOut(MenuId) {
  mouseOut("menu"+MenuId);
  setBorderColor (MenuId, 0);
  if(currentMenuId > 0) {
    setBorderColor (currentMenuId, 1);
  }
  currentHighlightedMenuId = currentMenuId;
}

/***********************
 * END main navigation *
 ***********************/

/***************************
 * START module navigation *
 ***************************/
var navDataPath      = new Array();
var navDataFinalPath = new Array();
var successStatus    = false;

function getNavigationDataPath(menuData,menuIndex,menuIndexLevel) {
  for (var i=0; i < menuData.length; i++) {
		if (!successStatus) {
			menuIndex[menuIndexLevel] = i;
			if (menuData[i]['navUniqueID'] == navUniqueID) {
				successStatus  = true;
			} else {
				if (menuData[i].length>0) {
		  		getNavigationDataPath(menuData[i],menuIndex,menuIndexLevel + 1);
				}
		  }
		}
	}
  if (!successStatus ) {
		menuIndex[menuIndexLevel] = null;
	}
  for (var j=0; j<menuIndex.length; j++) {
  	if (menuIndex[j] != null && successStatus) {
  		navDataFinalPath[j] = menuIndex[j];
  	}
  }
	return navDataFinalPath;
}

var moduleNavigationDynLayer;

function writeMiniModuleNavigation(navFontFace, navFontColor, striplineColor) {
  var moduleNavHiColor        = "color" + navFontColor.substr(12,6);
  var teaserLinkHeadlineColor = navFontColor.substr(0,11);
  var striplineColor          = ((striplineColor) ? striplineColor : "666666");
  var moduleNavigation        = '';

  moduleNavigation         += '<table cellpadding="0" cellspacing="0" width="166" border="0">';
  
  navHeaderData["navUrl"]   = ((navHeaderData["navAddParam"]) ? navHeaderData["navUrl"].split("?")[0] + '?' + navHeaderData["navAddParam"] : navHeaderData["navUrl"]);
  navHeaderData["navUrl"]   = ((navHeaderData["navUrl"].split("?")[0].indexOf("javascript:") != -1) ? navHeaderData["navUrl"] : rootpath + navHeaderData["navUrl"]);

//  START Module navigation headline
  moduleNavigation         += '  <tr>';
  moduleNavigation         += '    <td valign="top" width="10"><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="10" height="4" /><br /><img src="'+ rootpath +'/_common/_img/1x1_trans.gif"  width="3"   height="5" /><img src="'+ rootpath +'/_common/_img/arrow_3x5_trans_' + navFontColor.substr(12,6) + '.gif" width="3" height="5" id="ArrowNavHeader" name="ArrowNavHeader" /></td>';
  moduleNavigation         += '    <td width="156"><span class="' + navFontFace + '"><a href="' + navHeaderData["navUrl"] + '" target="_self" onmouseover="mouseOver(\'ArrowNavHeader\');self.status=\''+ navHeaderData["navStatus"] + '\';return true;" onmouseout="mouseOut(\'ArrowNavHeader\');self.status=\'\';return true;" class="' + moduleNavHiColor + '" onfocus="this.blur();">' + navHeaderData["navText"] + '</a><br /></span><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="4" /></td>';
  moduleNavigation         += '  </tr>';
  moduleNavigation         += '  <tr>';
  moduleNavigation         += '    <td></td>';
  moduleNavigation         += '    <td>';
  moduleNavigation         += '      <img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="1" /><br />';
  moduleNavigation         += '      <img src="'+ rootpath +'/_common/_img/1x1_' + striplineColor + '.gif" width="156" height="1" /><br />';
  moduleNavigation         += '      <img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="6" /><br />';
  moduleNavigation         += '    </td>';
  moduleNavigation         += '  </tr>';
//  END Module navigation headline


// START Module navigation body
  getNavigationDataPath(navMainData,navDataPath,0);//  Get actual path for the highlighting

  if (navMainData.length > 0) {
    moduleNavigation       += getModuleNavigationBody(navMainData,0,"Nav",navFontFace,navFontColor);
  }

  moduleNavigationBody = '';
// END Module navigation body


// START Content related topics
  if (navTeaserLinkData.length > 0) {
    if (navMainData.length > 0) {
      moduleNavigation     += '  <tr>';
      moduleNavigation     += '    <td></td>';
      moduleNavigation     += '    <td>';
      moduleNavigation     += '      <img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="1" /><br />';
      moduleNavigation     += '      <img src="'+ rootpath +'/_common/_img/1x1_' + striplineColor + '.gif" width="156" height="1" /><br />';
      moduleNavigation     += '      <img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="6" /><br />';
      moduleNavigation     += '    </td>';
      moduleNavigation     += '  </tr>';
    }

    moduleNavigation       += '  <tr>';
    moduleNavigation       += '    <td valign="top" width="10"><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="10" height="1" /></td>';
    moduleNavigation       += '    <td valign="top">';
    moduleNavigation       += '      <img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="22" /><br />';
    moduleNavigation       += '      <table cellpadding="0" cellspacing="0" border="0">';
    moduleNavigation       += '        <tr>';
    moduleNavigation       += '          <td valign="top" width="156" colspan="2"><span class="' + navFontFace + 'bold"><span class="' + teaserLinkHeadlineColor + '">' + navTeaserLinkData["navHeadline"] + '</span><br /></span><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="5" /></td>';
    moduleNavigation       += '        </tr>';

    for (var i=0; i<navTeaserLinkData.length ; i++) {
      var tempUrlSubString = navTeaserLinkData[i]["navUrl"].split("?")[0];
      if (!navTeaserLinkData[i]['navTarget']) {
        if (tempUrlSubString.indexOf("javascript:") != -1) {
          navTeaserLinkData[i]['navTarget'] = '_self';
        }
        else {
          if ((tempUrlSubString.indexOf("://") != -1)) {
            navTeaserLinkData[i]['navTarget'] = '_blank';
          }
          else {
              navTeaserLinkData[i]['navTarget'] = '_self';
              navTeaserLinkData[i]["navUrl"] = rootpath + navTeaserLinkData[i]["navUrl"];
          }
        }
      }
      else {
        if (tempUrlSubString.indexOf("://") == -1) {
          navTeaserLinkData[i]["navUrl"] = rootpath + navTeaserLinkData[i]["navUrl"];
        }
      }

      navTeaserLinkData[i]["navUrl"]  = ((navTeaserLinkData[i]["navAddParam"]) ? navTeaserLinkData[i]["navUrl"].split("?")[0] + '?' + navTeaserLinkData[i]["navAddParam"] : navTeaserLinkData[i]["navUrl"].split("?")[0] + '?');
      navTeaserLinkData[i]["navUrl"] += 'refType=teaserLink&refPage=' + serverRelativeUrl;
      
      moduleNavigation     += '        <tr>';
      moduleNavigation     += '          <td valign="top" width="11"><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="4" /><br /><img src="'+ rootpath +'/_common/_img/arrow_3x5_' + navFontColor.substr(5,6) +'_' + navFontColor.substr(12,6) + '.gif" width="3" height="5" id="QuickNav' + i + '" name="QuickNav' + i + '" /></td>';
      moduleNavigation     += '          <td width="145"><span class="' + navFontFace + '"><a href="' + navTeaserLinkData[i]["navUrl"] + '" target="' + navTeaserLinkData[i]["navTarget"] + '" onmouseover="mouseOver(\'QuickNav' + i + '\');self.status=\'' + navTeaserLinkData[i]["navStatus"] + '\';return true;" onmouseout="mouseOut(\'QuickNav' + i + '\');self.status=\'\';return true;" class="' + navFontColor + '" onfocus="this.blur();">' + navTeaserLinkData[i]["navText"] + '</a><br /></span><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="3" /></td>';
      moduleNavigation     += '        </tr>';
    }

    moduleNavigation       += '      </table>';
    moduleNavigation       += '    </td>';
    moduleNavigation       += '  </tr>';
  }
// END Content related topics

  moduleNavigation         += '</table>';

  moduleNavigationDynLayer = DynLayer.getInline("moduleNavigationLayer");
  moduleNavigationDynLayer.setHTML(moduleNavigation);
}



var moduleNavigationBody = '';

function getModuleNavigationBody(menuData,menuIndexLevel,arrowImgName,navFontFace,navFontColor,lastEntryValue) {
  var moduleNavHiColor = "color"+navFontColor.substr(12,6);

  moduleNavigationBody     += '  <tr>';
  moduleNavigationBody     += '    <td valign="top" width="10"><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="10" height="11" /></td>';
  moduleNavigationBody     += '    <td valign="top">';
  moduleNavigationBody     += '      <table cellpadding="0" cellspacing="0" border="0">';

  for (var i=0; i<menuData.length ; i++) {

    var tempUrlSubString = menuData[i]["navUrl"].split("?")[0];
  
    if (!menuData[i]['navTarget']) {
      if (tempUrlSubString.indexOf("javascript:") != -1) {
        menuData[i]['navTarget'] = '_self';
      }
      else {
        if ((tempUrlSubString.indexOf("://") != -1)) {
          menuData[i]['navTarget'] = '_blank';
        }
        else {
          menuData[i]['navTarget'] = '_self';
          menuData[i]["navUrl"] = rootpath + menuData[i]["navUrl"];
        }
      }
    }
    else {
      if (tempUrlSubString.indexOf("://") == -1) {
        menuData[i]["navUrl"] = rootpath + menuData[i]["navUrl"];
      }
    }
    
    menuData[i]["navUrl"] = ((menuData[i]["navAddParam"]) ? menuData[i]["navUrl"].split("?")[0] + '?' + menuData[i]["navAddParam"] : menuData[i]["navUrl"]);

    moduleNavigationBody   += '        <tr>';
    moduleNavigationBody   += '          <td valign="top" width="11"><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="11" height="4" /><br /><img src="'+ rootpath +'/_common/_img/arrow_3x5_trans_' + navFontColor.substr(12,6) + '.gif" width="3" height="5" id="' + arrowImgName+i + '" name="' + arrowImgName+i + '" /></td>';

    if (navDataFinalPath[menuIndexLevel] == i || menuData[i]['navUniqueID'] == navUniqueID) {
      moduleNavigationBody += '          <td><span class="' + navFontFace + '"><a href="' + menuData[i]["navUrl"] + '" target="' + menuData[i]["navTarget"] + '" onmouseover="mouseOver(\'' + arrowImgName+i + '\');self.status=\'' + menuData[i]["navStatus"] + '\';return true;" onmouseout="mouseOut(\'' + arrowImgName+i + '\');self.status=\'\';return true;" class="' + moduleNavHiColor + '" onfocus="this.blur();">' + menuData[i]["navText"] + '</a><br /></span><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="4" /></td>';
      moduleNavigationBody += '        </tr>';
      if (menuData[i].length > 0) {
        getModuleNavigationBody(menuData[i],menuIndexLevel+1,arrowImgName+i+"Sub",navFontFace,navFontColor,((i+1) >= menuData.length));
      }
    }
    else {
      moduleNavigationBody += '          <td><span class="' + navFontFace + '"><a href="' + menuData[i]["navUrl"] + '" target="' + menuData[i]["navTarget"] + '" onmouseover="mouseOver(\'' + arrowImgName+i + '\');self.status=\'' + menuData[i]["navStatus"] + '\';return true;" onmouseout="mouseOut(\'' + arrowImgName+i + '\');self.status=\'\';return true;" class="' + navFontColor + '" onfocus="this.blur();">' + menuData[i]["navText"] + '</a><br /></span><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="4" /></td>';
      moduleNavigationBody += '        </tr>';
    }

  }
  if ((menuIndexLevel != 0) && !(lastEntryValue)) {
      moduleNavigationBody += '        <tr>'
      moduleNavigationBody += '          <td colspan="2"><img src="'+ rootpath +'/_common/_img/1x1_trans.gif" width="1" height="9" /></td>'
      moduleNavigationBody += '        </tr>'
  }
  moduleNavigationBody     += '      </table>';
  moduleNavigationBody     += '    </td>';
  moduleNavigationBody     += '  </tr>';

	return moduleNavigationBody;
}
/*************************
 * END module navigation *
 *************************/

 /************************
 * START meta navigation *
 *************************/
 /**********************
 * END meta navigation *
 ***********************/