$(function(){
      var a = $('.mainmenu-skoly > ul > li > a');
      
      a.each(function(index, val){ // a
      
         if ($(this).hasClass('active2')) {
            //var activeIndex = index;
            $activeIndex = $(val);
         }
         
        $(this).mouseenter(function(){ // a
           $parent = $(this).parent(); 
           $parent.find('.top_submenu:animated').stop().animate({opacity:'100'});
           if ($parent.find('.top_submenu').not(':visible')) {
              $('.top_submenu').hide();
              $parent.find('.top_submenu').not(':visible').show();
           }
           
           $(this).removeClass('active2');
           $(this).addClass('active');
	try {           
		$activeIndex.removeClass('active2');
	}
	catch (e) {
	}
        }).parent().mouseleave(function(){   // li
            $(this).find('.top_submenu').fadeOut(500);
            $(this).find('a:first').removeClass('active');

              /* if (activeIndex == a.index($(this).find('a:first'))) {
                 $(this).find('a:first').addClass('active2');
               }    */
               
            try {
		 $activeIndex.addClass('active2'); 
		}
	    catch (e) {
}	
        });
      });
      
      $('.top_submenu').mouseenter(function(){
        $(this).stop().animate({opacity:'100'});
        $(this).prev().addClass('active');
      });

})

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString())+"; path=/";
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

