var IE = document.all;

function ustawCookie( name, value, days )
{
	if (days)
   {
		var date = new Date();
		date.setTime( date.getTime() + (days*24*60*60*1000) );
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
   
	document.cookie = name + "=" + value + expires;
}


function pokazCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


var Menu = function()
{   
   var that = this;
   var MenuInterval;
   var MenuOld = null;
   var NazwaMenu = "ActiveMenu";


   this.Make = function( Obj )
   {
      this.Clear();
      if( Obj === MenuOld )
         return false;

      Obj.parentNode.className = "kategoria active";
      if(MenuOld != null) MenuOld.parentNode.className = "kategoria";
      
      ustawCookie(NazwaMenu, Obj.Number, 1);

      MenuOld = Obj;
   }
   
   this.Selection = function( e )
   {
      e=e||event;
      var Elem = (IE) ? e.srcElement : e.target;
      MenuInterval = setInterval(function() { that.Make( Elem ); }, 300 );
   }
   
   this.Clear = function()
   {
      clearInterval(MenuInterval);
   }

   this.Init = function()
   {
      var Child = document.getElementById('menu_lo5').getElementsByTagName("em");
      for( var i = 0; i < Child.length; i++ )
      {
         Child[i].Number = i;

         if(!IE)
         {
            Child[i].addEventListener('mouseover', that.Selection, false);
            Child[i].addEventListener('mouseout',  that.Clear, false);
         }
         else
         {
            Child[i].attachEvent('onmouseover', that.Selection);
            Child[i].attachEvent('onmouseout', that.Clear);
         }
      }

      var Active = pokazCookie( NazwaMenu );
      that.Make( Child[(Active==null)?0:Active] );
   }
};
