//****************Objekt menu****************
/*
obsluhuje menu, je osetren na bug zobrazovani vrstvy nad selectem v ie
	
	Parametry konstruktoru:
		name_obj			- nazev objektu, pod kterym je spusten
		delay				- doba v ms, kterou se ma pockat, nez se menu schova
				
	Metody:
	
	Verejne:
		vse obstara konstruktor
				
	Privatni:
		register_method		- zaregistruje metody
		register_event		- zaregistruje udalosti
		initialise			- vypne zobrazeni divu, nastavi pozice
		show_dropDown		- zobrazi moznosti pod tlacitkem
		plan_hide_dropDown	- naplanuje schovani moznosti
				
OKi98
*/
function menu(name_obj,delay) {
	var i;
	this.menuItem=new Array('home','demand','supply','service','about','law_consult','contact','link');
	this.error=false;
	this.path=new Array();
	this.path['button']=new Array();
	this.path['dropDown']=new Array();
	for (i=0;i<this.menuItem.length;i++) {
		if (!(this.path['button'][''+this.menuItem[i]+'']=document.getElementById('menu_button_'+this.menuItem[i]))) {
//			alert('nebyl nalezen element s id=menu_button_'+this.menuItem[i]+' menu nebude fungovat');
			this.error=true;
			}
			else this.path['dropDown'][''+this.menuItem[i]+'']=document.getElementById('menu_dropDown_'+this.menuItem[i]);
		}
	this.register_method=menu_register_method;
	this.register_method();
	this.userAgent=get_userAgent();
	if (this.userAgent=='na') {
//		alert('používáte neznámý typ prohlížeče, menu se nebude zobrazovat');
		this.error=true;
		}
	if (!this.error) {
		this.names=new Array();
		this.names['obj']=name_obj;
		this.delay=delay;
		this.timer='na';
		this.current_menuItem='na';
		if (this.userAgent=='ie') this.path['iframe']=new Array();
		this.initialise();
		this.register_event();
		}
	}

function menu_register_method() {
	this.register_event=menu_register_event;
	this.initialise=menu_initialise;
	this.show_dropDown=menu_show_dropDown;
	this.plan_hide_dropDown=menu_plan_hide_dropDown;
	this.hide_dropDown=menu_hide_dropDown;
	}

function menu_register_event() {
	var i;
	for (i=0;i<this.menuItem.length;i++) {
		switch (this.userAgent) {
			case 'ie':
				eval('this.path[\'button\'][\''+this.menuItem[i]+'\'].attachEvent(\'onmouseover\',function anonymous() {'+this.names['obj']+'.show_dropDown(\''+this.menuItem[i]+'\');})');
				eval('this.path[\'button\'][\''+this.menuItem[i]+'\'].attachEvent(\'onmouseout\',function anonymous() {'+this.names['obj']+'.plan_hide_dropDown();})');
				if (this.path['dropDown'][''+this.menuItem[i]+'']!=null) {
					eval('this.path[\'dropDown\'][\''+this.menuItem[i]+'\'].attachEvent(\'onmouseover\',function anonymous() {'+this.names['obj']+'.show_dropDown(\''+this.menuItem[i]+'\');})');
					eval('this.path[\'dropDown\'][\''+this.menuItem[i]+'\'].attachEvent(\'onmouseout\',function anonymous() {'+this.names['obj']+'.plan_hide_dropDown();})');
					}
			break;
			case 'ns':
				eval('this.path[\'button\'][\''+this.menuItem[i]+'\'].addEventListener(\'mouseover\',function anonymous() {'+this.names['obj']+'.show_dropDown(\''+this.menuItem[i]+'\');},false)');
				eval('this.path[\'button\'][\''+this.menuItem[i]+'\'].addEventListener(\'mouseout\',function anonymous() {'+this.names['obj']+'.plan_hide_dropDown();},false)');
				if (this.path['dropDown'][''+this.menuItem[i]+'']!=null) {
					eval('this.path[\'dropDown\'][\''+this.menuItem[i]+'\'].addEventListener(\'mouseover\',function anonymous() {'+this.names['obj']+'.show_dropDown(\''+this.menuItem[i]+'\');},false)');
					eval('this.path[\'dropDown\'][\''+this.menuItem[i]+'\'].addEventListener(\'mouseout\',function anonymous() {'+this.names['obj']+'.plan_hide_dropDown();},false)');
					}
			break;
			}
		}
	}
	
