///* na podstawie skryptu ethanaka (www.ski.meagtravel.pl) */

function init()
{
    if (!document.getElementById) return;
	addHoverFunc('mmenu');
	addHoverFunc('smenu');
	liHover('switch');
//	liHover('loop');
//	addHoverFunc('loop');
	divHover('switchbutton');
      return;
}

function addHoverFunc(el)
{
	
	var thisElement,nextElement;
	var step=0;
	function howeron()
	{
		nextElement=this;
		var n=++step;
		if (!thisElement || !thisElement.hul) {
			shide();
			return;
		}
		setTimeout(function() {
			if (n==step) shide();
			},50);
	}
	
	function howeroff()
	{
		nextElement=null;
		var n=++step;
		if (!thisElement || !thisElement.hul) {
			shide();
			return;
		}
		setTimeout(function() {
			if (n==step) shide();
			},300);
	}
	
	
	function shide()
	{
		if (nextElement == thisElement) return;
		if (thisElement) {
			if (thisElement.className.indexOf('ves')>0) thisElement.className="havesub";
			else thisElement.className='';
		}
		if (nextElement) {
			if (nextElement.className.indexOf('ves')>0) nextElement.className="havesub hower";
			else nextElement.className='hower';
			}
		thisElement=nextElement;
	}
	
	function fokus()
	{
		nextElement=this.linea;
		this.className='fokus';
		step++;
		shide();
	}
	
	function unfokus()
	{
		nextElement=null;
		this.className='';
		step++;
		shide();
	}
	
	function fadd(li)
	{
		var el=li,i;
		var as=el.getElementsByTagName('a');
		for (i=0;i<as.length;i++) {
			as[i].linea=el;
			as[i].onfocus=fokus 
			as[i].onblur=unfokus;
		}
	}
	
	el=document.getElementById(el);
	var li;
	for (li=el.firstChild;li;li=li.nextSibling) {
		if (li.nodeName.toLowerCase()=='li') {
			li.onmouseover=howeron;
			li.onmouseout=howeroff;
			var s=li.getElementsByTagName('ul');
			if (s.length) li.hul=s[0];
			fadd(li);
		}
	}
}

function addHoverLoop(el)
{
	
	var thisElement,nextElement;
	var step=0;
	function howeron()
	{
		nextElement=this;
		var n=++step;
		if (!thisElement || !thisElement.hul) {
			shide();
			return;
		}
		setTimeout(function() {
			if (n==step) shide();
			},50);
	}
	
	function howeroff()
	{
		nextElement=null;
		var n=++step;
		if (!thisElement || !thisElement.hul) {
			shide();
			return;
		}
		setTimeout(function() {
			if (n==step) shide();
			},300);
	}
	
	
	function shide()
	{
		if (nextElement == thisElement) return;
		if (thisElement) {
			if (thisElement.className.indexOf('ves')>0) thisElement.className="havesub";
			else thisElement.className='';
		}
		if (nextElement) {
			if (nextElement.className.indexOf('ves')>0) nextElement.className="havesub hower";
			else nextElement.className='hower';
			}
		thisElement=nextElement;
	}
	
	function fokus()
	{
		nextElement=this.linea;
		this.className='fokus';
		step++;
		shide();
	}
	
	function unfokus()
	{
		nextElement=null;
		this.className='';
		step++;
		shide();
	}
	
	function fadd(li)
	{
		var el=li,i;
		var as=el.getElementsByTagName('a');
		for (i=0;i<as.length;i++) {
			as[i].linea=el;
			as[i].onfocus=fokus 
			as[i].onblur=unfokus;
		}
	}
	
	el=document.getElementById(el);
	var li;
	for (li=el.firstChild;li;li=li.nextSibling) {
		if (li.nodeName.toLowerCase()=='li') {
			li.onmouseover=howeron;
			li.onmouseout=howeroff;
			var s=li.getElementsByTagName('ul');
			if (s.length) li.hul=s[0];
			fadd(li);
		}
	}
}

function liHover(el){
	var sfEls = document.getElementById(el).getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hower";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hower\\b"), "");
		}
	}
}

function divHover(el) {
		var sfEls = document.getElementById(el).getElementsByTagName("DIV");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hower";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hower\\b"), "");
		}
	}
}

document.documentElement.className="js";
//if (window.opera) document.documentElement.className+=" opera";

(function()
{
	var wonlo=window.onload;
	window.onload=function() {
		init();
		if (wonlo) wonlo();
	}
})();
