$(document).ready(function() {

    var _link = $('#google-map-link');
    var _helper = $('#google-map-helper');
    var _protected = false;

    var _showMap = function(e) {

        if ($('#google-map').is(':animated'))
            return;

        $('#google-map-container').show();
        $('#google-map').animate({'left':0, 'top':0}, 500, 'easeInOutExpo', function() {
            _helper.show();
            _helper.bind('mouseover', _hideMap);
        });
    }
    var _hideMap = function(e) {

        if ($('#google-map').is(':animated'))
            return;

        if (_protected) {
            _protected = false;
            return;
        }
        $('#google-map').animate({'left':445, 'top':400}, 500, 'easeInOutExpo', function() {
            $('#google-map-container').hide();
        });
        $('#google-map-mask').unbind('mouseover');
        _helper.hide();
        _helper.unbind('mouseover');
        _link.bind('mouseover', _linkHover);
    }

    var _linkHover = function(e) {
        _protected = false;
        _showMap();
        $('#google-map-mask').bind('mouseover', _showMap);
    }

    _link.bind('mouseover', _linkHover);

    $('a#goMapLink').bind('click', function(e) {
        e.preventDefault();
        $('html, body').animate({scrollTop:5000}, 700, 'easeOutExpo');
        window.setTimeout(function() {
            _link.trigger('mouseover');
            _protected = true;
        }, 300);

    });

});
