var mapLoad = {
  init: function() {
		if (!document.getElementById) return;
		//mapid = document.getElementById('map');
    var map = new GMap(document.getElementById('map'));

    // Create small red marker icon
    var iconsm = new GIcon();
    iconsm.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
    iconsm.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    iconsm.iconSize = new GSize(12, 25);
    iconsm.shadowSize = new GSize(22, 25);
    iconsm.iconAnchor = new GPoint(6, 25);
    iconsm.infoWindowAnchor = new GPoint(5, 1);

    // Create big marker icon
    var iconbig = new GIcon();
    iconbig.image = "http://www.google.com/mapfiles/marker.png";
    iconbig.shadow = "http://www.google.com/mapfiles/shadow50.png";
    iconbig.iconSize = new GSize(20, 34);
    iconbig.shadowSize = new GSize(37, 34);
    iconbig.iconAnchor = new GPoint(6, 34);
    iconbig.infoWindowAnchor = new GPoint(5, 1);

    // Map type: map, satellite, hybrid
    map.setMapType(map.getMapTypes()[0]);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
		
      	  
    // Add locations
    var skylane = new GPoint(-0.163465, 51.186135);
		var weston = new GPoint(0.266247, 51.872331);
		var oldstreet = new GPoint(-0.096569, 51.526347);
		var ashford = new GPoint(0.89766, 51.166761);
		var marwell = new GPoint(-1.286173, 50.990556);
		var birch = new GPoint(-2.221051, 53.572351);
		
    // Center the map to the default location  //
		var page = new String(window.location);
		if (page.match(/skylane/)) {
		  map.centerAndZoom(new GPoint(-0.163465, 51.150000), 3);// 51.186135), 2);
      var skyInfoTabs = [
        new GInfoWindowTab("Skylane Hotel", "Bonehurst Road<br>Gatwick</br>Horley<br>Surrey<br>RH6 8QG"),
        new GInfoWindowTab("Phone", "01293 786971")
      ];
// Place a marker in the center of the map and open the info window
// automatically
      var skymarker = new GMarker(skylane);
      GEvent.addListener(skymarker, "click", function() {
        skymarker.openInfoWindowTabsHtml(skyInfoTabs);
      });
      map.addOverlay(skymarker);
      skymarker.openInfoWindowTabsHtml(skyInfoTabs);
		}
		else if (page.match(/weston/)) {
		  map.centerAndZoom(new GPoint(0.275216,51.750000), 3);//(0.266247, 51.872331), 3);http://maps.google.co.uk/maps?q=CM22+6PU&ie=UTF8&ll=51.880783,0.268178&spn=0.019074,0.057335&z=15
      var westInfoTabs = [
        new GInfoWindowTab("Weston Business Centre", "Parsonage Road<br>Takeley<br>Essex<br>CM22 6PU"),
        new GInfoWindowTab("Phone", "01279 874100")
      ];
// Place a marker in the center of the map and open the info window
// automatically
      var westmarker = new GMarker(weston);
      GEvent.addListener(westmarker, "click", function() {
        westmarker.openInfoWindowTabsHtml(westInfoTabs);
      });
      map.addOverlay(westmarker);
      westmarker.openInfoWindowTabsHtml(westInfoTabs);
    }
		else if (page.match(/old-street/)) {
		  map.centerAndZoom(new GPoint(-0.092118, 51.524659), 3);
      var streetInfoTabs = [
        new GInfoWindowTab("St. Luke's", "90 Central Street<br>London<br>EC1V 8AA"),
        new GInfoWindowTab("Phone", "020 76081395")
      ];
// Place a marker in the center of the map and open the info window
// automatically
      var streetmarker = new GMarker(oldstreet);
      GEvent.addListener(streetmarker, "click", function() {
        streetmarker.openInfoWindowTabsHtml(streetInfoTabs);
      });
      map.addOverlay(streetmarker);
      streetmarker.openInfoWindowTabsHtml(streetInfoTabs);
		}
		else if (page.match(/ashford/)) {
		  map.centerAndZoom(ashford, 3);
      var croftInfoTabs = [
        new GInfoWindowTab("The Croft", "Canterbury Road<br>Kennington<br>Kent<br>TN25 4DU"),
        new GInfoWindowTab("Phone", "01233 622140")
      ];
// Place a marker in the center of the map and open the info window
// automatically
      var croftmarker = new GMarker(ashford);
      GEvent.addListener(croftmarker, "click", function() {
        croftmarker.openInfoWindowTabsHtml(croftInfoTabs);
      });
      map.addOverlay(croftmarker);
      croftmarker.openInfoWindowTabsHtml(croftInfoTabs);
    }
		else if (page.match(/marwell/)) {
		  map.centerAndZoom(marwell, 3);
      var marwellInfoTabs = [
        new GInfoWindowTab("Marwell Hotel", "Thompsons Lane<br>Colden Common<br>Hampshire<br>SO21 1JY"),
        new GInfoWindowTab("Phone", "01962 777681")
      ];
// Place a marker in the center of the map and open the info window
// automatically
      var marwellmarker = new GMarker(marwell);
      GEvent.addListener(marwellmarker, "click", function() {
        marwellmarker.openInfoWindowTabsHtml(marwellInfoTabs);
      });
      map.addOverlay(marwellmarker);
      marwellmarker.openInfoWindowTabsHtml(marwellInfoTabs);
    }
		else if (page.match(/birch/)) {
		  map.centerAndZoom(birch, 4);
      var birchInfoTabs = [
        new GInfoWindowTab("Birch Hotel", "Manchester Road<br>Birch<br>Heywood<br>Manchester<br>OL10 2QD"),
        new GInfoWindowTab("Phone", "01706 360965")
      ];
// Place a marker in the center of the map and open the info window
// automatically
      var birchmarker = new GMarker(birch);
      GEvent.addListener(birchmarker, "click", function() {
        birchmarker.openInfoWindowTabsHtml(birchInfoTabs);
      });
      map.addOverlay(birchmarker);
      birchmarker.openInfoWindowTabsHtml(birchInfoTabs);
    }
  },
	
  addEvent: function(elm, evType, fn, useCapture) {
	  if (elm.addEventListener) {
		  elm.addEventListener(evType, fn, useCapture);
		  return true;
		} else if (elm.attchEvent) {
		  var r = elm.attachEvent('on' + evType, fn);
		  return r;
		} else {
		  elm['on' + evType] = fn;
		}
	}
}

mapLoad.addEvent(window, 'load', mapLoad.init, false);
