/* показывает или скрывает блок подменю*/
function toggleMenuBlockVis(id)
{
    subMenu.slideSubMenu(id);
    return false;
}

function subMenuObj(cookieName)
{
    this.open_submenu_cookie_name=cookieName;
    this.slide_time=200;
    this.cookie_str=this.getCookie(this.open_submenu_cookie_name);
    this.open_submenu=new Array();
    if(this.cookie_str.length)
    {
        this.open_submenu=this.cookie_str.split('.');
    }
    this.now = new Date();
    this.cookie_expires = new Date(this.now.getTime() + 1000 * 60 * 60 * 24 * 30);
}

subMenuObj.prototype.slideSubMenu = function(id)
{  
    if($("#"+id).css('display')=='none'){
        $("#"+id).animate({ 
            opacity: "show"
        }, this.slide_time);
    } else {
//        $("#"+id).animate({
//            opacity: "hide"
//        }, this.slide_time);
    }
	
    //$(".desc_of_"+id).slideToggle(this.slide_time);

    ind=this.isOpen(id);
    if(ind!==false) this.open_submenu.splice(ind, 1);
    else this.open_submenu.push(id);
   
    this.updateCookie();
    return false;
}

subMenuObj.prototype.isOpen = function(id)
{
    if(!this.open_submenu.length) {
        return false;
    }
    for (var n=0; n<this.open_submenu.length; n++) {
        if (this.open_submenu[n] == id) return n;
    }
    return false;
}

subMenuObj.prototype.getCookie = function(cookieName) {
    var cookieValue = '';
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1) {
        var posValue = posName + (escape(cookieName) + '=').length;
        var endPos = document.cookie.indexOf(';', posValue);
        if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
        else cookieValue = unescape(document.cookie.substring(posValue));
    }
    return (cookieValue);
};

subMenuObj.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
    document.cookie =
    escape(cookieName) + '=' + escape(cookieValue)
    + (expires ? '; expires=' + expires.toGMTString() : '')
    + (path ? '; path=' + path : '')
    + (domain ? '; domain=' + domain : '')
    + (secure ? '; secure' : '');
};

subMenuObj.prototype.updateCookie = function()
{
    var str = '';
    for (var n=0; n<this.open_submenu.length; n++)
    {
        if (str) str += '.';
        str += this.open_submenu[n];
    }
    this.cookie_str=str;
    this.setCookie(this.open_submenu_cookie_name, this.cookie_str,this.cookie_expires,'/');
//alert(this.cookie_str);
}

subMenu = new subMenuObj('subMenu_open');

