// (c)ComputerPress 2000, author: PetrFilipec 
var TOP_NODE_ID = 0;
var FIRST_ITEM_ID = 1;
var EXPIRE_COOKIE = 7;
var NODE_STYLE_E = 1;
var NODE_STYLE_SE = 2;
var NODE_STYLE_NE = 3;
var NODE_STYLE_NSE = 4;

var gSpaces = new Array();
var gItemStack = new Array();
var gIdCounter = FIRST_ITEM_ID;
var gItemArray = new Array();
var gPos = 0;
var gOutline = null;
var gState = "";

var bNetscape = document.all ? false : true;

var gLineNS = "/images/menu/lineNS.gif";
var gLineNSE = "/images/menu/lineNSE.gif";
var gLineNE = "/images/menu/lineNE.gif";
var gLineSE = "/images/menu/lineSE.gif";

var gPlus = "/images/menu/plus.gif";
var gPlusE = "/images/menu/plusE.gif";
var gPlusNSE = "/images/menu/plusNSE.gif";
var gPlusNE = "/images/menu/plusNE.gif";
var gPlusSE = "/images/menu/plusSE.gif";
var gMinus = "/images/menu/minus.gif";
var gMinusE = "/images/menu/minusE.gif";
var gMinusNSE = "/images/menu/minusNSE.gif";
var gMinusNE = "/images/menu/minusNE.gif";
var gMinusSE = "/images/menu/minusSE.gif";
var gSpace = "/images/menu/space.gif";

function getCurrState()
{
	var state = "";
	var cookieList = document.cookie.split("; ");
	for(var n = 0; n < cookieList.length; n++)
	{
		var name = cookieList[n].split("=");
		if(name[0] == gOutline.ShopID)
		{
			if(name[1].length == (gIdCounter - 1))
				state = name[1];
		}
	}
	if(state.length == 0)
	{
		for(i = FIRST_ITEM_ID; i < gIdCounter; i++)
		{
			state += "0";
		}
	}
	return state;
}

function setCurrState(setting)
{
	var expire = new Date();
	expire.setTime(expire.getTime() + (EXPIRE_COOKIE * 24 * 60 * 60 * 1000));
	document.cookie = gOutline.ShopID + "=" + escape(setting) + "; expires=" + expire.toGMTString();
}

function UseCookieSet()
{
	var item;
	for(var i = 1; i < gIdCounter; i++)
	{
		item = gOutline.top.Find(i);
		if(gOutline.current.substring(i - 1, i) == "1")
			item.show = true;
		else
			item.show = false;
	}
}

function SetCookieSet(n)
{
	if(n != 0)
	{
		var newString = ""
		var expanded = gOutline.current.substring(n - 1, n);
		newString += gOutline.current.substring(0, n - 1);
		newString += expanded ^ 1;
		newString += gOutline.current.substring(n, gOutline.current.length);
		gOutline.current = newString;
		setCurrState(newString);
	}
}

function OnNodeClick(id,nodeStyle)
{
  var item = null;
  var nodeImg = null;
  var bookImg = null;
  var i = 0;
  item = gOutline.top.Find(id);
  if(!bNetscape)
  {
    nodeImg = document.all["node" + item.id];
    bookImg = document.all["book" + item.id];

    if (nodeStyle == NODE_STYLE_E)
      nodeImg.src = item.show ? gPlusE : gMinusE;
    else if (nodeStyle == NODE_STYLE_SE)
      nodeImg.src = item.show ? gPlusSE : gMinusSE;
    else if (nodeStyle == NODE_STYLE_NE)
      nodeImg.src = item.show ? gPlusNE : gMinusNE;
    else
      nodeImg.src = item.show ? gPlusNSE : gMinusNSE;
    item.show = !item.show;
    if(item.iconOpen && item.iconItem)
		bookImg.src = (item.show ? item.iconOpen : item.iconItem);
    item.child.Display(item.show);
  }
  SetCookieSet(id);
}