function menu_initialise() {
	var i,iframe,x,y,current_obj,leftValue,tmp_left;
	if (this.userAgent=='ie') {
		iframe=document.createElement('iframe');
		iframe.style.position='absolute';
		iframe.style.zIndex=1;
		iframe.style.visibility='hidden';
		iframe.style.border='none';
		iframe.scrolling='no';
		this.path['button'][''+this.menuItem[0]+''].parentNode.insertBefore(iframe,this.path['button'][''+this.menuItem[0]+'']);
		this.path['iframe']=iframe;
		}
	for (i=0;i<this.menuItem.length;i++) {
		if (this.path['dropDown'][''+this.menuItem[i]+'']!=null) {
			this.path['dropDown'][''+this.menuItem[i]+''].style.visibility='hidden';
			if (this.userAgent=='ie') {
				iframe=document.createElement('iframe');
				iframe.style.position='absolute';
				iframe.style.zIndex=1;
				iframe.style.visibility='hidden';
				iframe.style.border='none';
				iframe.scrolling='no';		
				tmp_left=parseInt(this.path['dropDown'][''+this.menuItem[i]+''].currentStyle['left']);
				if (!isNaN(tmp_left)) {
					leftValue=tmp_left;
					tmp_left=parseInt(this.path['dropDown'][''+this.menuItem[i]+''].style.left);
					if (!isNaN(tmp_left)) leftValue+=tmp_left;
					leftValue+='px';
					}
					else leftValue=this.path['dropDown'][''+this.menuItem[i]+''].currentStyle['left'];
				iframe.style.left=leftValue;
				iframe.style.top=this.path['dropDown'][''+this.menuItem[i]+''].style.top;
				iframe.style.width=this.path['dropDown'][''+this.menuItem[i]+''].offsetWidth+'px';
				iframe.style.height=this.path['dropDown'][''+this.menuItem[i]+''].offsetHeight+'px';
				this.path['dropDown'][''+this.menuItem[i]+''].parentNode.insertBefore(iframe,this.path['dropDown'][''+this.menuItem[i]+'']);
				this.path['iframe'][''+this.menuItem[i]+'']=iframe;
				}
			}
		}
	}
	
function menu_show_dropDown(menuItem) {
	if (this.timer!='na') {
		clearTimeout(this.timer);
		this.timer='na';
		}
	if (this.current_MenuItem!=menuItem) {
		if (this.current_menuItem!='na') {
			this.path['dropDown'][''+this.current_menuItem+''].style.visibility='hidden';
			if (this.userAgent=='ie') this.path['iframe'][''+this.current_menuItem+''].style.visibility='hidden';
			this.current_menuItem='na';
			}
		if (this.path['dropDown'][''+menuItem+'']!=null) {
			this.current_menuItem=menuItem;
			this.path['dropDown'][''+menuItem+''].style.visibility='visible';
			if (this.userAgent=='ie') this.path['iframe'][''+menuItem+''].style.visibility='visible';
			}
		}
	}

function menu_plan_hide_dropDown() {
	if (this.current_menuItem!='na') eval('this.timer=setTimeout(function anonymous() {'+this.names['obj']+'.hide_dropDown();},'+this.delay+')');
	}

function menu_hide_dropDown() {
	this.path['dropDown'][''+this.current_menuItem+''].style.visibility='hidden';
	if (this.userAgent=='ie') this.path['iframe'][''+this.current_menuItem+''].style.visibility='hidden';
	this.current_menuItem='na';
	}

/*
all scripts on www.agentura-acco.cz were created by OKi98, all are tested for IE and Mozilla. I dont care about other
browsers.
Scripts can be freely used but keep this note intact.
*/
