    var map = null;
    var BaseShapeLayer = null;
    var mapCenter = new VELatLong(53.808760650677456, -1.510620117187513);
    var mapZoom = 8;
    var PostcodeLocations = new Array();
    var LongLatLocations = new Array();
    var CurrentLocation = 0;
    var CurrentShape = null;
    var PinCenter = null;
    var Timer = null;
    
    function LoadMap()
    {
        map = new VEMap('FindFodderMap');
        map.LoadMap(mapCenter, mapZoom);        
        BaseShapeLayer = new VEShapeLayer();
        map.AddShapeLayer(BaseShapeLayer);
    }

    function AddLocationFromPostcode(index, title, description, id, postcode)
    {
        if(postcode != null && postcode != undefined)
        {
            PostcodeLocations[index] = new Array(title, description, id, postcode);
        }
    }

    function AddLocationFromLongLat(index, title, description, id, longitude, latitude,fodderIcon)
    {
        LongLatLocations[index] = new Array(title, description, id, longitude, latitude,fodderIcon);
    }
    
    function LoadLocation()
    {
        if(PostcodeLocations.length > 0)
        {
            results = map.Find('',
                PostcodeLocations[CurrentLocation][3],
                null,
                null,
                null,
                null,
                true,
                true,
                true,
                true,
                AddPostcodePin);
        }
    }
    
    function LoadLongLatLocations()
    {
        for(var i = 0; i < LongLatLocations.length; i ++)
        {
            var tmpLong = parseFloat(LongLatLocations[i][3]);
            var tmpLat = parseFloat(LongLatLocations[i][4]);
            var LL = new VELatLong(tmpLat,tmpLong);
            var pin = new VEShape(VEShapeType.Pushpin, LL);
            if(LongLatLocations[i][5])
            {
                pin.SetCustomIcon('<img src="/images/presentation/FodderMapIcon.gif" />');
            }
            else
            {
                pin.SetCustomIcon('<img src="/images/presentation/MapPin.gif" />');
            }
            pin.SetTitle('<h4 class="mapTitle">'+LongLatLocations[i][0]+'</h4>');
            pin.SetDescription('<div class="mapInfoBox">'+LongLatLocations[i][1]+'<div class="clear">&nbsp;</div></div>');
            BaseShapeLayer.AddShape(pin);
        }
    }
    
    
     function AddPostcodePin(layer, resultsArray, places, hasMore, veErrorMessage)
     {
         if(places != null)
         {
            var pin = new VEShape(VEShapeType.Pushpin, places[0].LatLong);
            pin.SetCustomIcon('<img src="/images/presentation/FodderMapIcon.gif" />');
            pin.SetTitle('<h4 class="mapTitle">'+PostcodeLocations[CurrentLocation][0]+'</h4>');
            pin.SetDescription('<div class="mapInfoBox">'+PostcodeLocations[CurrentLocation][1]+'<div class="clear">&nbsp;</div></div>');
            BaseShapeLayer.AddShape(pin);
            
            var path = '/plugins/FindFodder/FindFodderAjax.php?savelocation=true&dsid=12&id='+PostcodeLocations[CurrentLocation][2]+'&long='+places[0].LatLong.Longitude+'&lat='+places[0].LatLong.Latitude;
            var AjaxLoader = new Ajax(null, path);
            CurrentLocation ++;
        }
        if(CurrentLocation < PostcodeLocations.length)
        {
            LoadLocation();
        }
     }    
    
    function HighlightMapLocation(markerId){
        //Update pushpin
        CurrentShape = BaseShapeLayer.GetShapeByIndex(markerId);
        // PinCenter = new VELatLong(CurrentShape.Latitude, CurrentShape.Longitude);
        // map.AttachEvent("onendpan", ShowInfo);
        // map.SetCenter(PinCenter);
        map.ShowInfoBox(CurrentShape);    
    }
        
    function ShowInfo()
    {
        if(CurrentShape != null)
        {
            map.ShowInfoBox(CurrentShape);  
        }
    }

    function HideMapLocation(markerId){
        //Update pushpin
        CurrentShape = BaseShapeLayer.GetShapeByIndex(markerId);
        map.HideInfoBox(CurrentShape);
    }


    

/* END - CALLED DIRECTLY FROM MAP APP */

/* BEGIN - UTILS */
    function AddLoadEvent(func) 
    {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') 
      {
        window.onload = func;
      } 
      else
      {
        window.onload = function()
        {
          if (oldonload) 
          {
            oldonload();
          }
          func();
        }
      }
    }
/* END - UTILS */