var lastNavBGColor, lastNavSubBGColor, lastNavHoverColor, lastNavSelectedColor;
var lastAyiracDarkColor, lastAyiracLigthColor;
var isNewMenu, inSubMenu = false;
var navLinkPrefix = "";
var navHTML = "";

if (nav_kok == 1) {
  navLinkPrefix = siteroot;
} else if (request_in_dir) {
  // alt dizinlere gidilmisse URL'de "../" ekle linkin basina...
  navLinkPrefix = "../";
} else { 
  navLinkPrefix = "";
}

function beginNavMenu(bgcolor, subbgcolor, hovercolor, selectedcolor, ayiracDarkColor, ayiracLightColor) {
  lastNavBGColor = bgcolor;
  lastNavSubBGColor = subbgcolor;
  lastNavHoverColor = hovercolor;
  lastNavSelectedColor = selectedcolor;
  lastAyiracDarkColor = ayiracDarkColor;
  lastAyiracLightColor = ayiracLightColor;
  isNewMenu = true;

  navHTML += '<div style="width: 117px; margin-bottom: 1px; background-color: ' + bgcolor + ';">';
  navHTML += '<div style="margin-left: 0px;">';
  navHTML += '<table width="117" border="0" cellspacing="0" cellpadding="0">';
}

function endNavMenu() {
  navMenuAyirac();
  navHTML += '</table></div></div>';
}

function beginSubMenu(menu_id) {
  var visible = (selected_menu_group == menu_id);
  inSubMenu = true;
  var display = visible ? 'block' : 'none';
  navHTML += '<tr><td><div id="nav_' + menu_id + '" style="display: ' + display + '"><table width="117" border="0" bordercolor=#FFFF00 cellspacing="0" cellpadding="0">';
}

function endSubMenu() {
  inSubMenu = false;
  navHTML += '</table></div></td></tr>';
}

function navMenuItem(menu_id, text, link, has_sub_menu, target, is_new) {
  if (link.match(/^\//))
    link = siteroot + link.substring(1);
  else if(!link.match(/^http/))
    link = navLinkPrefix + link;
  has_sub_menu = has_sub_menu != null && has_sub_menu;
  is_new = is_new != null && is_new;
  navMenuAyirac();
  if (selected_menu_id == menu_id) {
    navHTML += '<tr bgcolor="' + lastNavSelectedColor + '"><td style="cursor: pointer;" onclick="document.location.href=\'' + link + '\';">';
  } else {
    var bgcolor = inSubMenu ? " bgcolor='" + lastNavSubBGColor + "'" : "";
    navHTML += '<tr' + bgcolor + '><td onmouseover="this.style.backgroundColor=\'' + lastNavHoverColor + '\'" onmouseout="this.style.backgroundColor=\'\'">';
  }
  navHTML += '<div style="position: relative; width: 117px; height: 22px; overflow: hidden;">';
  if (has_sub_menu) {
    var style_cmn = "position: absolute; left: 100px; top: 5px; width: 11px; height: 11px; z-index: 15;";
    var style_pls = (menu_id == selected_menu_group) ? " display: none;" : "";
    var style_mns = (menu_id != selected_menu_group) ? " display: none;" : "";
    navHTML += '<a href="javascript:;" id="navpls_' + menu_id + '" onclick="toggleNavMenu(' + menu_id + ');" style="' + style_cmn + style_pls + '"><img src="' + I_URL + 'nav_menudown.gif" width="11" height="11" border="0" alt=""></a>';
    navHTML += '<a href="javascript:;" id="navmns_' + menu_id + '" onclick="toggleNavMenu(' + menu_id + ');" style="' + style_cmn + style_mns + '"><img src="' + I_URL + 'nav_menuright.gif" width="11" height="11" border="0" alt=""></a>';
  }
  if (selected_menu_id == menu_id)
    navHTML += '<span style="position: absolute; left: 2px; top: 4px; z-index: 10;">»</span>';
  var padleft = inSubMenu ? 20 : (selected_menu_id == menu_id) ? 12 : 12;
  var target_html = (target == null || target == "") ? "" : " target='" + target + "'";
  navHTML += '<a href="' + link + '" style="position: absolute; left: 0px; top: 0px; width: 117px; height: 22px; z-index: 5;" ' +
  	target_html + ' onfocus="this.blur();"><img src="' + I_URL + 'sp.gif" width="117" height="22" alt="' + text + '" title="' + text + '"></a>';
  navHTML += '<a href="' + link + '" class="left_menu" alt="' + text + '" title="' + text + '" ' + target_html + ' onfocus="this.blur();" style="position: absolute; left: ' + padleft + 'px; top: 4px; z-index: 10;">' + text + '</a>';
  if (is_new)
    navHTML += '<span style="position: absolute; left: 94px; top: 5px; width: 19px; height: 11px; z-index: 10;"><img src="' + I_URL + 'nav_menuyeni.gif" width="19" height="11" border="0" alt="yeni"></span>';
  navHTML += '</div>';
  navHTML += '</td></tr>';
}

function navMenuAyirac() {
  if (isNewMenu) {
    isNewMenu=false;
    return;
  }
  navHTML += '<tr><td>';
  navHTML += '<div style="background-image: url(' + I_URL + '_nav_tireler.gif); background-repeat: repeat-x;"><img src="' + I_URL + 'sp.gif" width="1" height="1" alt=""></div>';
  navHTML += '</td></tr>';
}

function toggleNavMenu(id) {
  var menu=document.getElementById('nav_' + id);
  var menupls=document.getElementById('navpls_' + id);
  var menumns=document.getElementById('navmns_' + id);
  var menu_visible = (menu.style.display == 'none');
  if (menu_visible) {
    // hide old visible menu if any
    var old_menu=document.getElementById('nav_' + selected_menu_group);
    if (old_menu != null) {
      var old_menu=document.getElementById('nav_' + selected_menu_group);
      var old_menupls=document.getElementById('navpls_' + selected_menu_group);
      var old_menumns=document.getElementById('navmns_' + selected_menu_group);
      old_menu.style.display = 'none';
      old_menupls.style.display = 'inline';
      old_menumns.style.display = 'none';
    }
    selected_menu_group = id;
  } else if (selected_menu_group == id) {
    selected_menu_group = 0;
  }
  menu.style.display = (menu_visible) ? 'block' : 'none';
  menupls.style.display = (menu_visible) ? 'none' : 'inline';
  menumns.style.display = (menu_visible) ? 'inline' : 'none';
}
