
    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.602225, -5.908593, 'Belfast Office');
	newpoints[1] = new Array(51.501264, -0.097473, 'London Office');
	
    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(53.29698, -6.13237);
            //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.602225, -5.908593);
				map.setCenter(TobermoreLoc, 6);
				showInfoWindow(0);
			}else if(qs=='bangor'){
				var TobermoreLoc = new GLatLng(51.501264, -0.097473);
				map.setCenter(TobermoreLoc, 6);
				showInfoWindow(1);
			}else{
				var TobermoreLoc = new GLatLng(54.820656, -6.726849);
				map.setCenter(TobermoreLoc, 6);
			};*/
			map.setCenter(TobermoreLoc, 6);
			//showInfoWindow(0);
			
            icon0 = new GIcon();
            icon0.image = "http://www.beingonline.co.uk/siteFiles/images/being.png";
            icon0.shadow = "http://www.google.com/mapfiles/shadow50.png";
            icon0.iconSize = new GSize(60, 53);
            icon0.shadowSize = new GSize(37, 34);
            icon0.iconAnchor = new GPoint(57, 53);
            icon0.infoWindowAnchor = new GPoint(30, 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());
					//var info = new Infowin((new GLatLng(newpoints[i][0], newpoints[i][1])), newpoints[i][3]);
					//map.addOverlay(info);
					//showInfoWindow(i);
					//$("#message")
						//.fadeIn()
						//.css({ top:markerOffset.y, left:markerOffset.x });
        			GEvent.removeListener(moveEnd);
					});
				map.panTo(new GLatLng(newpoints[i][0],newpoints[i][1]));
				map.setCenter(new GLatLng(newpoints[i][0],newpoints[i][1]), 16);
				});
			});
			
        }
    
    }

    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);
        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'>" +
					"<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(){
			 var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());	
			//showInfoWindow(i);
			GEvent.removeListener(moveEnd);
			});
		map.panTo(new GLatLng(thelat, thelng));
		map.setCenter(new GLatLng(thelat, thelng), 16);
    }

    function onGDirectionsLoad() {
        // nothing
    }

	function Infowin(latlng, html) {
        this.latlng_ = latlng;
        this.html_ = html;
        this.prototype = new GOverlay();
 
        // Creates the DIV representing the infowindow
        this.initialize = function(map) {
                var div = $('<div />');
                div.css({
                        position : 'absolute',
                        width : 234
                }).appendTo(map.getPane(G_MAP_FLOAT_PANE))
 
                this.map_ = map;
                this.div_ = div;
 
                this.update(html);
        }
 
        this.update = function(html){
                this.html_ = html;
 
                this.div_.empty();
 
                $('<div />').css({
                        'background-image' : 'url(http://www.beingonline.co.uk/siteFiles/images/bubbletop.png)',
                        height : 14,
                        padding: '0 0 0 0'
                }).appendTo(this.div_);
 
                var content = $('<div />').addClass('infowin-content').css({
                        'position' : 'relative',
                        'overflow' : 'hidden',
                        'max-height' : 100,
                        'top' : -5
                }).html(html);
 
                $('<div />').css({
                        'background-image' : 'url(http://www.beingonline.co.uk/siteFiles/images/bubblebottom.png)',
                        'background-position' : 'bottom left',
                        'padding' : '0 10px 30px 10px'
                }).append(content).appendTo(this.div_);
 
                this.redraw(true);
        }
 
        // Remove the main DIV from the map pane
        this.remove = function() {
          this.div_.remove();
        }
 
        // Copy our data to a new instance
        this.copy = function() {
          return new Infowin(this.latlng_, this.html_);
        }
 
        // Redraw based on the current projection and zoom level
        this.redraw = function(force) {
                if (!force) return;
 
                var point = this.map_.fromLatLngToDivPixel(this.latlng_);
 
                // Now position our DIV based on the DIV coordinates of our bounds
                this.div_.css({
                        left : point.x - 119,
                        top : point.y - this.div_.height() - 42
                });
        }
	}
