/*
	JSZenMenu 1.0.6
	http://jszenmenu.sourceforge.net
*/

//global variables
var delay=345;
var zindex=1000;
var p='p__';
_split=['___'];
var sstr='';
var mid=0;
iar=new Array();

//functions
function m/*item*/(v/*value*/,txt/*title*/,l/*link*/,d/*description*/,t/*target*/,img/*image*/,a/*submenu [items array]*/) {
	if(a!=null){
		this.a=new Array();
		for(var i=0;i<a.length;i++)
			{
			this.a[i]=a[i];
			}
		if(img==null)this.img=themedir+'folder.gif';else this.img=themedir+img;
		this.i2=themedir+'arrowv.gif';//image 2
	}
	else {
		this.a=null;
		if(img==null)this.img=themedir+'link.gif';else this.img=themedir+img;
		this.i2=themedir+'blank.gif';		
	}
	this.v=txt;
	if(l==null || l=='')this.l='#';else this.l=l;
	if(d==null)this.d=txt;else this.d=d;
	if(t==null)this.t='_self';else this.t=t;
	this.o=null;
	this.Id=v;
}

function getId(s){
	return s.replace(/;/g,'').replace(/&/g,'').replace(/#/g,'');
}

function gen(m/*menu*/,th/*theme*/,n/*menu_name*/,or/*orientation*/){
	var s1="",f1="",s2="",f2="",vd="V",sp=" colspan=\"3\"",sv="",cls="";
	cls = getMask(1,or);
	if(or == null)
		vd="A";
	else
		vd="F";

	if(or==0){
		sp="";
		sv="|";
		s1="<tr>";
		f1="</tr>";
		s2="<td class=\""+th+cls+"x\"><table cellspacing=\"0\">";
		f2="</table></td>";
	}
	
	if(m.a!=null){
		cls = getMask(1,or);
		if(m.v='')m.v=n;
//		alert(th+"TABLE"+vd);
		sstr+="<div id=\""+p+m.a[0].Id+n+"\" class=\""+th+"DIV\" onMouseOver=\"clearTimeOut('"+n+"');\" onMouseOut=\"setTimeOut('"+n+"','"+th+"');\" style=\"z-index:"+(zindex++)+";\"><table id=\"table"+m.a[0].Id+n+"\" class=\""+th+"TABLE"+vd+"\" cellspacing=\"0\"><tr><td class=\""+th+"TD"+vd+"\"><table cellspacing=\"0\">"+s1;
		for(var i=0;i<m.a.length;i++){
			if(m.a[i].Id < 100)
				m.a[i].o=or;
			cls = getMask(m.a[i].Id,m.a[i].o);
			tmpArr=new Array("<img src=\""+m.a[i].img+"\">",m.a[i].v,"<img src=\""+m.a[i].i2+"\">");
			var clic = "";
			if(m.a[i].l!="#")clic=" --- ";
			sstr+=s2+"<tr id=\""+m.a[i].Id+n+"\" ::: "+clic+" >";
			if(m.a[i].a!=null){
				if(or==0)
					tmpArr[2]="<img src=\""+themedir+'arrowh.gif'+"\">";
				for(var t=0;t<3;t++)
					sstr+="<td id=\""+m.a[i].Id+n+(t+1)+"\" class=\""+th+cls+(t+1)+"\">"+tmpArr[t]+"</td>";
			}else{
				if(m.a[i].v==_split[0]){
					sstr+="<td id=\""+m.a[i].Id+n+"\" "+sp+"><div class=\""+th+"SPLIT"+vd+"\"><img src=\""+themedir+'blank.gif'+"\">"+sv+"</div></td>";
				} else 
					for(var t=0;t<3;t++)
						sstr+="<td id=\""+m.a[i].Id+n+(t+1)+"\" class=\""+th+cls+(t+1)+"\">"+tmpArr[t]+"</td>";
			}
			sstr+="</tr>"+f2;
		}
		sstr+=f1+"</table></td></tr></table></div>";
	}
	if(m.a!=null)
		for(var i=0;i<m.a.length;i++) 
			gen(m.a[i],th,n,null);
}

function getX(o)
{
	var x=0;
	do{
		x+=o.offsetLeft;
		o=o.offsetParent;
	} while(o);
	return x;
}

function getY(o)
{
	var y=0;
	do{
		y+=o.offsetTop;
		o=o.offsetParent;
	} while(o);
	return y;
}

function getObj(id)
{
	if (document.all)
		return document.all[id];
	return document.getElementById(id);
}

function setTimeOut(name,th/*theme*/){
	g=0;q=new Array();
	q[0]=name;q[1]=setTimeout("hidems("+name+",'"+th+"','','"+name+"')",delay);
	for(var k=0;k<iar.length;k++)
		if(iar[k][0]==name) {
			iar[k][1]=q[1];
			g=1;
		}
	if(g==0)iar.push(q);
}

function clearTimeOut(n) {
	for(var k=0;k<iar.length;k++) {
		if(iar[k][0]==n) {
			clearTimeout(iar[k][1]);
		}
	}
}

function posAr(ar){
	for(var i=0;i<ar.length;i++)
		if(ar[i] instanceof Array)
			return i;
	return null;
}

function getArr(ar1,ar2) {
	var j=0;
	for(var i=posAr(ar1);i<ar1.length;i++)
		ar2[j++]=menu(ar1[i]);
	return ar2;
}

function menu(ar) {
	if(posAr(ar)==null)
		return new m(ar[0],ar[1],ar[2],ar[3],ar[4],ar[5]);
	else {
		arr=new Array();
		if(posAr(ar)==0) return new m(0,null,null,null,null,null, getArr(ar,arr));
		if(posAr(ar)==1) return new m(ar[0],null,null,null,null,null,getArr(ar,arr));
		if(posAr(ar)==2) return new m(ar[0],ar[1],null,null,null,null,getArr(ar,arr));
		if(posAr(ar)==3) return new m(ar[0],ar[1],ar[2],null,null,null,getArr(ar,arr));
		if(posAr(ar)==4) return new m(ar[0],ar[1],ar[2],ar[3],null,null,getArr(ar,arr));
		if(posAr(ar)==5) return new m(ar[0],ar[1],ar[2],ar[3],ar[4],null,getArr(ar,arr));
		if(posAr(ar)==5) return new m(ar[0],ar[1],ar[2],ar[3],ar[4],ar[5],getArr(ar,arr));
	}
}

function showm(m,n){
	if (m.a!=null)
		getObj(p+m.a[0].Id+n).style.visibility='visible';
}

function setCls(m,th,cl,n){
	for(var j=1;j<4;j++)
		getObj(m.Id+(n+j)).className=th+cl+j;
}

function getMask(id,orient){
var res = "";
if(orient == null)
	orient = 0;

if(id > 100)
	{
			res = 'TDA';
	}
else
	{
	if(orient == 0)
			res = 'TDHF';
	else 
			res = 'TDVF';
        if(id == mid)
			res = 'TDAF';
	}
return res;
}


function hidem(m,th,id,n) {
	if(m.Id+n==id) window.open(m.l,m.t);
	if (m.a!=null)
		for(var i=0;i<m.a.length;i++) {
			getObj(p+m.a[0].Id+n).style.visibility='hidden';
			if(m.a[i].v.substring(0,_split[0].length)!=_split[0]) 
			   setCls(m.a[i],th,getMask(m.a[i].Id,m.a[i].o),n);
			hidem(m.a[i],th,id,n);
		}
}

function hidems(m,th,id,n){
	if (m.a!=null)
		for(var i=0;i<m.a.length;i++) {
			if(m.a[i].v.substring(0,_split[0].length)!=_split[0])
			   setCls(m.a[i],th,getMask(m.a[i].Id,m.a[i].o),n);
			hidem(m.a[i],th,id,n);
		}
}

function showhidems(m,id,th,n){
	if(m.a!=null)
		for(var i=0;i<m.a.length;i++)
			if(m.a[i].Id+n==id){
				showm(m.a[i],n);
				if(m.a[i].v.substring(0,_split[0].length)!=_split[0])
				   setCls(m.a[i],th,getMask(m.a[i].Id,m.a[i].o)+'O',n);
			} else {
				hidem(m.a[i],th,'',n);
				if(m.a[i].v.substring(0,_split[0].length)!=_split[0])
				   setCls(m.a[i],th,getMask(m.a[i].Id,m.a[i].o),n);
			}
}

function createMenu(m,id,name,th,orient,pos,mi){
	if(mi==null)mid=0;
	else mid=mi;
	if(th==null)
		th=defTh;
	try{
		if(getTh(name,th)!='')
			th=getTh(name,th);
	}catch(e){}
	gen(m,th,name,orient);
	if (m.a!=null){
		var obj=getObj(id);
		obj.innerHTML=sstr.replace(/---/g," onClick=\"hidems("+name+",'"+th+"',this.id,'"+name+"');\" ").replace(/:::/g," onMouseOver=\"playMenu("+name+",this.id,'"+th+"','"+name+"');\"  ");
		getObj(p+m.a[0].Id+name).style.visibility='visible';
		if(pos==null)pos='static';
		getObj(p+m.a[0].Id+name).style.position=pos;
	}
	sstr='';
}

function playMenu(m/*menu*/,id,th/*theme*/,n/*menu name*/){
	if(m.Id+n==id){
		var X=0, Y=0;
		if(m.o==1){
				X=getX(getObj(id))+getObj(id).offsetWidth;
				Y=getY(getObj(id));
		}
		if(m.o==0){
				X=getX(getObj(id));
				Y=getY(getObj(id))+getObj(id).offsetHeight;

		}
		else {
				X=getX(getObj(id))+getObj(id).offsetWidth;
				Y=getY(getObj(id));

		}
		if(m.a!=null){
			if(X+getObj(p+m.a[0].Id+n).offsetWidth>wClient())
				X=getX(getObj(id))-getObj(p+m.a[0].Id+n).offsetWidth;
			getObj(p+m.a[0].Id+n).style.left=X+'px';
			getObj(p+m.a[0].Id+n).style.top=Y+'px';
		}
	}
	if(m.a!=null)
		for (var i=0;i<m.a.length;i++){
			playMenu(m.a[i],id,th,n);
			if(m.a[i].Id+n==id) {
				showhidems(m,id,th,n);
				return;
			}
		}
}

function wClient(){
	if(window.innerWidth instanceof Number)
		return window.innerWidth;
	else if(document.documentElement.clientWidth>0)
		return document.documentElement.clientWidth;
	else if(document.body.clientWidth>0)
		return document.body.clientWidth;
	return 0;
}