var isFlash = false;

$(document).ready(function () {
    isFlash = (typeof document.CosinMovie!='undefined');
    $("#menu a").click(fOption);
    fRefresh();
});

function fOption() {
    var jThis = $(this);
    var href  = jThis.attr("href");
    if(href.indexOf("#")>-1) {
        var lev  = jThis.parent().parent().attr("class").replace(/[a-z ]*/, "");
        var name = href.substr(1+href.indexOf("#"));
        aOpened[lev] = name;
        while(++lev<=3) aOpened[lev] = null;
        fRefresh();
        $("#contenedor>div:eq(2)").css({ display: "none" });
        $("#contenedor>div:eq(3)").css({ display: "none" });
        return false;
    }
    return isFlash ? fNotify(href) : true;
}

function fRefresh() {
    $("#menu .submenu").css({ display: "none" });
    $("#menu a").css({ color: ""});
    for(k in aOpened) {
        $("ul#"+aOpened[k]).css({ display: "block" });
        $("a[href='#"+aOpened[k]+"']").css({ color: "#E30D1D" });
    }
    if(typeof(k)!="undefined")
        $("a."+aOpened[k]).css({ color: "#E30D1D" });
}

function fNotify(href) {
    document.CosinMovie.SetVariable("urlDestino", href); 
    return false;
}