function OutlineItem(text,url,target,iconItem,iconOpen,show,dep,alt)
{
  this.text = text;
  this.url = url;
  this.target = target;
  this.iconItem = iconItem;
  this.iconOpen = iconOpen;
  this.show = show;
  this.dep = dep;
  this.alt = alt;
  this.child = null;
  this.next = null;
  this.id = 0;
  this.style = 0;
  this.Find = Find;
  this.Display = Display;
  this.Create = Create;
}

function Find(id)
{
	return gItemArray[id];
}

function Display(show)
{
  var nodeImg = null;
  var bookImg = null;
  var item;
  if(!bNetscape && VISIBLE_MODE == "advanced")
  {
    document.all["div" + this.id].style.display = show ? "block" : "none";
  }
  if(this.child)
  {
    this.child.Display(show & this.show);
  }
  if(this.next)
    this.next.Display(show);
}

function Create(level,show)
{
  var i = 0;
  var j = 0;
  var item = null;
  var strItem = "";
  if(!bNetscape && VISIBLE_MODE == "advanced")
    strItem += '<div style="parent" id="div' + this.id + '">';
  strItem += '<table border=0 cellspacing=0 cellpadding=0><tr>';
  if(this.next)
    gSpaces[level] = false;
  else
    gSpaces[level] = true;
  for(j = 1; j < level; j++)
  {
	 if(gSpaces[j])
	 {
		if(j == (level - 1))
	      strItem += '<td><img align="absmiddle" src="' + gSpace + '" width="' + OPT_WIDTH + '"></td>';
		else
			strItem += '<td><img align="absmiddle" src="' + gSpace + '"></td>';
	 }
	 else
	 {
		if(VISIBLE_MODE == "basic")
		{
			strItem += '<td><img align="absmiddle" src="' + gSpace + '"></td>';
		}
		else
		{
			strItem += '<td><img align="absmiddle" src="' + (gLineNS ? gLineNS : gSpace) + '"></td>';
		}
	 }
  }     
  if(this.child == null)
  {
    if(!this.next && gLineNE)
	 {
	   if(VISIBLE_MODE == "basic")
	   {
			strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>';
	   }
	   else
	   {
			strItem += '<td><img align="absmiddle" src="' + gLineNE + '"></td>';
		}
	 }
    if(this.next && (gLineNSE && gLineSE))
	 {
	   if(VISIBLE_MODE == "basic")
	   {
			strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>';
	   }
	   else
	   {
			strItem += '<td><img align="absmiddle" src="' + 
				(this.id == FIRST_ITEM_ID ? gLineSE : gLineNSE) + '"></td>';
		}
	 }
  }
  else
  {
    if(this.id == FIRST_ITEM_ID)
    {
      if(this.next == null)
      {
        this.style = NODE_STYLE_E;
  		  if(!bNetscape && VISIBLE_MODE == "advanced")
		  {
          strItem += '<td><a href="javascript:OnNodeClick(' + this.id + 
            ',' + NODE_STYLE_E + ');"><img border=0 align="absmiddle" src="' + 
            (this.show ? gMinusE : gPlusE) + '" name="node' + this.id + '"></a></td>';
		  }
		  else
		  {
          strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>';
		  }
      }
      else
      {
		  this.style = NODE_STYLE_SE;
  		  if(!bNetscape && VISIBLE_MODE == "advanced")
		  {
		    strItem += '<td><a href="javascript:OnNodeClick(' + this.id + 
		      ',' + NODE_STYLE_SE + ')"><img border=0 align="absmiddle" src="' + 
		      (this.show ? gMinusSE : gPlusSE) + '" name="node' + this.id + '"></a></td>';
		  }
		  else
		  {
		    strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>';
		  }
      }
    }  
    else if(this.next == null)
    {
      this.style = NODE_STYLE_NE;
  	   if(!bNetscape && VISIBLE_MODE == "advanced")
	   {
        strItem += '<td><a href="javascript:OnNodeClick(' + this.id + 
          ',' + NODE_STYLE_NE + ');"><img border=0 align="absmiddle" src="' + 
          (this.show ? gMinusNE : gPlusNE) + '" name="node' + this.id + '"></a></td>';
	   }
	   else
	   {
        strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>';
	   }
    }
    else
    {
      this.style = NODE_STYLE_NSE;
  	   if(!bNetscape && VISIBLE_MODE == "advanced")
	   {
        strItem += '<td><a href="javascript:OnNodeClick(' + this.id + 
          ',' + NODE_STYLE_NSE + ');"><img border=0 align="absmiddle" src="' + 
          (this.show ? gMinusNSE : gPlusNSE) + '" name="node' + this.id + '"></a></td>';
	   }
	   else
	   {
        strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>';
	   }
    }
  }
  if(VISIBLE_MODE == "advanced")
  {
	 if(this.show && this.iconOpen)
	 {
		if(bNetscape && this.alt)
		{
			strItem += '<td><img name="book' + this.id + '" align="absmiddle" class="icon" src="' + 
				this.iconOpen + '" alt="' + this.alt + '"><img align="absmiddle" src="' +  gSpace + '" width=3></td>'
		}
		else
		{
			strItem += '<td><img name="book' + this.id + '" align="absmiddle" class="icon" src="' + 
				this.iconOpen + '"><img align="absmiddle" src="' +  gSpace + '" width=3></td>'
		}
	 }
	 else
	 {
		if(!this.show && this.iconItem)
		{
		  if(bNetscape && this.alt)
		  {
		    strItem += '<td><img name="book' + this.id + '" align="absmiddle" class="icon" src="' + 
			   this.iconItem + '" alt="' + this.alt + '"><img align="absmiddle" src="' +  gSpace + '" width=3></td>'
		  }
		  else
		  {
		    strItem += '<td><img name="book' + this.id + '" align="absmiddle" class="icon" src="' + 
			   this.iconItem + '"><img align="absmiddle" src="' +  gSpace + '" width=3></td>'
		  }
		}
		else
		{
		  strItem += '<td><img align="absmiddle" src="' +  gSpace + '" width=3></td>'
		}
	 } 
  }
  else
  {
	 strItem += '<td></td>'
  }
    
  if(this.url)
  {
    strItem += '<td><a target="' + this.target +'" href="' + this.url + 
      '" title="' + this.alt + '">' + this.text + '</a></td>';
  }
  else
  {
    strItem += '<td>' + this.text + '</td>';
  }

  strItem += '</tr></table>';
  if(!bNetscape && VISIBLE_MODE == "advanced")
    strItem += '</div>';
  document.write(strItem);
  if(!bNetscape && VISIBLE_MODE == "advanced")
    document.all["div" + this.id].style.display = show ? "block" : "none";
  if(this.child != null)
    this.child.Create(level + 1,this.show);
  if(this.next != null)
    this.next.Create(level,show);
}

