/**
 * menu.js 
 * by Garrett Smith http://dhtmlkitchen.com 
 * Provides functionality for working nodeLists.
 */
Browser = {
	isSupported : function(){
			return (Boolean(document.getElementsByTagName)
						&& Boolean(document.getElementById));
		},
	id : new function() {

			var ua= navigator.userAgent;
			var OMNI = ua.indexOf("Omni") > 0;

			this.OP5 = ua.indexOf("Opera 5") >= 0 || ua.indexOf("Opera 6") >= 0;
			this.OP7 = ua.indexOf("Opera 7") >= 0;
			this.MAC = ua.indexOf("Mac") > 0;

			this.win9x = ua.match(/Win98/) || ua.match(/Windows 95/) 
						|| ua.match(/Windows 98/) || ua.match(/Windows 95/);
			if(!this.OP5 && !OMNI){
				this.IE5 = ua.indexOf("MSIE 5") > 0;
				this.IE5_0 = ua.indexOf("MSIE 5.0") > 0;
				this.NS6 = ua.indexOf("Gecko") > 0;
				this.MOZ = this.NS6 && ua.indexOf("Netscape") == -1;
				this.MAC_IE5 = this.MAC && this.IE5;
				this.IE6 = ua.indexOf("MSIE 6") > 0;
				this.KONQUEROR = ua.indexOf("Konqueror/") > 0;
			}
		}		
};
var px = "px";
TokenizedExps = {};
function getTokenizedExp(token, flag){
	var x = TokenizedExps[token];
	if(!x)
		x = TokenizedExps[token] =  new RegExp("\\b"+token+"\\b", flag);
	return x;
}

function hasToken(s, token){
	return getTokenizedExp(token,"").test(s);
};

/** Returns an Array of all childNodes
 *  who have a className that matches the className
 *  parameter.
 *
 *	Nested elements are not returned, only
 *	direct descendants (i.e. childNodes).
 */
function getChildNodesWithClass(parent, klass){
		
	var collection = parent.childNodes;
	var returnedCollection = [];
	var exp = getTokenizedExp(klass,"");

	for(var i = 0, counter = 0; i < collection.length; i++)
		if(exp.test(collection[i].className))
			returnedCollection[counter++] = collection[i];

	return returnedCollection;
}

/** Returns an Array of all descendant elements
 *  who have a className that matches the className
 *  parameter. This method differs from getChildNodesWithClass
 *  because it returns ALL descendants (deep).
 */	
function getElementsWithClass(parent, tagName, klass){
	var returnedCollection = [];
	try{
	var exp = getTokenizedExp(klass,"");
	var collection = (tagName == "*" && parent.all) ?
		parent.all : parent.getElementsByTagName(tagName);
	
	for(var i = 0, counter = 0; i < collection.length; i++){
		
		if(exp.test(collection[i].className))
			returnedCollection[counter++] = collection[i];
	}
	return returnedCollection;
	}
	catch(x){	alert("parent = "+ parent  +" tagName = "+ tagName+" klass = "+klass);throw x;
}
}

/** Returns an Array of all descendant elements
 *  where each element has a className that matches 
 *  any of the classNames in classList.
 *
 *  This method is like getElementsWithClass except it accepts 
 *  an Array of classes to search for.
 */	

function get_elements_with_class_from_classList(el, tagName, classList){

    var returnedCollection = new Array(0);
    
    var collection = (tagName == "*" && el.all) ?
    	el.all : el.getElementsByTagName(tagName);
    var exps = [];
	for(var i = 0; i < classList.length; i++)
		exps[i] = getTokenizedExp(classList[i],"");
	for(var j = 0, coLen = collection.length; j < coLen; j++){
		kloop: for(var k = 0; k < classList.length; k++){
			if(exps[k].test(collection[j].className)){
				returnedCollection[returnedCollection.length] = collection[j];
				break kloop;
			}
		}
	}
    return returnedCollection;
}

function findAncestorWithClass(el, klass) {
	
	if(el == null)
		return null;
	var exp = getTokenizedExp(klass,"");
	for(var parent = el.parentNode;parent != null;){
	
		if( exp.test(parent.className) )
			return parent;
			
		parent = parent.parentNode;
	}
	return null;
}


