﻿//<!--
var cssSbMnu = '.submenu';
var cssSbMnuBg = '.submenu_bg';
var cssItem = '.mnuitem';

$(document).ready(function() {
    initMnu();
});

function initMnu() {

    var title = document.title;
    $(cssItem).click(function(e) {
        //must use visibility style instead of hide/show for IE compatibility
        var root = $(cssSbMnu, $(this).parent().parent());
        root.css("visibility", "hidden");
        var root = $(cssSbMnuBg, $(this).parent().parent());
        root.css("visibility", "hidden");
        var sbmnu = $(this).parent().find(cssSbMnu + ":first");
        var sbmnubg = $(this).parent().find(cssSbMnuBg + ":first");
        sbmnubg.css("visibility", "visible");
        sbmnu.css("visibility", "visible");

        //reset others for alt style
        reset($(".smnuitem", $(this).parent().parent().parent()), "a");

        //set fixed class
        select($(this).parent(), "a:first");
        if (window.location.hash != '') 
            document.title = $(this).text() + ' - ' + title;
        return true;
    }
    );

    //show menu based on current page (server side set)
    var a = $("a.selected:first");

    if(a.size() == 0)
    //if there is no selection, try set based on location.hash (client side)
    {
        if (window.location.hash != '') {
            var id = "mnu_" + window.location.hash.replace(new RegExp("^#/"),"").replace(new RegExp("/"),"_");
            //alert(id);
            a = $("li#" + id).find("a:first");
            select(a.parent(), a);
            document.title = a.text() + ' - ' + title;
        }
    }
    if (a.size() > 0) {
        //alert(a.parent().html());
        //if not root
        if (a.parent().parent().parent().attr("id") != 'navigation') {
            $(cssSbMnuBg, a.parents(cssSbMnu).parent()).css("visibility", "visible");
            a.parents(cssSbMnu).css("visibility", "visible");
            //select($(this), a);
            select(a.parent().parent().parent(), "a:first");
        } else {
            $(cssSbMnuBg, a.parent().children(cssSbMnu).parent()).css("visibility", "visible");
            a.parent().children(cssSbMnu).css("visibility", "visible");
            //select($(this), a);
            //select(a.parent().parent().parent(), "a:first");
        }
        //set childs visible for selected option
        a.parent().children(cssSbMnu).css("visibility", "visible");
        //alert(a.parent().html());
    }
}

function reset(cntx, selector) {
    cntx.each(function() {
            $(selector, $(this)).removeClass("selected");
    });
}

function select(cntx, selector) {

    cntx.each(function() {
            $(selector, $(this)).addClass("selected");
    });

}

//-->
