var moduleNavigationLayer;


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        = '';

//Get actual path for the highlighting
  getNavigationDataPath(navMainData,navDataPath,0);

//Navigation head

  moduleNavigation     += '<table cellpadding="0" cellspacing="0" width="166"border="0">';
  
  moduleNavigation     += '  <tr>';
  moduleNavigation     += '    <td valign="top" width="10"><img src="'+ rootpath +'/common/_img/1x1_trans.gif" width="11" 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 + '" /*title="' + navHeaderData["navText"] + '"*/ 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="2" /><br />';
  moduleNavigation     += '      <img src="'+ rootpath +'/common/_img/1x1_' + striplineColor + '.gif" width="155" height="1" /><br />';
  moduleNavigation     += '      <img src="'+ rootpath +'/common/_img/1x1_trans.gif" width="1" height="6" /><br />';
  moduleNavigation     += '    </td>';
  moduleNavigation     += '  </tr>';

//Navigation body
  if (navMainData.length > 0) {
    moduleNavigation += getModuleNavigationBody(navMainData,0,"Nav",navFontFace,navFontColor);
  }
  moduleNavigationBody = '';

//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="155" 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"].substr(0,12);
      if (!navTeaserLinkData[i]['navTarget']) {
        if (navTeaserLinkData[i]["navUrl"].indexOf("javascript:") != -1) {
          navTeaserLinkData[i]['navTarget'] = '_self';
        } else {
          if ((navTeaserLinkData[i]["navUrl"].indexOf("http://") != -1) || (navTeaserLinkData[i]["navUrl"].indexOf("https://") != -1)) {
            navTeaserLinkData[i]['navTarget'] = '_blank';
          } else {
              navTeaserLinkData[i]['navTarget'] = '_self';
          }
        }
      }

      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 + '" /*title="' + navTeaserLinkData[i]["navText"] + '"*/ onfocus="this.blur();">' + navTeaserLinkData[i]["navText"] + '</a><br /></span><img src="'+ rootpath +'/common/_img/1x1_trans.gif" width="1" height="5" /></td>';
      moduleNavigation += '        </tr>';
    }

    moduleNavigation   += '      </table>';
    moduleNavigation   += '    </td>';
    moduleNavigation   += '  </tr>';
  }

  moduleNavigation     += '</table>';

  moduleNavigationLayer = DynLayer.getInline("moduleNavigationLayer");
  moduleNavigationLayer.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"].substr(0,12);
    if (!menuData[i]['navTarget']) {
      if (tempUrlSubString.indexOf("javascript:") != -1) {
        menuData[i]['navTarget'] = '_self';
      } else {
        if ((tempUrlSubString.indexOf("http://") != -1) || (tempUrlSubString.indexOf("https://") != -1)) {
          menuData[i]['navTarget'] = '_blank';
        } else {
          menuData[i]['navTarget'] = '_self';
        }
      }
    }

    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 + '" /*title="' + menuData[i]["navText"] + '"*/ onfocus="this.blur();">' + menuData[i]["navText"] + '</a><br /></span><img src="'+ rootpath +'/common/_img/1x1_trans.gif" width="1" height="5" /></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 + '" /*title="' + menuData[i]["navText"] + '"*/ onfocus="this.blur();">' + menuData[i]["navText"] + '</a><br /></span><img src="'+ rootpath +'/common/_img/1x1_trans.gif" width="1" height="5" /></td>';
      moduleNavigationBody += '        </tr>';
    }

  }
  if ((menuIndexLevel != 0) && !(lastEntryValue)) {
      moduleNavigationBody += '        <tr>'
      moduleNavigationBody += '          <td colspan="2"><img src="'+ rootpath +'/common/_img/1x1_trans.gif" width="1" height="10" /></td>'
      moduleNavigationBody += '        </tr>'
  }
  moduleNavigationBody     += '      </table>';
  moduleNavigationBody     += '    </td>';
  moduleNavigationBody     += '  </tr>';

	return moduleNavigationBody;
}


/*
 *
 */

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;
}

