$(document).ready(function(){
    if(location.search)$("a.mgb-menuitem[href$='"+location.search+"']").addClass("active");
    else{
        mypath=location.pathname.split('/');
        mypath=mypath[mypath.length-1];
        if(mypath)$("a.mgb-menuitem[href$='"+mypath+"']").addClass("active");
    }
    loadMenuStates();
    $("h4.mgb-menu-head").click(function(){
        $(this).next().next().toggleClass("hide");
        rememberState();
    });
    rememberState();
    $(".mgb-bio-bottom div:even").addClass("clearLeft");
    $(".mgb-trigger").hover(function(){
        $(this).addClass("over");
    },function(){
        $(this).removeClass("over");
    });
    $(".mgb-trigger").click(function(){
        $(".mgb-main-image").hide();
        $(".mgb-trigger").removeClass("active");
        $(this).addClass("active");
        myid=$(this).attr("id");
        $(".mgb-panel").hide();
        $("#"+myid.split("_")[1]).show();
    });
    if (/iPhone/i.test(navigator.userAgent)||/iPod/i.test(navigator.userAgent)) { // sniff     
        $(".iphonebutton").show();
    }
});
function loadMenuStates(){
    if($.cookie("mgb_menus")){
        menustates=$.cookie("mgb_menus").toString().split("|");
        var i=0;
        $("h4.mgb-menu-head").each(function(){
            if(menustates[i]=="true")$(this).next().next().addClass("hide");
            else $(this).next().next().removeClass("hide");
            i++;
        });
    }
}
function rememberState(){
    states="";
    $(".mgb-vertical-menu").each(function(){   
        states+=$(this).hasClass("hide").toString()+"|";
    });
    $.cookie("mgb_menus", states, { path: '/', expires: 10 });
}