function getDescendantById(parent, id){
	var childNodes = parent.all ? parent.all : parent.getElementsByTagName("*");
	for(var i = 0, len = childNodes.length; i < len; i++)
		if(childNodes[i].id == id)
			return childNodes[i];
	return null;
}

/** Removes all occurances of token klass from element el's className.
 */
function removeClass(el, klass){
	el.className = el.className.replace(getTokenizedExp(klass, "g"),"").normalize();
}

function repaintFix(el){
	el.style.visibility = 'hidden';
	el.style.visibility = 'visible';
}
var trimExp = /^\s+|\s+$/g;
String.prototype.trim = function(){
		return this.replace(trimExp, "");
};
var wsMultExp = /\s\s+/g;
String.prototype.normalize = function(){
		return this.trim().replace(wsMultExp, " ");
};
if(!Array.prototype.unshift)
	Array.prototype.unshift = function() {
        this.reverse();
        for(var i=arguments.length-1; i > -1; i--)
            this[this.length] = arguments[i];
        this.reverse();
        return this.length;
};

function toggleMenu(el)
	{if(Browser.id.OP5||Browser.id.NS4) return;var l=Button.getLabel(el);if(l.dp){if(TreeParams.OPEN_MULTIPLE_MENUS||l.m.c.aM==l.m){l.m.cS();l.m.c.aM=null;}}else{if(TreeParams.OPEN_MULTIPLE_MENUS||l.m.c.aM==null){l.m.oS();l.m.c.aM=l.m;}else{l.m.c.aM.cS();if(!TreeParams.OPEN_WHILE_CLOSING){if(l.m.c.aM!=l.m)
l.m.c.aM.mic=l.m;else{l.m.mic=null;l.m.oS();}}else{l.m.oS();l.m.c.aM=l.m;}}}}function activateMenu(id){if(!window.toggleMenu||Browser.id.OP5)
return;var b=document.getElementById(id);
if(!b) return;var me=findAncestorWithClass(b,"menu");if(me!=null)
activateMenu(me.id.replace(/Menu$/,""));
var l=Button.getLabel(getElementsWithClass(b,"*","mainmenulabel")[0]);
if(!l.dp){toggleMenu(l.el);l.dp=true;}}

function buttonOver(el){
window.status=el.parentNode.id;
l=Button.getLabel(el);if(hasToken(l.el.className,"labelHover"))
return;l.el.className+=" labelHover";}

