    var map = null;
    var BaseShapeLayer = null;
    var mapCenter = new VELatLong(53.970760650677456, -1.300620117187513);
    var mapZoom = 8;
    var PostcodeLocations = new Array();
    var LongLatLocations = new Array();
    var CurrentLocation = 0;
    var CurrentShape = null;
    var PinCenter = null;
    var Timer = null;
    
	$(document).ready(function(){
			LoadMap();
			LoadLocations();
	});
    
    function LoadMap()
    {
        map = new VEMap('ClientMapMap');
        map.LoadMap(mapCenter, mapZoom);        
        BaseShapeLayer = new VEShapeLayer();
        map.AddShapeLayer(BaseShapeLayer);
    }

    function AddLocationFromPostcode(index, title, description, id, postcode)
    {
        description = stripslashes(description);
        if(postcode != null && postcode != undefined)
        {
            PostcodeLocations[index] = new Array(title, description, id, postcode);
        }
    }

    function AddLocationFromLongLat(index, title, description, id, longitude, latitude,fodderIcon)
    {
        description = stripslashes(description);
        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/MapIcon.png" />');
            }
            else
            {
                pin.SetCustomIcon('<img src="/images/presentation/MapIcon.png" />');
            }
            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);
            LongLatLocations[i] = pin.GetID();
        }
    }
    
    
     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/MapIcon.png" />');
            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);
            alert(PostcodeLocations[CurrentLocation][2]);
            var path = '/plugins/ClientMap/ClientMapAjax.php?savelocation=true&dsid=4&id='+PostcodeLocations[CurrentLocation][2]+'&long='+places[0].LatLong.Longitude+'&lat='+places[0].LatLong.Latitude;
            var AjaxLoader = new Ajax(null, path);
            
            CurrentLocation ++;
        }
        else if(resultsArray == null)
        {
            PostcodeLocations[CurrentLocation] = null;
            CurrentLocation ++;
        }
        
        if(CurrentLocation < PostcodeLocations.length)
        {
            LoadLocation();
        }
     }    
    
    function HighlightPostcodeMapLocation(markerId)
    {
        var id = PostcodeLocations[markerId];
        if(id != null)
        {
            CurrentShape = BaseShapeLayer.GetShapeByIndex(markerId);
            map.ShowInfoBox(CurrentShape);
        }
    }

    function HidePostcodeMapLocation(markerId)
    {
        var id = PostcodeLocations[markerId];
        if(id != null)
        {
            CurrentShape = BaseShapeLayer.GetShapeByIndex(markerId);
            map.HideInfoBox(CurrentShape);
        }
    }

    function HighlightLongLatMapLocation(markerId)
    {
        var id = LongLatLocations[markerId];
        if(id != null)
        {
            CurrentShape = BaseShapeLayer.GetShapeByIndex(markerId);
            map.ShowInfoBox(CurrentShape);   
        }
    }

    function HideLongLatMapLocation(markerId){
        var id = LongLatLocations[markerId];
        if(id != null)
        {
            CurrentShape = BaseShapeLayer.GetShapeByIndex(markerId);
            map.HideInfoBox(CurrentShape);
        }
    }

    function addslashes(str) 
    {
        str=str.replace(/\\/g,'\\\\');
        str=str.replace(/\'/g,'\\\'');
        str=str.replace(/\"/g,'\\"');
        str=str.replace(/\0/g,'\\0');
        return str;
    }
    function stripslashes(str) 
    {
        str=str.replace(/\\'/g,'\'');
        str=str.replace(/\\"/g,'"');
        str=str.replace(/\\0/g,'\0');
        str=str.replace(/\\\\/g,'\\');
        return str;
    }

/* END - CALLED DIRECTLY FROM MAP APP */
