/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: ScriptBreaker :: http://www.scriptbreaker.com/ */

var height = 28; // height of the menu headers
var iheight = 22; // height of the menu_items

var speed = 0;
var timerID = "";
var N = (document.all) ? 0 : 1;
var width = 196;
var self_menu = new Array();
var parent_array = new Array();

var open_block = -1;

function write_menu() {
  smc = 0; // count the position of the self_menu
  document.write("<div style='position:absolute'>");
  mn = 0;
  mni = 1;
  start = -1;

  for(i=0;i<Link.length;i++) {
   la = Link[i].split("|");
   if (la[0] == "0") {
    if(start == 0) {
      document.write("</div>");
      h =  tot_iheight;//csmc * iheight;
      tmn = mn; //-h
      self_menu[smc] = new Array(tmn,h,0,-2);
      smc++;
      mn--;
    }
    if(la[2] == "1"){
	  temp_height = height;
	  height *= 2;
	}
	csmc = 0;
    document.write("<div class='menu' style='top:"+mn+"px;height:"+height+"px' id='down"+smc+"' onclick='pull_down("+smc+","+mni+")' onmouseover='hover_image("+smc+")' onmouseout='out_image("+smc+")'><img src='images/spacer.gif' alt='' style='margin-left:-1px' width='1' height='26' /><div class='title_pad'>"+ la[1] + "</div></div>");
    self_menu[smc] = new Array(mn,height,0,mni);
	parent_array[smc] = la[1];
    smc++;
    mni++;
    mn+=height;
    start = 1;
	if(la[2] == "1"){
	  height = temp_height;
	}
   } else {
    if(start == 1) {
      if(N)mn+=2;
       document.write("<div class='item_panel' id='down"+smc+"' style='top:"+mn+"px; display:none'>");
       start = 0;
	   tot_iheight = 0;
    }
	if(la[4] == "1"){
	  temp_height = iheight;
	  iheight += 16;
	}
    document.write("<a href='"+la[2]+"'");
    if (la[3] != "") document.write(" target='" + la[3] + "' ");
    document.write("><div class='item' id='d"+i+"' style='height:"+iheight+"px'>" + la[1] + "</div></a>");
    csmc++;
	tot_iheight += iheight+6;
	if(la[4] == "1"){
	    iheight = temp_height;
	}
   }
  }
  if (start == 0) {
     document.write("</div>");
     h = tot_iheight;//csmc * iheight;
     tmn = mn + 5; //-h
     self_menu[smc] = new Array(tmn,h,0);
     name = "down" + (self_menu.length-1);
   }
  document.write("</div>");
}

function pull_down(nr,c) {
 if (timerID == "") {
 if((open_block != nr) && (self_menu[open_block+1][2] == 1)){
  to = self_menu[open_block+1][1];
  begin = open_block + 2;
  name = "down" + (begin-1);
  name2 = "down" + open_block;
  title = "<div class='title_pad'>"+parent_array[open_block]+"</div>";
  self_menu[open_block+1][2] = 0;
  obj = document.getElementById(name).style.clip = "rect(0,"+width+"px,0,0)";
  document.getElementById(name2).style.backgroundColor = '#8ca27d';
  document.getElementById(name2).innerHTML = "<img src='images/spacer.gif' alt='' style='margin-left:-1px' width='1' height='26' />"+title;
  for (i=begin;i<self_menu.length;i++) {
  name = "down" + i;
  obj = document.getElementById(name);
  obj.style.top = parseInt(obj.style.top)-to+"px";
  }
 }
 to = self_menu[nr+1][1]
 begin = nr + 2;
 name2 = "down"+(nr);
 title = "<div class='title_pad'>"+parent_array[nr]+"</div>";
 if (timerID != "") clearTimeout(timerID);
 if (self_menu[nr+1][2] == 0) {
  self_menu[nr+1][2] = 1;
  open_block = nr;
  name = "down"+(nr+1);
  document.getElementById(name).style.display = 'block';
  document.getElementById(name2).style.backgroundColor = '#8ca27d';
  document.getElementById(name2).innerHTML = '<img src="images/paw.gif" alt="paw" style="margin-left:-30px" width="24" height="26" /> ' + title;
  if(nr == self_menu.length-2) {to++;}
  epull_down(begin,to,0);
 } else {
  to = 0;
  self_menu[nr+1][2] = 0;
  name = "down"+(nr+2);
  document.getElementById(name2).style.backgroundColor = '#4d633f';
  document.getElementById(name2).innerHTML = "<img src='images/spacer.gif' alt='' style='margin-left:-1px' width='1' height='26' />"+title;
  open_item = 0;
  for(i=0;i<nr;i++) {
   if(self_menu[i][2] == 1)
    {open_item += self_menu[i][1];
    }
  }
  if (N == false) {open_item-= (c*1);}
  if (nr== self_menu.length-2) {val = self_menu[self_menu.length-1][1];to=-1;}
  else  val = parseInt(document.getElementById(name).style.top) -(open_item)-(c*height);
  epull_up(begin,to,val);
  }
  }
}

function epull_down(nr,to,nowv) {
 name = "down" + (nr-1);
 obj = document.getElementById(name).style.clip = "rect(0,"+width+"px,"+(nowv+4)+"px,0)";
 for (i=nr;i<self_menu.length;i++) {
  name = "down" + i;
  obj = document.getElementById(name);
  obj.style.top = parseInt(obj.style.top)+4+"px";
 }
 nowv+=4;
 if(nowv < to) timerID = setTimeout("epull_down("+nr+","+to+","+nowv+")",speed);
 else timerID = ""; 
}

function epull_up(nr,to,nowv) {
 name = "down" + (nr-1);
 obj = document.getElementById(name).style.clip = "rect(0,"+width+"px,"+(nowv-4)+"px,0)";
 for (i=nr;i<self_menu.length;i++) {
  name = "down" + i;
  obj = document.getElementById(name);
  obj.style.top = parseInt(obj.style.top)-4+"px";
 }
 nowv-=4;
 if(nowv > to) timerID = setTimeout("epull_up("+nr+","+to+","+nowv+")",speed);
 else timerID = "";
}
function hover_image(nr){
	name2 = "down"+(nr);
	title = "<div class='title_pad'>"+parent_array[nr]+"</div>";
	if (self_menu[nr+1][2] == 0) {
		//document.getElementById(name2).innerHTML = '<img src="images/paw.gif" alt="paw" style="margin-left:-30px" width="24" height="26" /> ' + title;
		document.getElementById(name2).style.backgroundColor = '#4d633f';
	}
}
function out_image(nr){
	name2 = "down"+(nr);
	//if (self_menu[nr+1][2] == 0) {
		//document.getElementById(name2).innerHTML = "<div class='title_pad'>"+parent_array[nr]+"</div>";
		document.getElementById(name2).style.backgroundColor = '#8ca27d';
	//}
}
function startup(nr) {
 if(!nr)
 	nr=1;
 write_menu();
 if (nr != 0) {
 for(i=0;i<self_menu.length;i++)
 {
  if(self_menu[i][3] == nr){ open_block = i; pull_down(i,nr);}
  i==self_menu.length;
 }
 }
}