/*
	Can be used only then all elements is on ( IE bug? )
*/


/*
		original from coolmenus4 (Thomas Brattli)
*/
function findPos(num){
  //alert(num)
  if(bw.ns4){   //Netscape 4
    x = document.layers["menu"+num].pageX;
    y = document.layers["menu"+num].pageY;
    w = document.layers["menu"+num].pageW;
    h = document.layers["menu"+num].pageH;
  }else{ //other browsers
    x=0; y=0; var el,temp;
    el = bw.ie4?document.all["menu"+num]:document.getElementById("menu"+num);		
    if(el.offsetParent){
		  temp = el;		  
      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well 
        temp=temp.offsetParent;			
        x+=temp.offsetLeft
        y+=temp.offsetTop;
      }
    }
    x+=el.offsetLeft
    y+=el.offsetTop
    w = el.offsetWidth
    h = el.offsetHeight
  }
  //Returning the x and y as an array
  return [x,y,w,h]
}

/*
		added from coolmenus4 (Thomas Brattli)
*/

function cm_bwcheck(){
	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7//Use dom creation
  this.reuse = this.ie||this.op7||this.usedom //Reuse layers
  this.px=this.dom&&!this.op5?"px":""
	return this
}

var bw=new cm_bwcheck();
var linktime;
var txt = '';
var cl = 'popup';
var doc = document;
var lcliked = 0;
var dtime = 100; 
//TESTAS

function allMenu ( name ) {
		this.name = name;
		this.active=-1;
		this.items = new Array ();		
		window.onscroll=new Function(this.name+".hideItemLater()");
		return this;
}

allMenu.prototype.addItem=function( id ) {
	itm = new MItem(id);
	this.items[ id ] = itm;
	return itm;
}

allMenu.prototype.showItem=function( id ) {
	clearTimeout(this.tim);
	if ( this.active == id ) return;
	if ( this.active > -1 ) {
		this.items[ this.active ].hide();
	}	
	this.items[ id ].show();
	this.active=id;
}

allMenu.prototype.hideItem=function( id ) {
	clearTimeout(this.tim);	 
	this.items[ id ].hide();
	this.active=-1;
}

allMenu.prototype.hideItemDelay=function( id ) {
	clearTimeout(this.tim); 
	var f = this.name+'.hideItem('+id+')'; 
	this.tim = setTimeout(f,dtime)
}

allMenu.prototype.hideItemLater=function() {
	if ( this.active > -1 ) {
		clearTimeout(this.tim); 
		var f = this.name+'.hideItem('+this.active+')'; 
	this.tim = setTimeout(f,dtime)
	}
}

function MItem ( id ) {
	this.id = id;
	this.moved = 0;	
	this.item = getElementById ( 'menugroup'+id );
	this.forhide = new Array();
	return this;	
}

MItem.prototype.show=function() {
	var i;
	if (!this.css) {
		this.css=bw.dom||bw.ie4?this.item.style:this.item;
	}
	if ( !this.moved ) {
		this.move();
	}
	if ( this.sel ) { for ( i = 0; i < this.sel.length; i++ ) { this.sel[i].visibility='hidden'; } }
	this.css.visibility='visible';
}

MItem.prototype.hide=function() {
	if (!this.css) {
		this.css=bw.dom||bw.ie4?this.item.style:this.item;
	}	
	this.css.visibility='hidden';
	if ( this.sel ) { for ( i = 0; i < this.sel.length; i++ ) { this.sel[i].visibility='visible'; } }
} 

MItem.prototype.move=function( ) {
		pos = findPos( this.id );
		//alert ( this.id < 1000 );
		if ( this.id < 1000 ) {
		   x = pos[0] + pos[2];
		   y = pos[1]-3;
		   //h = pos[3];
		} else {
		   x = pos[0]-5;
		   y = pos[1] + pos[3];

		}
		this.item.x=x;this.y=y; this.css.left=x+bw.px;this.css.top=y+bw.px;		
		this.moved = 1;
		//ADDING select object to hide/show 		
		if(bw.dom&&!bw.op){
			this.sel = new Array();
			var selx,sely,selw,selh,i
			w = this.item.offsetWidth;
			h = this.item.offsetHeight;			
			sel=document.getElementsByTagName("SELECT");
			for(i=0;i<sel.length;i++){
				selx=0; sely=0; var selp;
				if(sel[i].offsetParent){
					selp=sel[i]; 
					while(selp.offsetParent){
						selp=selp.offsetParent; selx+=selp.offsetLeft; sely+=selp.offsetTop;
					}
				}
				selx+=sel[i].offsetLeft; sely+=sel[i].offsetTop
				selw=sel[i].offsetWidth; selh=sel[i].offsetHeight			
				if(selx+selw>x && selx<x+w && sely+selh>y && sely<y+h){
					if(sel[i].style.visibility!="hidden"){
						this.sel[this.sel.length]=sel[i].style;
					}						
      		}
			}		
		}		
}

function getElementById ( id ) {
		if ( !doc ) doc=document;
		return bw.dom? doc.getElementById(id):bw.ie4?doc.all[id]:bw.ns4?eval(document.layers[id]):0;
}

function getLinkById ( id ) {
		if ( !doc ) doc=document;
		return bw.dom? doc.getElementById(id):bw.ie4?doc.all[id]:bw.ns4?eval(document.links[id]):0;
}

function divClick( id ) {
	if (!lcliked) {
		clicked(id);
	} else {
		lcliked = 0;
	}
}

function linkClick( l ) {
	lcliked = 1;
	clearTimeout(linktime);
	return;
}

function clicked( id ) {
	var l = getLinkById ( 'link'+id );
	if (l){
		if ((l.target == '_self') || (l.target == '') ) {			
			window.location = l.href;
		} else {
			window.open(l.href, l.target);
		}
	}
	return;
}

function print ( s ) {
	window.status=s;
}
