    //Global vars
    
    //cufon vars
    var fontReplace = ('h1', 'h1:not(.profile)');
    
    //vars for main menu
    //uncomment the below var to reintialise 
    //the primary nav hover for the sub menu
    //var nav = ('#primarynav');
    var nav = '';
    var timeout = 800;
    var closetimer = 800;
    var menuItem = 0;
    var menuItemActive = 0;
    
    //vars for mini menu
    var miniNav = ('#home_mini_nav ul');
    
    //vars for resevervations menu
    var resMenuItem = 0;
    var resMenu = ('.reservations_panel nav ul');
    
    //vars for pagination
    var pagination = ('.pagination');
    
    //vars for carousel
    var carousel = ('.carousel_items');
    
    //columnize vars
    var columnNize = ('.columns');
    var columnNizeCols = 2;
    var columnNizeWidth = 310;
    
    //vertical alignment vars
    var valign_cont = '.mini_prevs';
    var valign_elem = valign_cont + ('span');
    var valign_padd = '';
    
    //add this vars and config
    var addthis_config = {
      ui_click: true    
    }
    
    
    $(document).ready(function()    {
        //cufon config
        //Cufon.replace(fontReplace);
        
        //start the mini nav menus
        initMenu();
        
        //main navigation config
        $(nav + '> li').bind('mouseover', navMenu_open);
        $(nav + '> li').bind('mouseout',  navMenu_closeTimer);
        
        //reservations dropdown
        $(resMenu + '> li').bind('mouseover', navMenu_open);
        $(resMenu + '> li').bind('mouseout', navMenu_close);
        
        //pagination center align config
        if($(pagination).length)    {
            var pagiUL = $(pagination + '> ul');
                pagiWidth = $(pagination).children('ul').width();
                pagiUL.width(pagiWidth).css('display','block');
        }
        
        //carousel config
        $(carousel).cycle({
            fx: 'fade',
            speed: 2000,
            timeout: 6000,
            cleartype: 1,
            activePagerClass: 'active',
            pager: '.carousel_nav',
            pagerAnchorBuilder: function(idx, slide) {
                return '.carousel_nav a:eq(' + idx + ')';
            },
            fastOnEvent: 300,
            manualTrump: true,
            onPagerEvent: function(zeroBasedSlideIndex, slideElement) {
                $(carousel).cycle('pause');
            },
            pause: 1
        });
        
        //columnize config
        $(columnNize).columnize({
            columns: columnNizeCols,
            width: columnNizeWidth
        });
        
        //vertical alignment
        
        if($('.mini_prevs').length) {
            var container = $('.mini_prevs').children('div');
                container.each(function()   {
                    var parentHeight = $(this).children('hgroup').height();
                    var h3s = $(this).find('h3');
                    var actualHeight = h3s.height();
                    var calcPad = Math.ceil((parentHeight - actualHeight) / 2);
                    h3s.css('padding-top', calcPad);
                    h3s.fadeIn('slow');
                });
        }
        
        function load_map(){
            var def_location = new google.maps.LatLng(51.508528775862885, -0.10454177856445312);
            this.map = new google.maps.Map(this, {
                zoom: 15,
                center: def_location,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            });
            this.marker = new google.maps.Marker({
                map: this.map,
                draggable: false
            });
        }
        
        function set_location(event, latitude, longitude) {
            if(!latitude) {
                latitude = $(this).attr('data-latitude');
            }
            if(!longitude) {
                longitude = $(this).attr('data-longitude');
            }
            var location = new google.maps.LatLng(latitude, longitude);
            this.marker.setPosition(location);
            this.map.setCenter(location);
        }
        
        var bakery_maps = $('.bakery_location_map');
        bakery_maps.each(function(){
            $(this).bind('load-map', load_map);
            $(this).bind('set-location', set_location);
        });
        bakery_maps.trigger('load-map')
                   .trigger('set-location');
                   
        var venue_maps = $('.venue_location_map');
        venue_maps.each(function(){
            $(this).bind('load-map', load_map);
            $(this).bind('set-location', set_location);
        });
        venue_maps.trigger('load-map')
                   .trigger('set-location');
      
        var restaurant_maps = $('.restaurant_location_map');
        
        restaurant_maps.each(function(){
            $(this).bind('load-map', load_map);
            $(this).bind('set-location', set_location);
            $(this).bind('show-info', function(event, info){
                if(!info) {
                    var restaurant = $.parseJSON($(this).attr('data-restaurant'));
                    info  = '<div class="restaurant_loc_bubble"><strong>' + restaurant.name + "</strong>";
                    info += '<div class="address">' + restaurant.address.replace(/\n/g,'<br />') + "<br/>" + restaurant.postcode + "</div>";
                    info += '<div class="phone">' + restaurant.phone + "</div>";
                    info += "</div>"
                }
                var info_pane = new google.maps.InfoWindow({
                    content: info,
                    disableAutoPan: false,
                    maxWidth: '300px'
                });
                info_pane.open(this.map, this.marker);
            });
        });
        restaurant_maps.trigger('load-map')
                       .trigger('set-location')
                       .trigger('show-info');
                       
                       
        /**
         * Code to show and hide the placeholder text in fields when the user
         * clicks on the field.
         * 
         * The data stored against the element is later used by the validator.
         */
        $('input[type="text"], textarea').each(function(){
            $(this).data('placeholder', null);
            $(this).focus(function(){
                if(null === $(this).data('placeholder')) {
                    $(this).data('placeholder', $(this).val());
                }
                if($(this).data('placeholder') == $(this).val()) {
                    $(this).val('');
                }
            });
            $(this).blur(function(){
                if('' == $(this).val()) {
                    $(this).val($(this).data('placeholder'));
                }
            });
        });
    });
    
    // *** Global Function ***
    
    //Navigation
    //handles the opening of the sub nav
    function navMenu_open()  {
        navMenu_cancelTimer();
        navMenu_close();
        
        menuItemActive = $(this).find('ul.active');
        menuItem = $(this).find('ul').css('display', 'block');
    }

    //handles menu closing
    //if the sub menu is visible while hovering something
    //else it hide the it hides the sub menu
    function navMenu_close()  {
        if(menuItem) menuItem.css('display', 'none');
        navMenu_current();
    }

    //handles the menu closing if the menu
    //is currently not being hovered on and 
    //closes after the timeout
    function navMenu_closeTimer()   {
        closetimer = setTimeout(navMenu_close, timeout);
    }
    
    //handles the menu closing
    function navMenu_cancelTimer()  {
        if(closetimer) {  
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }
    
    //always makesure the active ul is displayed
    //even when we mouseover the page
    function navMenu_current()  {
        if(menuItemActive) menuItemActive.css('display', 'block');
    }

    //handles the mini tab opening/closing
     function initMenu() {
         $('#dynamic-mini-tabs ul li ul').hide();
         $('#dynamic-mini-tabs ul li ul li ul').show();
         $('#dynamic-mini-tabs ul li ul:first').toggleClass('active').show();
         $('#dynamic-mini-tabs ul li a:first').toggleClass('active');
         $('#dynamic-mini-tabs li > a.navitem').click(function() {
                 var checkElement = $(this).next();

                 $('#dynamic-mini-tabs ul li a').removeClass('active');                 

                 $(this).addClass('active');

                 if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                    return false;
                 }
                 
                 if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                     $('#dynamic-mini-tabs ul li ul').hide();
                     checkElement.fadeIn('fast');
                 return false;
                 }
             }
        );
     }
