var menuDisplay = 0;
$(document).ready(function(){
    dimensions = clientCoords();
    $('div#menu').mouseenter(function(){
        if (menuDisplay == 0) {
            showMenu(dimensions);
            menuDisplay = 1;
        }
    });

    $('div#menu').click(function(){
        if (menuDisplay == 1) {
            hideMenu();
            menuDisplay = 0;
        }
    });

    $(window).scroll(function () {
        $('div#menu').animate({
            top: 212 +$(window).scrollTop() +'px'
        }, 20 );
    })

    if ($('#goto').length > 0) {
        target = $('#goto').html() +'Target';
        $.scrollTo($('#' +target));
    }
});

showMenu = function(dimensions){
    if ($('div#map').length > 0){
        $('div#map').hide();
    }
    $('div#menuUI').animate({
        width: dimensions.width - 180 +'px'
    }, 1000 );
    setTimeout("$('ul#menuContent').show();", 1100);
    $('ul#menuContent').css('margin-left', '25px');
}

hideMenu = function(){
    $('ul#menuContent').hide();
    $('div#menuUI').animate({
        width: '0px'
    }, 1500 );
    if ($('div#map').length > 0){
        setTimeout('$("div#map").show()', 1550);
    }
}

clientCoords = function() {
    var dimensions = {
        width: 0,
        height: 0
    };
    if (document.documentElement) {
        dimensions.width = document.documentElement.offsetWidth;
        dimensions.height = document.documentElement.offsetHeight;
    } else if (window.innerWidth && window.innerHeight) {
        dimensions.width = window.innerWidth;
        dimensions.height = window.innerHeight;
    }
    return dimensions;
}
