
$(document).ready(function () {
    document.body.className += "hasJs";


    // Find out what page you are on and remove the relevant anchor tag in the nav 
    var url = window.location.href;


    var indexPage = url.indexOf("index", 0);
    var recipePage = url.indexOf("recipe", 0);
    var eventsPage = url.indexOf("events", 0);
    var historyPage = url.indexOf("past-and-present", 0);
    if (indexPage > 0) {
        //$("#header ul.nav li.nav1 a, #header ul.nav li.nav1 span").remove();
        // The link is removed in the back end code
    }
    else if (recipePage > 0) {
        $("#header ul.nav li.nav2 a, #header ul.nav li.nav2 span").remove();
    }
    else if (eventsPage > 0) {
        $("#header ul.nav li.nav3 a, #header ul.nav li.nav3 span").remove();
    }
    else if (historyPage > 0) {
        $("#header ul.nav li.nav4 a, #header ul.nav li.nav4 span").remove();
    }
    
    
    // Check if you are NOT on the History Page
    var historyPage = $(".historyPage").length;
    if (historyPage != 1) {
        //  hide the background to the LI in the Nav for history
        $("#header li.nav4").css({'background-image':'url("../images/Transparent.png")'});
    }
    


    // Check if you are on the Recipes Page
    var recipePage = $("#recipesPage").length;
    if (recipePage == 1) {
        // To every second HR add the class "alt"
        $("#recipesPage>div.hr:odd").addClass("alt");

        // Remove last div which holds a HR - dotted line with scissors
        //$("#recipesPage div.hr").last().remove();
        $("#recipesPage div.hr:last").remove();
    }
    
    // Preload graphics function
    (function($) {
      var cache = [];
      // Arguments are image paths relative to the current page.
      $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
          var cacheImage = document.createElement('img');
          cacheImage.src = arguments[i];
          cache.push(cacheImage);
        }
      }
    })(jQuery)
    
    function clearMapPopup()
    {
        $('img.map').attr('src','../images/maps/uk-none.png');
        $("p#mapMessageBox").hide();
    }
    
    // Check if you are on the Events Page
    var eventsPage = $(".eventsPage").length;
    if (eventsPage == 1) {
        
        // Preload maps
        jQuery.preLoadImages("../images/maps/uk-none.png", "../images/maps/scotland.png", 
"../images/maps/north-west.png", "../images/maps/north-east.png", "../images/maps/yorkshire.png",
"../images/maps/wales.png",
"../images/maps/lincolnshire.png", "../images/maps/west-midlands.png", "../images/maps/east-midlands.png", 
"../images/maps/east.png", "../images/maps/south-west.png", "../images/maps/south.png", 
"../images/maps/surrey.png", "../images/maps/london.png", "../images/maps/kent.png");
        
        // Hide all regions
        //$(".eventsPage .events").hide();
        
        // Hide big red down arrow
        $(".eventsPage .arrowEvents").hide();
        
        // Await clicks on map
        $(".eventsPage #ukMap area").click(function() {
            
            // Hide previous region
            $(".eventsPage .events").hide(); 
            
            // Determine which region has been clicked
            var region = $(this).attr('href');
            
            //alert('region=' + region);
            
            // Show region list
            $(region).show(); 
            
            // Remove Hash #
            region=region.substring(1);
            
            // Replace dash with space
            region=region.replace("-"," ");
            // Update text in big arrow and display
            $(".eventsPage .arrowEvents h2").html(region+"<br />Events");
            $(".eventsPage .arrowEvents").show();
            
            
            return false;
        });
        
        var messageHTML="EVENTS</span> near you -<br />click and take a look below.";
        var eventsNum="0";
        
        $('#ScotlandA').hover(
            function() {
                $('img.map').attr('src','../images/maps/scotland.png');
                eventsNum="<span>1&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'345px','top':'272px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#NorthWestA').hover(
            function() {
                $('img.map').attr('src','../images/maps/north-west.png');
                eventsNum="<span>14&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'426px','top':'349px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#NorthEastA').hover(
            function() {
                $('img.map').attr('src','../images/maps/north-east.png');
                eventsNum="<span>3&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'430px','top':'302px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#YorkshireA').hover(
            function() {
                $('img.map').attr('src','../images/maps/yorkshire.png');
                eventsNum="<span>14&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'466px','top':'339px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#WalesA').hover(
            function() {
                $('img.map').attr('src','../images/maps/wales.png');
                eventsNum="<span>2&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'444px','top':'239px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#LincolnshireA').hover(
            function() {
                $('img.map').attr('src','../images/maps/lincolnshire.png');
                eventsNum="<span>6&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'502px','top':'383px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#West-MidlandsA').hover(
            function() {
                $('img.map').attr('src','../images/maps/west-midlands.png');
                eventsNum="<span>5&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'416px','top':'412px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#East-MidlandsA').hover(
            function() {
                $('img.map').attr('src','../images/maps/east-midlands.png');
                eventsNum="<span>20&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'458px','top':'394px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#EastA').hover(
            function() {
                $('img.map').attr('src','../images/maps/east.png');
                eventsNum="<span>7&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'417px','top':'268px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#SouthWestA').hover(
            function() {
                $('img.map').attr('src','../images/maps/south-west.png');
                eventsNum="<span>1&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'413px','top':'318px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#SouthA').hover(
            function() {
                $('img.map').attr('src','../images/maps/south.png');
                eventsNum="<span>19&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'362px','top':'323px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#SurreyA').hover(
            function() {
                $('img.map').attr('src','../images/maps/surrey.png');
                eventsNum="<span>15&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'392px','top':'303px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
        
        $('#LondonA').hover(
            function() {
                $('img.map').attr('src','../images/maps/london.png');
                eventsNum="<span>10&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'418px','top':'288px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });

        $('#KentA').hover(
            function() {
                $('img.map').attr('src','../images/maps/kent.png');
                eventsNum="<span>14&nbsp;";
                messageHTMLCombo=eventsNum+messageHTML;
                $("p#mapMessageBox").html(messageHTMLCombo);
                $("p#mapMessageBox").css({'left':'442px','top':'319px'});
                $("p#mapMessageBox").show();
            },
            function() {
                clearMapPopup();
        });
    }


});

