
$(document).ready(function() {

    //hide the all of the element with class msg_body
    $(".msg_body").hide();

    //toggle the component with class msg_body
    $(".msg_head").click(function() {
        $(this).next(".msg_body").slideToggle(300);
    });

    /* 
    * if we have  cookies
    */
    //handleCookies();
    var openId = getCookie("openItem");
    if (openId != null && openId != "") {


        //prepei na anoiksw to menu
        $("#" + openId).find(".msg_body").show();
    }

    var activea = getCookie("activelink");
    if (activea != null && activea != "") {
    
        $("#" + activea).addClass("active");
        
    }

    deleteCookie("activelink");
    deleteCookie("openItem");


    /*
    * Register click functions
    */
    $(".msg_body a").click(function() {


        //    saveMenuStatus();
        // alert("saving cookie : " + menuStatusArray.toString());
        // set the cookie each time  an  anchor is clicked
        setCookie("openItem", $(this).parents(".menuItem").attr('id'), 365);

        if ($(this).parents(".menuItem").attr('id') == "") {

        }
    });

    $("#menucontent a").click(function() {


        //    saveMenuStatus();
        // alert("saving cookie : " + menuStatusArray.toString());
        // set the cookie each time  an  anchor is clicked
        setCookie("activelink", $(this).attr('id'), 365);


    });



});



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.toGMTString());
}

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 deleteCookie(cookie_name) {
    // current date & time
    var cookie_date = new Date();
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}




