if (document.layers) {navigator.family = "nn4"}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}
op7 = (window.opera && document.createComment ||  navigator.userAgent.indexOf("Opera") ) ; 
w3dom = (document.getElementById || op7); 
document.write('<div id="kqmenutrigger" style="position:absolute;left:0px; padding:0px; background-color:#FFFFFF; display:none; z-index:2000">&nbsp;a</div>');
document.write('<div id="kqmenu" class="kqmenu" style="position:absolute; top:0px; left:0px; padding:0px; background-color:#FFFFFF; display:none; z-index:999">&nbsp;a</div>');
document.write('<div id="kqsubmenu" class="kqmenu" style="position:absolute; top:0px; left:0px; padding:0px; background-color:#FFFFFF; display:none; z-index:999">&nbsp;a</div>');
if( !Opera )
{
	document.write('<iframe id="kqmenuiframe" style="position:absolute; top:0px; left:0px; display:none;" src="javascript:false" scrolling="no" frameborder="0"></iframe>');
	document.write('<iframe id="kqsubmenuiframe" style="position:absolute; top:0px; left:0px; display:none;" src="javascript:false" scrolling="no" frameborder="0"></iframe>');
}
else
{
	document.write('<div id="kqmenuiframe" style="position:absolute; top:0px; left:0px; padding:0px; background-color:#FFFFFF; display:none; z-index:998">&nbsp;a</div>');
	document.write('<div id="kqsubmenuiframe" class="kqmenu" style="position:absolute; top:0px; left:0px; padding:0px; background-color:#FFFFFF; display:none; z-index:998">&nbsp;a</div>');
}

var foo	= document.getElementById('kqmenu'); 
var subfoo = document.getElementById('kqsubmenu'); 
var footrigger = document.getElementById('kqmenutrigger'); 
var fooiframe = document.getElementById('kqmenuiframe'); 
var subfooiframe = document.getElementById('kqsubmenuiframe'); 
var hoveractive = false; 
var menuover = false; 
foo.innerHTML = ''; 
subfoo.innerHTML = ''; 
footrigger.innerHTML = '';