function Outline()
{
  this.top = new OutlineItem(null,null,null,null,null,0,true,0,null);
  this.lastLevel = 0;
  this.stack = new Array();
  this.docX = 0;
  this.docY = document.height;
  this.docW = 0;
  this.docH = 0;
  this.current = null;
  this.AddItem = AddItem;
  this.CreateOutline = CreateOutline;
  this.stack[0] = this.top;
  gOutline = this;
}

function AddItem(text,url,target,iconItem,iconOpen,level,show,dep,alt)
{
  var item = this.top;

  if (level <= 0)
  {
    window.alert("The level must be greater then 0.");
    return false;
  }

  if (this.top == null)
  {
    window.alert("Call 'InitOutline' first.");
    return false;
  }

  if (this.lastLevel < level)
  {
    item = this.stack[level - 1];
    item.child = new OutlineItem(text,url,target,iconItem,iconOpen,show,dep,alt);
    item = item.child;
  }
  else
  {
    item = this.stack[level];
    item.next = new OutlineItem(text,url,target,iconItem,iconOpen,show,dep,alt);
    item = item.next;
  }

  item.id = gIdCounter++;
  this.stack[level] = item;
  this.lastLevel = level;
  
  gItemArray[item.id] = item;
}

function CreateOutline()
{
	if (this.top != null && this.top.child != null)
	{
		if(!bNetscape && VISIBLE_MODE == "advanced")
		{
			this.current = getCurrState();
			UseCookieSet();
		}
		
		this.top.child.Create(1,true);
	}
}
