/*************************************************
Menu Maker (Menu Generator Code)
Created:  20020828  
Updated:  08.01.2003 19:57:22

Copyright 2002 by Donald Lessau  donald@xbeat.net
*************************************************/

writeMenu(parseMenuItems());

function writeMenu(sHTML) {  
  var method = 0; //values below
  switch(method) {
    case 0: document.write(sHTML); break; // IE/PC yes, NS/PC yes
    case 1: initContainer(); Container.html(sHTML); break; // IE/PC yes, NS/PC no
    case 2:
      initContainer(); Container.text(sHTML); // debug only
      document.write(sHTML); break; // IE/PC yes, NS/PC yes
    case 3: alert(sHTML); break;
  }
}

var Container;
function initContainer() {
  Container = new cContainer();
  function cContainer() {
    document.write("<div id='Container' style='position:relative; Height:0px;FONT-FAMILY: Verdana; font-size: 10px; background:#ffffff;visibility:visible;'> </div>");
    this.box = document.getElementById("Container");
    this.html = write_html;
    this.text = write_text;
  }
  function write_html(msg) {
    Container.box.innerHTML = msg;
  }
  function write_text(msg) {
    Container.box.innerText = msg;
  }
}

function makeDivID(level, count) {
  return "L" + level + "_" + count;
}
function makeTrID(DivID, TrID) {
  return  DivID + "_" + TrID;
}
function fik()
{alert(this.className)
}
function parseMenuItems() {
  var cMaxMenLevel = 10;
  var curLevel = -1, cntTrID = 0;  
  var aDivID = new Array(); //track IDs levelwise
  var cntDivLevel = new Array(); //track div count per level  
  var cntLineLevel = new Array(); //track line count per level
  var asLineLevel = new Array(); //lines are pooled levelwise  

  // 20021029: bgcolor
  var idxBgColor = -1;
  var sBgColors = conf.BgColors;
  // 20021107
  var fURLparams = conf.URLparams.length > 0;
  // default to white
  if (typeof(sBgColors)=="undefined") {var sBgColors = "#FFFFFF"};
  var asBgColor = sBgColors.split(",");

  // init arrays
  for (var i=0; i < cMaxMenLevel; i++) {
    cntDivLevel[i] = 0;
    cntLineLevel[i] = 0;
    asLineLevel[i] = new Array();  //2-d array
  }
  
  for (var i=0; i < menuitems.length; i++) {
    var sOut = "";
    // 0=level, 1=caption, 2=link, 3=target
    var aItem = menuitems[i];
    // level change
    var newLevel = aItem[0];
    if (newLevel != curLevel) {
      if (newLevel > curLevel) {
        //down: open new DIV
        if (newLevel == 1 && idxBgColor+1 < asBgColor.length) {
          idxBgColor++;
        };
        cntDivLevel[newLevel]++;
        aDivID[newLevel] = makeDivID(newLevel,cntDivLevel[newLevel]);
        sOut += "<div id=\"" + aDivID[newLevel] + "\" class=nav style=\"position:absolute; visibility: hidden; background-color: "+asBgColor[idxBgColor]+";\" onMouseOver=\"menOver();\" onMouseOut=\"menOut();\">";
        sOut += "\n<table class=nav cellspacing=\"0\" cellpadding=\"0\">";
      } else {
        //up: close any open DIV
        for (var openLevel=curLevel; openLevel > newLevel; openLevel--) {
          // add to current level pool
          asLineLevel[openLevel][cntLineLevel[openLevel]] = "</table></div>\n\n";
          // set captionlast class to the previous item
          //asLineLevel[openLevel][cntLineLevel[openLevel]-1] = asLineLevel[openLevel][cntLineLevel[openLevel]-1].replace(/class=caption/g, "class=captionlast");    
          cntLineLevel[openLevel]++;
        }
      }
      curLevel=newLevel;
    } else {
      // special for 0-level
      if (newLevel==0) cntDivLevel[1]++;
    }
    
    // build item
    var sTdImg="<img src=../../gribeson.com/_js//%22../images/b.gif/%22 width=19 height=14>";
    var nextDivID = "";
    cntTrID++;
    var sTrID=" id=\"" + makeTrID(aDivID[curLevel] , cntTrID)+ "\"";
    var sTrOnC="";
    var sTrCls=" class=item";
    // find out about the next item
    if (menuitems[i+1]) {
      // if subfolders -> onMouseOver
      if (menuitems[i+1][0] == curLevel+1) {
        nextDivID = makeDivID(curLevel+1, cntDivLevel[curLevel+1]+1);
        sTdImg="<img src=../../gribeson.com/_js//%22../images/img_arrow.gif/%22 width=19 height=14>";
      }
    }
    // escape ' needs double-escape \\' 
    var sStatus = aItem[1].replace(/'/g,"\\'"); //g for global
    sStatus = sStatus.replace(/\"/g,""");
    sTrOnMO = " onMouseOver=\"menOverTR(this.id,'"+nextDivID+"');window.status='"+sStatus+"'; return true;\" ";
    // if link -> onClick
    if (aItem[2]) {
      // 20021107: add any URL-parameters
      if (fURLparams) {
        if (aItem[2].indexOf("?") == -1) {
          aItem[2]+="?"+conf.URLparams;
        } else {
          aItem[2]+=conf.URLparams;
        }
      }
      // target
      if (aItem[3]===1) { //sic!
        sTrOnC=" onClick=\"window.open('"+aItem[2]+"');\"";  //_blank
      } else {
        sTrOnC=" onClick=\"document.location='"+aItem[2]+"';send_cookie('"+sStatus+"');\"";  //_self
      }
      sTrCls=" class=itemlink";
    }
    sOut += "\n<tr"+sTrID+sTrCls+ sTrOnC+sTrOnMO+">";    
    sOut += "<td class=caption onmouseout=\"this.className='caption'\" onmouseover=\"this.className='caption_over'\">"+aItem[1]+"</td>";    
    sOut += "<td class=caption width=17 >"+sTdImg+"</td></tr>";
    
    // add to current level pool
    // skip level 0 (no need to generate it)
    if (curLevel > 0) {
      asLineLevel[curLevel][cntLineLevel[curLevel]] = sOut;
      cntLineLevel[curLevel]++;
    }
  }

  // close any open DIV
  for (var openLevel=curLevel; openLevel > 0; openLevel--) {
    // add to current level pool
    asLineLevel[openLevel][cntLineLevel[openLevel]] = "</table></div>\n\n";
    // set captionlast class to the previous item
    //asLineLevel[openLevel][cntLineLevel[openLevel]-1] = asLineLevel[openLevel][cntLineLevel[openLevel]-1].replace(/class=caption/g, "class=captionlast");  
 //asLineLevel[openLevel][cntLineLevel[openLevel]-1]=asLineLevel[openLevel][cntLineLevel[openLevel]-1].replace(/this.className='caption'/g, "this.className='captionlast'");  
//asLineLevel[openLevel][cntLineLevel[openLevel]-1]=asLineLevel[openLevel][cntLineLevel[openLevel]-1].replace(/this.className='caption_over'/g, "this.className='captionlast_over'");  
    cntLineLevel[openLevel]++;
  }

  // collect the levels
  sOut="<!-- " + cntTrID + " menu items -->\n";
  for (var i=0; i < cMaxMenLevel; i++) {  
    sOut += asLineLevel[i].join("");
  }
  return sOut;
}
function send_cookie(val){

val=val.replace(" ","_");
val=val.replace(" ","_");
val=val.replace(" ","_");
val=val.replace(" ","_");
//alert(val)
	//alert(val)
	//var sure=24 * 1 * 60 * 60 * 1000
	var sure=1 * 60 * 60 * 1000 //
	var today = new Date(); // bir saatlik
	var expiry = new Date(today.getTime() + sure);
	document.cookie="sayfa_ad="+val+"; expires=" + expiry.toGMTString()+" path=/";
}