if (window.captureEvents) 
{ 
	window.captureEvents(Event.MOUSEMOVE ); 
	window.onmousemove = mouseTracker; 
	document.documentElement.onclick = killmenuAll; 
} 
else 
{ 
	document.onmousemove = mouseTracker; 
	document.documentElement.onclick = killmenuAll; 
}
function mouseTracker(e) 
{ 
	 
	var e = e || window.Event || window.event; 
	window.pageX = e.pageX || e.clientX;  
	window.pageY = e.pageY || e.clientY;
	//console.log('y:'+window.pageY+' x:'+window.pageX); 
}
var kqmenudown = 0; 
var subshow = -1; 
var mouseoversub = false; 
var mouseovermain = false; 
var menuclick=false;
function getMenuTop(offset) 
{ 
	if( document.documentElement.scrollTop == 0 ) 
		return document.body.scrollTop+offset; 
	else 
		return document.documentElement.scrollTop+offset; 
}
function KQMenu(width)
{
	this.width = width; 
	this.spacer = 0; 
	this.menuItems = new Array(); 
	this.infoItems = new Array(); 
	this.pos = -1;	
	this.content = ''; 
	this.ownpos = false; 
	this.spacercounter = 0;
	this.setownpos =  function(inx,iny) 
	{ 
		this.ownpos = true;
		this.x = inx; 
		this.y = getMenuTop(iny); 
	}
	this.addMenuItem = function(text,url,image,axx,title,newwindow ) 
	{
		this.menuItems[++this.pos] = new Array(text,url,image,axx,new Array(), title,newwindow);	
	}
	this.addSubMenuItem = function(text,url,image,axx,title,newwindow ) 
	{ 
		this.menuItems[this.pos][4][this.menuItems[this.pos][4].length] = new Array(text,url,image,axx, title,newwindow); 
	}
	this.addMenuItemInFrame= function(url,height,scrolling) 
	{ 
		this.frameheight+=height; this.menuItems[++this.pos] = new Array(url,height,scrolling); 
	}	
	this.addSpacer = function() 
	{ 
		this.spacer++; this.menuItems[++this.pos] = new Array(true); 
	}
	this.generateTrigger = function() 
	{ 
		this.setTriggerContent(); 
	}
	this.generate = function() 
	{ 
		menuclick = true;killsubmenu(); 
		this.height = (this.menuItems.length-this.spacer)*20; 
		if( this.spacer > 0 ) 
			this.height += this.spacer*5; 
		if( this.frameheight > 0 ) 
			this.height +=this.frameheight-20; 
		this.setMenuTop(); 
		
		this.content += '<ul class="kqmenu" style="width:'+this.width+'px">'; 
		
		for(i=0; i< this.menuItems.length; i++ ) 
		{ 
			if( this.menuItems[i].length > 3 ) 
			{
				this.setMenuItem(i,false,this.menuItems[i][0],this.menuItems[i][1],this.menuItems[i][2],this.menuItems[i][3],this.menuItems[i][4],this.menuItems[i][5],this.menuItems[i][6]); 
			} 
			else if ( this.menuItems[i].length > 2 ) 
			{ 
				this.setIframe(this.menuItems[i][0],this.menuItems[i][1],this.menuItems[i][2]); 
			} 
			else 
			{ 
				this.setSpacer(); 
			}	
		} 
		this.content += '</ul>'; 
		this.setMenuBottom(); 
		
		this.setContent(false); 
	}
	this.showSub= function(pos,spacer,trigger) 
	{ 
		if( subshow == pos ) 
			return; 
		subshow = pos; 
		this.content=''; 
		this.height = this.menuItems[pos][4].length*20; this.setMenuTop(); 
		this.content += '<ul class="kqmenu" style="width:'+this.width+'px">'; 
		for(i=0; i< this.menuItems[pos][4].length; i++ ) 
			this.setMenuItem(i,true,this.menuItems[pos][4][i][0],this.menuItems[pos][4][i][1],this.menuItems[pos][4][i][2],this.menuItems[pos][4][i][3],new Array(),this.menuItems[pos][4][i][4],this.menuItems[pos][4][i][5]); 
		this.content += '</ul>'; 
		this.setMenuBottom(); 
		this.setContent(true,spacer,trigger); 
	}
	this.setExtraTop = function(text,height,width,js,out,title) 
	{ 
		this.content += '<div style="width:'+width+'px;height:'+height+'px" onclick="'+js+';hoveractive=true" title="'+title+'" class="kqmenuHover">'+text+'</div>'; 
	}
	this.setMenuTop = function() 
	{ 
		this.content += '<div style="width:'+this.width+'px">'; 
	}
	this.setMenuBottom = function() 
	{
		this.content += '</div>'; 
	} 
	this.setSpacer = function() 
	{ 
		this.spacercounter++; this.content += '<li><hr /></li>'; 
	}
	this.setIframe = function(url,height,scrolling) 
	{
		this.content += '<li><iframe id="kq_menu_iframe" '; 
		if( scrolling == true ) 
		this.content += ' scrolling="NO" '; 
		this.content += ' frameborder="0" height="'+height+'" width="'+(width-2)+'" src="'+url+'"></iframe></li>'; 
	}
	this.setMenuItem = function(i,issub,text,url,image,axx,submenu,title,newwindow) 
	{ 
		var classname = ""; 
		var extra = ""; 
		var eventid = 'style="cursor: default" '; 
		if( submenu.length > 0 ) 
		{ 
			url = 'void(0);'; 
			classname = 'menuButtonSub'; 
			extra = 'this.className = \'menuButtonHover\';this.style.cursor = \'default\';kqmenudown = '+i+';menu.showSub('+i+','+this.spacercounter+',this); mouseoversub = true;'; 
		} 
		else 
		{ 
			if( issub == false ) 
				extra = 'killsubmenu();'; 
			
			extra += 'this.className = \'menuButtonHover\';mouseoversub = false;'; 
			eventid = 'style="cursor: hand" onmousedown="'+url+'"'; 
			classname = "menuButton"; 
		} 
		extra += 'menuover=true'; 
		this.content += '<li ' + ((image) ? ' style="background-image:url('+image+');background-repeat:no-repeat;	background-position: center left;" ' : ' ' )+'>'; 
		if( axx == 1 ) 
			this.content += '<div class="'+classname+'" onclick="javascript:'+url+'"  onmouseover="'+extra+'" onmouseout="this.className = \''+classname+'\';mouseover=false;">'+text+'</div>'; 
		else 	
			this.content += '<span class="disabled">'+text+'</span>'; 
		this.content += '</li>'; 
	}
	this.setTriggerContent = function() 
	{ 
		objt = footrigger; 
		objt.style.left=this.x+'px'; 
		objt.style.top= this.y+"px"; 
		if (navigator.family == 'nn4' ) 
		{
			objt.document.write(this.content);
			objt.document.close(); 
		} 
		else 
		{ 
			objt.innerHTML = this.content; 
		} 
		objt.style.visibility = "visible"; 
		objt.style.display = "block";  
	}
	this.setContent = function(issub,spacer,trigger) 
	{ 
		obj = ( issub ) ? subfoo : foo; 
		objiframe = ( issub ) ? subfooiframe : fooiframe; 
		this.setPos(issub,spacer,trigger); 
		if (navigator.family == 'nn4' ) 
		{ 
			obj.document.write(this.content); 
			obj.document.close(); 
		} 
		else 
		{ 
			obj.innerHTML = this.content; 
		} 
		
		if( issub ) 
		{ 
			objiframe.style.width = obj.offsetWidth+'px'; 
			objiframe.style.height = obj.offsetHeight+'px'; 
		} 
		else 
		{ 
			objiframe.style.width = this.width+'px'; 
			objiframe.style.height = this.height+2+'px'; 
		} 
		
		obj.style.display = "block"; 
		objiframe.style.width = obj.offsetWidth+'px'; 
		objiframe.style.height = obj.offsetHeight+'px'; 
		objiframe.style.top = obj.style.top; 
		objiframe.style.left = obj.style.left; 
		objiframe.style.zIndex = obj.style.zIndex - 1; 
		objiframe.style.visibility = "visible"; 
		objiframe.style.display = "block";  
	}
	this.getRoughPosition = function(ele)
	{
		var pos = ele.offsetTop;
		var tmp = ele.offsetParent;
		while(tmp != null )
		{
			pos += tmp.offsetTop;
			tmp = tmp.offsetParent;
		}
		return pos;
	}
	this.getViewportSize = function()
	{
	 var size = [0, 0];
	
	 if (typeof window.innerWidth != 'undefined')
	 {
	   size = [
	       window.innerWidth,
	       window.innerHeight
	   ];
	 }
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	   size = [
	       document.documentElement.clientWidth,
	       document.documentElement.clientHeight
	   ];
	 }
	 else
	 {
	   size = [
	       document.getElementsByTagName('body')[0].clientWidth,
	       document.getElementsByTagName('body')[0].clientHeight
	   ];
	 }
	
	 return size;
	}
	
	this.getScrollingPosition = function()
	{
	 var position = [0, 0];
	
	 if (typeof window.pageYOffset != 'undefined')
	 {
	   position = [
	       window.pageXOffset,
	       window.pageYOffset
	   ];
	 }
	
	 else if (typeof document.documentElement.scrollTop
	     != 'undefined' && document.documentElement.scrollTop > 0)
	 {
	   position = [
	       document.documentElement.scrollLeft,
	       document.documentElement.scrollTop
	   ];
	 }
	
	 else if (typeof document.body.scrollTop != 'undefined')
	 {
	   position = [
	       document.body.scrollLeft,
	       document.body.scrollTop
	   ];
	 }
	
	 return position;
	}
	this.setPos = function(issub,spacer,trigger) 
	{ 
		if( this.ownpos && !issub ) 
		{ 
			var x = this.x; 
			var y = this.y; 
		}
		else 
		{ 
			obj = ( issub ) ? subfoo : foo; 
			if( issub ) 
			{ 
				var x = parseInt(foo.style.left)+this.width-15; 
				var y =  this.getRoughPosition(trigger)+4;
				var scrollSize = this.getScrollingPosition();
				var size = this.getViewportSize();

				if( (y-scrollSize[1]+this.height) > size[1] )
					y -= this.height;
		 
			} 
			else 
			{ 
				var posx = window.pageX; 
				var posy = window.pageY; 
				
				var scrollSize = this.getScrollingPosition();
				var size = this.getViewportSize();
				var scrollTop = Math.max(document.body.scrollTop,document.documentElement.scrollTop); 
				var scrollLeft = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft); 
				var scrollSize = this.getScrollingPosition();
				var size = this.getViewportSize();
				var clientWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth); 
				var clientHeight = Math.max(document.body.clientHeight,document.documentElement.clientHeight); 
				if(navigator.family =="gecko") 
				{ 
					var x = posx-40; 
					if( (x+this.width) > clientWidth) 
						x = posx-this.width+20; 
					var y = posy; 
					if( (y-scrollSize[1]+this.height) > size[1]) 
						y = posy-this.height; 
					else 
						y = y -10; 
				} 
				else 
				{ 
					var x = posx+scrollLeft-40; 
					if( (x+this.width) > clientWidth) 
						x = posx+scrollLeft-this.width+20; 
					var y = posy+scrollTop; 
					if( (y+this.height) > clientHeight) 
						y = posy+scrollTop-this.height; 
					else 
						y = y -10;
				} 
			
				
			} 
		}  
		obj.style.left=x+'px'; 
		obj.style.top=y+'px'; 
	} 
}
function killmenu() 
{ 
	if ( !mouseoversub ) 
	{ 
		if( foo ) 
			foo.style.display = "none"; 
		fooiframe.style.display = "none"; 
		killsubmenu(); 
	} 
}
function killmenuAll() 
{
	if( menuclick ) 
	{
		menuclick =false;
		return; 
	} 
	if( foo ) 
	{ 
		foo.style.display = "none"; 
		fooiframe.style.display = "none"; 
	} 
	killsubmenu(); 
	killtrigger(); 
	hoveractive = false; 
	menuclick=false; 
}
function killsubmenu() 
{ 
	subfoo.style.display = "none"; 
	subfooiframe.style.display = "none"; 
	subshow = -1; 
}
function killtrigger() 
{ 
	footrigger.style.visibility = "hidden"; 
}
