
    google.load("maps", "2.x");

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	var newpoints = new Array();
	var CENTER_OFFSET = 1.7;
	//Marker Locations
	newpoints[0] = new Array(54.820656, -6.726849, 'Tobermore', '2 Lisnamuck Road, Tobermore', 'County Lderry, BT45 5QF', '028 7964 2411', '028 7964 4145', 'sales@tobermore.co.uk', '8.00 - 5.30 Mon - Fri', '8.00 - 1.00 Sat', 'siteFiles/images/tobermore_centre.jpg', 'Wed 8am to 8.30pm');
	newpoints[1] = new Array(54.647601, -5.724746, 'Bangor', '79 Cootehall Road, Bangor', 'County Down BT19 1UP', '028 9185 2545', '028 9185 2596', 'bangoroffice@tobermore.co.uk', '9.00 - 5.00 Mon - Sat', '', 'siteFiles/images/bangor_centre.jpg', 'Sorry, not available');
	newpoints[2] = new Array(53.505462, -6.194127, 'Dublin', 'Blakescross, Lusk', 'County Dublin', '01 8437440', '01 8437750', 'dublinoffice@tobermore.ie', '9.00 - 5.30 Mon - Sat', '', 'siteFiles/images/dublin_centre.jpg', 'Sorry, not available');
	newpoints[3] = new Array(51.746974, -8.723631, 'Cork', 'Mill Road, Irishtown Cross', 'Bandon, County Cork', '023 8843046', '023 8843047', 'cork@tobermore.ie', '9.00 - 5.30 Mon - Sat', '', 'siteFiles/images/cork_centre.jpg', 'Sorry, not available');
	newpoints[4] = new Array(53.692504, -2.675017, 'Leyland', 'Avant Garden Centre, Wigan Road, Leyland', 'Lancashire PR25 5XW', '01772 458923', '01772 452698', 'leylandoffice@tobermore.co.uk', '9.00 - 5.00 Mon - Fri', '', 'siteFiles/images/leyland_centre.jpg', 'Sorry, not available');
	
    function initialize(dirIndex) {
  
        if (GBrowserIsCompatible()) {
            //map = new GMap2($("#map").get(0));
	    var qs = window.location.search.substring(1);
            map = new GMap2(document.getElementById("map"));
            
            var icon0;
            //var TobermoreLoc = new GLatLng(54.820656, -6.726849);
            //map.setCenter(TobermoreLoc, 7);
            gdir = new GDirections(map);
            GEvent.addListener(gdir, "load", onGDirectionsLoad);
            GEvent.addListener(gdir, "error", handleErrors);
			if(qs=='tobermore'){
				var TobermoreLoc = new GLatLng(54.820656 + CENTER_OFFSET, -6.726849);
				map.setCenter(TobermoreLoc, 7);
				showInfoWindow(0);
			}else if(qs=='bangor'){
				var TobermoreLoc = new GLatLng(54.647601 + CENTER_OFFSET, -5.724746);
				map.setCenter(TobermoreLoc, 7);
				showInfoWindow(1);
			}else if(qs=='dublin'){
				var TobermoreLoc = new GLatLng(53.505462 + CENTER_OFFSET, -6.194127);
				map.setCenter(TobermoreLoc, 7);
				showInfoWindow(2);
			}else if(qs=='galway'){
				var TobermoreLoc = new GLatLng(53.30931 + CENTER_OFFSET, -9.128378);
				map.setCenter(TobermoreLoc, 7);
				showInfoWindow(3);
			}else if(qs=='cork'){
				var TobermoreLoc = new GLatLng(51.746974 + CENTER_OFFSET, -8.723631);
				map.setCenter(TobermoreLoc, 7);
				showInfoWindow(4);
			}else if(qs=='leyland'){
				var TobermoreLoc = new GLatLng(53.692504 + CENTER_OFFSET, -2.675017);
				map.setCenter(TobermoreLoc, 7);
				showInfoWindow(5);
			}else{
				var TobermoreLoc = new GLatLng(54.820656, -6.726849);
				map.setCenter(TobermoreLoc, 7);
			};
			
			//showInfoWindow(0);
			
            icon0 = new GIcon();
            icon0.image = "http://www.tobermore.co.uk/siteFiles/images/icons/TOBERMORE-MARKER.png";
            icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
            icon0.iconSize = new GSize(26, 31);
            icon0.shadowSize = new GSize(37, 34);
            icon0.iconAnchor = new GPoint(9, 34);
            icon0.infoWindowAnchor = new GPoint(9, 2);
            icon0.infoShadowAnchor = new GPoint(18, 25);

            var markers = [];
            for (var i = 0; i < newpoints.length; i++) {
                var point = new GPoint(newpoints[i][1], newpoints[i][0]);
                marker = new GMarker(point, icon0);
                map.addOverlay(marker);
                markers[i] = marker;
            }
			$(markers).each(function(i,marker){
			 GEvent.addListener(marker, "click", function(){
			 	var moveEnd = GEvent.addListener(map, "moveend", function(){
        			var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());
					showInfoWindow(i);
        			GEvent.removeListener(moveEnd);
					});
				map.panTo(new GLatLng(newpoints[i][0] + CENTER_OFFSET,newpoints[i][1]));
				});
			});
			
        }
    
    }

    function weetest(a, b, c){
		window.alert(a +" - "+ b +" - "+ c);
		map.panTo(getLatLng(a,b));
	};
	
	function getDirections(dirIndex){
		var fromValue = document.getElementById('toAddress').value;
		gdir.load("from: "+newpoints[dirIndex][0]+", "+newpoints[dirIndex][1]+" to: " + fromValue, { "locale": "en" });
	}
	
    function handleErrors() {
        if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
            //alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
            alert("No corresponding geographic location could be found for one of the specified addresses. Please try adding further information to narrow the search, e.g. 'Limerick, Ireland' rather than 'Limerick'\nError code: " + gdir.getStatus().code);
        else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
            alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);

        else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
            alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

        else if (gdir.getStatus().code == G_GEO_BAD_KEY)
            alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

        else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
            alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);

        else alert("An unknown error occurred.");
    }

	function showInfoWindow(i){
		if(newpoints[i][9]!=''){
			var comma = ", ";
		} else {
			var comma = "";
		}
		var info =  "<div class='locMenu'><img src='" + newpoints[i][10] + "' width='253' height='119' />" +
					"<h2>"+newpoints[i][2]+"</h2>" +
					"<p>"+newpoints[i][3]+", " + newpoints[i][4]+"</p>" +
					"<p><strong>Phone:</strong> "+newpoints[i][5]+"  <strong>Fax:</strong> "+newpoints[i][6]+"</p>" +
					"<p><strong>Email:</strong> <a href='mailto:"+newpoints[i][7]+"'>"+newpoints[i][7]+"</a></p>" +
					"<p><strong>Opening Hours:</strong> "+newpoints[i][8]+""+comma+""+newpoints[i][9]+"</p>" +
					"<p><strong>Late Night Opening Hours (Apr - Aug): </strong> "+newpoints[i][11]+"</p>" +
					"<input type='text' size='25' id='toAddress' name='to' value='your town' class='locBox' />"+
					"<input id='submit1' name='submit1' type='submit' value='Get Directions!' onclick='getDirections("+i+");' />"+
					"</div>";
					
		//map.openInfoWindowHtml(map.getCenter(),info);
		map.openInfoWindowHtml(new GLatLng(newpoints[i][0], newpoints[i][1]),info);
		};
	
    function animate(thelat, thelng, i) {
		
		var moveEnd = GEvent.addListener(map, "moveend", function(){
			showInfoWindow(i);
			GEvent.removeListener(moveEnd);
			});
		map.panTo(new GLatLng(thelat + CENTER_OFFSET, thelng));
    }

    function onGDirectionsLoad() {
        // nothing
    }


