/**
* ----------------------------------------------------------------
*                 InfiCMS
* 
*  Developer        : Erwin Kooi
*  released at      : June 2005
*  last modified by : Erwin Kooi
*  date modified    : June 2005
*                                                               
*  Copyright (c) 2004 Cyane Dynamic Web Solutions
*  IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF THIS SITE,
*  WITHOUT THE PERMISION OF THE AUTHOR.    
*  					                            			  				
*  Info? Mail to info@cyane.nl
* 
* --------------------------------------------------------------
**/

function lib_bwcheck(){
	this.ver=navigator.appVersion;
	this.agent=navigator.userAgent;
	this.dom=document.getElementById?1:0;
	this.opera5=this.agent.indexOf("Opera 5")>-1;
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6;
	this.mac=this.agent.indexOf("Mac")>-1;
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);
	return this;
}
var bw=new lib_bwcheck();
var px = bw.ns4||window.opera?"":"px";

function Node(caption,menucolor,img,img_mouseover,link,customhtml) {
	this.caption=caption;
	this.menucolor=menucolor;
	this.link=link;
	this.children=new Array();
	this.div="";
	this.parent=null;
	this.img=img;
	this.img_mouseover=img_mouseover;
	this.addChild=_add_child;
	this.vertical=true;
	this.x=false;
	this.y=false;
	this.customhtml=customhtml;
	this.isSelectedItem=false;
}
function _add_child(caption,menucolor,img,img_mouseover,link,customhtml) {
	var node = new Node(caption,menucolor,img,img_mouseover,link,customhtml);
	this.children[this.children.length] = node;
	return node;
}

var divtable=new Array();
var domtable=new Array();
var divcounter=0;
var timer=null;

function writeMenu(t,menustyle,visible,vertical,isroot) {
	divcounter++;
	if (t.children.length==0) return;
	divtable[divcounter]=t;
	var divname = "m"+divcounter;
	t.div=divname;
	t.vertical=vertical;

	if (!isroot)
		window.document.write("<div id='"+divname+"' style='visibility:"+(visible?"visible":"hidden")+";position:absolute;'>");
	else
		window.document.write("<div id='"+divname+"' style='"+menustyle+";visibility:"+(visible?"visible":"hidden")+";'>");
	window.document.write("<table class='menutable' cellspacing='0' cellpadding='0'>");
	if (!vertical) window.document.write("<tr>");
	for (var i=0;i<t.children.length;i++) {
		var node = t.children[i];
		node.parent=t;
		if (vertical) window.document.write("<tr>");
		window.document.write("<td class='menuItemStyle"+(isroot?"Root":"Sub")+"' ");
		window.document.write("style='background-color:"+(node.isSelectedItem?menuMousecolor:node.menucolor)+";' ");
		if (node.customhtml) {
			window.document.write("onmouseover='showsub("+divcounter+","+i+",this)' ");
		} else {
			window.document.write("onclick='window.location.href=\""+node.link+"\"' ");
			window.document.write("onmouseover='this.style.backgroundColor=menuMousecolor;showsub("+divcounter+","+i+",this)' ");
			window.document.write("onmouseout='this.style.backgroundColor="+(node.isSelectedItem?"menuMousecolor":"\""+node.menucolor+"\"")+";timeHide();' ");
		}
		window.document.write(node.menucolor=="#FFFFFF" || node.menucolor=="white"?"":" style='color:white' ");
		window.document.write(">");
		if (node.customhtml)
			window.document.write(decodeBase64(node.customhtml));
		else if (node.img) {
			if (node.isSelectedItem)
				window.document.write("<img border=0 src='"+(node.img_mouseover==null?node.img:node.img_mouseover)+"' />");
			else
				window.document.write("<img border=0 src='"+node.img+"' "+(node.img_mouseover==null?"":"onmouseover='this.src=\""+node.img_mouseover+"\"' onmouseout='this.src=\""+node.img+"\"'")+" />");
		} else
			window.document.write("<nobr>"+node.caption);
			
		window.document.write("</td>");
		if (vertical) window.document.write("</tr>");
	}
	if (!vertical) window.document.write("</tr>");
	window.document.write("</table>");
	window.document.write("</div>");
	for (var i=0;i<t.children.length;i++) {
		var node = t.children[i];
		writeMenu(node,'',false,true,false);
	}
}

function getDomObject(obj) {
	var divid = obj.div;
	if (domtable[divid]) return domtable[divid];
	var div = bw.ie4?document.all[divid]:bw.ns4?eval('document.'+divid):document.getElementById(divid);
	domtable[divid]=div;
	return div;
}

function getStyleObject(obj) {
	var div = getDomObject(obj);
	if (div==null) return div;
	return bw.ns4?div:div.style;
}
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}
function showsub(parent,index,callingObj) {
	if (timer!=null) clearTimeout(timer);
	timer=null;
	hideAll();
	showsubobject(divtable[parent].children[index],callingObj);
}
function showsubobject(obj,callingObj) {
	if (obj.parent==null) return;
	var parentObj = getDomObject(obj.parent);
	if (!obj.x) {
		if (obj.parent.vertical) {
			obj.x=findPosX(callingObj)+callingObj.clientWidth;
			obj.y=findPosY(callingObj);
		} else {
			obj.x=findPosX(callingObj);
			obj.y=findPosY(callingObj)+callingObj.clientHeight;
		}
	}
	var objstyle = getStyleObject(obj);
	if (objstyle!=null) {
		objstyle.left=obj.x;
		objstyle.top=obj.y;
		objstyle.visibility='visible';
	}
	showsubobject(obj.parent,null);
}
function hidesubobject(obj) {
	var o = getStyleObject(obj);
	if (o==null) return;
	o.visibility='hidden';
	for (var i=0;i<obj.children.length;i++) {
		hidesubobject(obj.children[i]);
	}
}
function timeHide() {
	timer = setTimeout("hideAll()",1000);	
}
function hideAll() {
	for (var i=0;i<menu.children.length;i++) {
		hidesubobject(menu.children[i]);
	}
}

