// Runs when the DOM has been loaded
$(document).ready(function() {
    // Check if map exists
    if ($('#map-hover')) {
        // Loop through each AREA in the imagemap
        $('#map-hover area').each(function() {

            // Assigning an action to the mouseover event
            $(this).mouseover(function(e) {
                var branch_id = $(this).attr('id').replace('area_', '');
                $('#image-Newport').hide();
                $('#image-Freshwater').hide();
                $('#image-EastCowes').hide();
                $('#image-Ryde').hide();
                $('#image-Shanklin').hide();
                $('#panel-Newport').hide();
                $('#panel-Freshwater').hide();
                $('#panel-EastCowes').hide();
                $('#panel-Ryde').hide();
                $('#panel-Shanklin').hide();
                $('#image-' + branch_id).show();
                $('#panel-' + branch_id).show();
            });

            // Assigning an action to the mouseout event
            $(this).mouseout(function(e) {
            var branch_id = $(this).attr('id').replace('area_', '');
                //$('#image-' + branch_id).hide();
                //$('#panel-' + branch_id).hide();
            });

            // Assigning an action to the click event
            $(this).click(function(e) {
                e.preventDefault();
                var branch_id = $(this).attr('id').replace('area_', '');
                //alert('You clicked ' + branch_id);
                $('#image-Newport').hide();
                $('#image-Freshwater').hide();
                $('#image-EastCowes').hide();
                $('#image-Ryde').hide();
                $('#image-Shanklin').hide();
                $('#panel-Newport').hide();
                $('#panel-Freshwater').hide();
                $('#panel-EastCowes').hide();
                $('#panel-Ryde').hide();
                $('#panel-Shanklin').hide();
                $('#image-' + branch_id).show();
                $('#panel-' + branch_id).show();
            });

        });
    }
});
