	// vygeneruje retezec popisujici stav otevteni menu
	function getMenuState() {
		oMenu = document.getElementById('menu');
		oUL = oMenu.firstChild;
		
		var state = '';
		while ( oUL ) {
		  if ( oUL.nodeType == 1 )	{
		  	(oUL.className!='') ? state +='o' : state+='c';
			}
		  oUL = oUL.nextSibling;
		}
		return state;
	}

	function setMenuState( state ) {
		oMenu = document.getElementById('menu');
		oUL = oMenu.firstChild;
		
		var i = 0;
		
		while ( oUL ) {
		  if ( oUL.nodeType == 1 )	{
  		  if ( state[i] == 'o' ) {
    		  oUL.className = 'opened';
  		  } else {
    		  oUL.className = '';
        }
   		  i++;
			}
		  oUL = oUL.nextSibling;
		}
		return state;
	}

	// otevre menu
	function openMenu( oUL )	{
		oUL.className = 'opened';
	  setCookie( 'menu', getMenuState(), 2 ); 
	}
	
	// zavre menu
	function closeMenu( oUL ) {
		oUL.className = '';
	  setCookie( 'menu', getMenuState(), 2 ); 
	}

	// otevre nebo zavre menu
	function collapse(oItem)	{
		oUL = oItem.parentNode.parentNode;
		(oUL.className=='opened') ? closeMenu(oUL) : openMenu(oUL);
		oItem.href = '';
		return false;
	}
	
	// pred prechodem na odkaz zmeni jeho URL
	function alterURL( oAnchor )	{
		//oAnchor.href = oAnchor.href+'&menu='+getMenuState();
	}


  function getCookie(c_name) {
    if (document.cookie.length>0) {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1) {
          c_start=c_start + c_name.length+1;
          c_end=document.cookie.indexOf(";",c_start);
          if (c_end==-1) c_end=document.cookie.length;
          return unescape(document.cookie.substring(c_start,c_end));
      }
    }
    return "";
  }

  function setCookie(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
  }


setMenuState( getCookie('menu') );
