var currNav = new Array;
var xtmp = 0;
var xxtmp = '';
var yytmp = '';
var k;
var theUrl;

var Navigation;
Navigation = Class.create();
Navigation.prototype = {
	initialize: function(element) {
		this.elname    = element;
		this.element   = $(element);
		this.prevented = false;
		this.Roll = null;
		this.magnetic = false;
		this.level = 0;
		this.order = 0;
		this.onload();
	},
	onload: function(){
		Event.observe(this.element, 'mouseover', this.checkDisplay.bindAsEventListener(this));
		Event.observe(this.element, 'mouseout',  this.checkHide.bindAsEventListener(this));
		//Event.observe(document, 'mousewheel', this.emptyArray);
		//Event.observe(document, 'DOMMouseScroll', this.emptyArray);
	},
	checkDisplay: function(e){
		printfire('checkDisplay');
		if (!e) var e = window.event;
		var relTarg = e.relatedTarget || e.toElement;
		
		//RFC xxxx RKLANKE - voor de nieuwe vertical-menu
		if(relTarg.nodeName == "A" || relTarg.nodeName == "SPAN"){			
			relTarg = relTarg.parentNode;
		}
	    xxtmp = relTarg;
		
		this.timerstart();
		this.tableDisplay(e);
	},
	checkHide: function(e){
		printfire('checkHide');
		if (!e) var e = window.event;
		var relTarg = e.relatedTarget || e.toElement;
		
		//RFC xxxx RKLANKE - voor de nieuwe vertical-menu
		if(relTarg.nodeName == "A" || relTarg.nodeName == "SPAN"){			
			relTarg = relTarg.parentNode;
		}

	    yytmp = relTarg;
		
		this.timerstop();
		this.tableHide(e);		
	},
	timerstart: function(){
		printfire('timerstart');
		clearTimeout(k);
		if(xxtmp !='' && yytmp!=''){
			if((typeof xxtmp == 'object' && !xxtmp.getAttribute('level')) || (yytmp !== undefined && yytmp!='' && !yytmp.getAttribute('level'))){
				//printfire('time starts ticking');
				k=setTimeout(this.checktime,1000);
			}
		}
	},
	timerstop: function(){
		printfire('timerstop');
		if(yytmp !== undefined && yytmp !=''){
			
			if(typeof yytmp == 'object' && ( yytmp.getAttribute('level') || yytmp.nodeName=='UL')){
				printfire('just in time!');
				clearTimeout(k);
			}
			if(yytmp.nodeName != 'LI' && yytmp.nodeName != 'UL' ){
				//printfire('WEG ERMEE');
				this.timerstart();			
			}
		}
	},
	checktime: function(){
		//printfire('checktime');
		printfire(' time is up!');
		currNav = new Array;
		Navigation.prototype.tableHide();		
	},
	emptyArray: function(){
		currNav = new Array;
	},
	tableDisplay: function(e){
		printfire('tableDisplay');
		if (!e) var e = window.event;
		   
		//printfire('OVER magnetic: '+this.magnetic+' level: '+this.level);
		var tmp   = '';
		var level = '';
		var lvlTmp = '';
		
		this.Roll = Event.element(e);	
		
		//RFC xxxx RKLANKE - voor de nieuwe vertical-menu
		if(this.Roll.nodeName == "A" || this.Roll.nodeName == "SPAN"){
			//printfire(this.Roll.parentNode.nodeName);
			this.Roll = this.Roll.parentNode;
		}
		var level = this.Roll.getAttribute('level');
		var order = this.Roll.getAttribute('order');
		var url   = this.Roll.getAttribute('url'); //VOOR IE6
			theUrl= (url == null) ? theUrl : url;
		//var obj =  this.Roll;
		var position = Position.cumulativeOffset(this.Roll);
		var x = position[0];
		var y = position[1];
		var w = this.Roll.offsetWidth;
		var h = this.Roll.offsetHeight;
		
		if(order){
				this.order = order;
		}else{
			this.order--;	
		}
		
	  
		if(level!== null){
			tmp  = level.split('.');
			tmp2 = level.split('.');
			
			tmp.pop();
			lvlTmp = (tmp.length !=0 )? tmp.join('.') : '';
			
			//printfire(tmp2);
			//RAMON 11-02-2007 opslaan van navigatie in array		
			if(!in_array(lvlTmp, currNav) || tmp2.length  >= 1){
				
				currNav = new Array;			
			}

			for(var i=0; i <currNav.length; i++){
				var ccc = currNav[i].split('.');
				//printfire(currNav[i]+' '+ccc.length+' '+ xtmp);
				if(ccc.length == xtmp){
					currNav.splice(currNav[i]);
				}
			}
			
			if(!in_array(level, currNav)){
				currNav.push(level);
			}
			
			if(!in_array(lvlTmp, currNav) || tmp2.length >= 1){
				//printfire('HENK--'+tmp2);
				xtmp = tmp2.length;
			}
			
		}
	
	
		if($('lvl_'+level+'.01') && this.Roll.nodeName!='DIV'){
			
			var obj = $('lvl_'+level+'.01');
		    
			if(obj.style.display == 'none'){
				
				//obj.style.border = '1px solid red';
				obj.style.display = 'block';			
				//obj.style.position = 'absolute';
				obj.style.zIndex  = '600';				
				obj.style.left = '0px';
				obj.style.top = '0px';
				//printfire('offsetTOP: '+findPosY(obj)+' offsetLEFT:'+findPosX(obj) + ' Y:'+ y +' X:'+x);
				//printfire( findPosY(obj)+ ' '+ findPosX(obj)+ ' '+Position.realOffset(obj));
				var zz = Position.cumulativeOffset(obj);
				yy = zz[1];				
				xx = zz[0];
				
				switch(this.elname){
					case 'vertical_box':
										
							obj.style.left = (x -xx + w) +'px';
							obj.style.top = (y - yy + 5) +'px';	
						
					break;
					
					case 'topmenu_box':
					
						if(this.order <=3){
							//printfire('test ramon X:'+x+' Y:'+y);
							//alert(y +' '+ yy +' '+ hh);
							//alert(obj.style.top +' '+ obj.style.left);
							obj.style.left = (x -xx -5) +'px';
							obj.style.top = (y - yy + h) +'px';					
						}else{					
							obj.style.left = w+'px';
							obj.style.top = this.Roll.offsetTop+'px';
						}
					break;
				}
			}
			
		}
		
		//this.checkHide(e);
		this.tableHide();
	},
	
	tableHide: function(){
		//printfire('tableHide');
		var el = getElementsByClassName('menudiv', 'div');
		
		//printfire('verwijderen! '+ currNav.length);
		for(var i=0; i <el.length; i++){
			level = el[i].getAttribute('xxx');
			tmp = level.split('.');
			
			tmp.pop();
			lvlTmp = (tmp.length !=0 )? tmp.join('.') : '';
					
			//RAMON 11-02-2007 opslaan van navigatie in array		
			if(!in_array(lvlTmp, currNav)){
				el[i].style.display = 'none';
			}
		}
			
	}
}

function gotoUrl(itm){
	if(ie()){
		var url = theUrl;
	}else{
		var url = itm.getAttribute('url');
	}
	window.location.href = url;	

}
