$(function() {
    //hide when the page loads
    $('#map_information').hide();
        
    $('#americaShow').bind('click', function() {
        showRegion("america");
        return false;
    });
    $('#americaSlice').bind('click', function() {
        showRegion("america");
        return false;
    });
    $('#europeShow').bind('click', function() {
        showRegion("europe");
        return false;
    });
    $('#europeSlice').bind('click', function() {
        showRegion("europe");
        return false;
    });
    $('#asiaShow').bind('click', function() {
        showRegion("asia");
        return false;
    });
    $('#asiaSlice').bind('click', function() {
        showRegion("asia");
        return false;
    });
});

function showRegion(region) {
    $('.highlightedRegion').removeClass('highlightedRegion');
    $('#'+region+'Show').addClass('highlightedRegion');
    $('.sliceShown').removeClass('sliceShown');
    $('#'+region+'Slice').addClass('sliceShown');

    //if IE6 then the slideup and down will fail - so have to just show/hide
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        $('#map_information').hide();
        $('#map_information').removeClass("europeInformation"); //different classnames because IE6 sucks
        $('#map_information').removeClass("asiaInformation");
        $('#map_information').removeClass("americaInformation");
        $('#map_information').addClass(region+"Information");
        $('.innerInfo').hide(); //hide all inner information
        $('#'+region+'Inner').show();
        if (typeof document.body.style.maxHeight == "undefined") { //if IE6
            $('a.slice').height('311px');
        }
        else {
            $('a.slice').height('306px');
        }
        $('#map').addClass('withBorder');
        $('#map_information').show();
    }
    else {
        $('#map_information').slideUp("slow", function() {
            $('#map_information').removeClass("europe");
            $('#map_information').removeClass("asia");
            $('#map_information').removeClass("america");
            $('#map_information').addClass(region);
            $('.innerInfo').hide(); //hide all inner information
            $('#'+region+'Inner').show("normal", function() { //must slide down only once the new content has been loaded
                $('a.slice').height('306px');                
                $('#map').addClass('withBorder');
                $('#map_information').slideDown('slow');
            });
        });
    }
}