function buttonOff(l){
window.status=window.defaultStatus;
removeClass(l,"labelHover");}
if(typeof document.getElementsByTagName=="undefined"||Browser.id.OP5)
	buttonOver=buttonOff=function(){};
	Button=function(el,cat){
		this.el=el;
		this.cat=cat;
		this.m=new Menu(document.getElementById(this.cat+"Menu"),this);
		var icons=el.getElementsByTagName("img");
		this.i=(icons.length>0)?icons[0]:null;
		this.isI=false;
		if(el.tagName.toLowerCase()=="img"){
			this.isI=true;
			this.i=el;
		}
		this.dp=false;
	};
	Button.getLabel=function(el){
	var be=findAncestorWithClass(el,"mainmenu");
	if(Menus[be.id])
		return Menus[be.id].oB;
		return new Button(el,be.id);};
		Button.prototype.sdl=function(){
		if(this.isI)
			return void(this.i.src=TreeParams.CLOSED_MENU_ICON);
			removeClass(this.el,"labelHover");
			removeClass(this.el,"labelDown");
			if(this.i!=null)
				this.i.src=TreeParams.CLOSED_MENU_ICON;
			};
			Menu=function(el,l){
			this.oB=l;
			this.id=l.cat;
			this.el=el;
			this.c=this.getC();
			this.it=getChildNodesWithClass(el,"menuNode");
			this.it.unshift(el);
			var all=getElementsWithClass(el,"*","menuNode");
			if(all.length==0){
				lis=getElementsWithClass(el,"li","menuNode");
				divs=getElementsWithClass(el,"div","menuNode");
				all=lis.length>divs.length?lis:divs;
			}
			this.al=all;
			this.al.unshift(el);
			this.cur=0;
			this._root=null;
			this.aM=null;
			this.mic=null;
			Menus[this.id]=this;};
			Menus={};
			Menu.prototype={oS:function(){if(this.io) return;
			if(this.oB.i!=null)
				this.oB.i.src=TreeParams.OPEN_MENU_ICON;
				if(this.ic){this.cE();
					if(this.itc){
						this.ito=this.itc.reverse();
						this.cur=this.itc.length-this.cur;
					}
				}else{
					this.cur=0;
					this.ito=new Array();
					if(this.itc)
						this.ito=this.itc.reverse();
					else
						this.ito=this.it;
						if(!this.oB.isI)
							this.oB.el.className+=" labelDown";
				}
				this.ic=false;
				this.io=true;
				if(this.ito[0]!=this.el)
					this.ito.reverse();
					this.pat=setInterval("Menus."+this.id+".o()",TreeParams.TIME_DELAY);
					if(Browser.id.win9x&&!Browser.id.NS6)
						this.pat2=setInterval("Menus."+this.id+".o()",TreeParams.TIME_DELAY);
						this.oB.dp=true;
					},cS:function(){
					if(this.ic) 
						return;
						if(this.io){
							this.oE();}
						else{
							this.io=false;
							this.cur=0;
							this.itc=new Array();
							for(
								var i=this.al.length-1,n=0;i>0;i--
							)
							if(this.al[i].style.display=="block")
								this.itc[n++]=this.al[i];
							}
							this.itc[this.itc.length]=this.el;
							this.pat=setInterval("Menus."+this.id+".cl()",TreeParams.TIME_DELAY);
							if(Browser.id.win9x&&!Browser.id.NS6)
								this.pat2=setInterval("Menus."+this.id+".cl()",TreeParams.TIME_DELAY);
								this.ic=true;this.oB.dp=false;
							},o:function(){
							this.ito[this.cur].style.display="block";
							if(++this.cur==this.ito.length)
								this.oE();
							},cl:function(){this.itc[this.cur].style.display="";
							if(++this.cur>=this.itc.length)
								this.cE();
							},oE:function(){
								clearInterval(this.pat);clearInterval(this.pat2);
								this.io=false;
								this.itc=this.ito.reverse();
								this.cur=this.ito.length-this.cur;
								if(!TreeParams.OPEN_MULTIPLE_MENUS&&this.c.aM!=this)
									this.cS();
									this.c.aM=this;
								},cE:function(){
									clearInterval(this.pat);
									clearInterval(this.pat2);
									this.ic=false;if(this.cur>=this.itc.length)
									this.oB.sdl();
									if(!TreeParams.OPEN_WHILE_CLOSING&&this.c.aM&&this.c.aM.mic!=null&&this.c.aM.mic!=this){
										this.c.aM.mic.oS();
										if(this.mic)
											this.c.aM=this.mic;
										}else{}
											this.mic=null;
											if(Browser.id.IE6)
												setTimeout("repaintFix(document.getElementById('"+this.el.id+"'));",50);
											},getC:function(){
												var pe=findAncestorWithClass(this.el,"menu");
												if(pe!=null){pId=pe.id.replace(/Menu$/,"");
												if(!Menus[pId])
													return Button.getLabel(getElementsWithClass(document.getElementById(pId),"*","mainmenulabel")[0]).m;
													return Menus[pId];
												}if(!this._root){
													var rt=findAncestorWithClass(this.el,"AnimTree");if(!rt)
													rt=document.body;
													if(!rt.id)
														rt.id="AnimTree_"+Math.round(Math.random()*1E5);
														if(Trees[rt.id]!=null)
															this._root=Trees[rt.id];
														else
															this._root=new Tree(rt);
														}
														return this._root;
													}
												};
												Tree=function(el){
													this.el=el;
													this.aM=null;
													this.id=el.id;
													Trees[this.id]=this;};
													Trees={};
													if(document.getElementById&&!Browser.id.OP5&&!window.T_ini){
													document.writeln("<style type='text/css'>","/*<![CDATA[*/\n",".menu,.menuNode{display:none;}\n","/*]]>*/","<"+"/style>");
													window.T_ini=true;
												}

