
  var ItinMap = {
    Render:function(){
      if (GBrowserIsCompatible()) {
        this.map = new google.maps.Map2(document.getElementById("gmap"));
        this.map.addMapType(G_HYBRID_MAP);
        this.map.enableDoubleClickZoom();
        this.map.setCenter(new google.maps.LatLng(28.304381, 14.765625), 2);
        this.map.setMapType(G_HYBRID_MAP);//calculate the boundaries
        ItinMap.map = this.map;
        ItinMap.BuildSlider("#slider");
        GEvent.addListener(ItinMap.map, "zoomend", function(){ItinMap.UpdateZoom()});
        ItinMap.UpdateZoom();
        ItinMap.mm = new MarkerManager(ItinMap.map, {borderPadding:1});
        ItinMap.countryicon = new GIcon();
        ItinMap.countryicon.image = "/sites/all/modules/map/images/markers/exodus-pin.png";
        ItinMap.countryicon.iconSize = new GSize(23, 40);
        ItinMap.countryicon.iconAnchor = new GPoint(16, 24);
        ItinMap.readMap();
      }
    },

    BuildSlider:function(slider_selector){
      if ($(slider_selector).length) {
        $(slider_selector).slider({
          min: 0, max: 13, value: 4, range: false,
          change: function(e,ui) {ItinMap.map.setZoom(1 + (ui.value));}
        });
     		//ItinMap.slider_height = $(slider_selector).css("height").replace("px","");
     		ItinMap.slider_width = $(slider_selector).css("width").replace("px","");
    		//ItinMap.marker_height = $("div.ui-slider-handle").css("height").replace("px","");
    		ItinMap.marker_width = $("div.ui-slider-handle").css("width").replace("px","");
    		ItinMap.available_slide = ItinMap.slider_width - ItinMap.marker_width;
    		ItinMap.pixelperstop = ItinMap.available_slide/14;
    		ItinMap.UpdateZoom();
    		$("a#zoom-in").click(function(){ return ItinMap.zoomIn(); });
    		$("a#zoom-out").click(function(){ return ItinMap.zoomOut(); });
    		$("a#up").click(function(){ return ItinMap.panUp(); });
    		$("a#down").click(function(){ return ItinMap.panDown(); });
    		$("a#left").click(function(){ return ItinMap.panLeft(); });
    		$("a#right").click(function(){ return ItinMap.panRight(); });
    		$("a#centre").click(function(){ return ItinMap.returnToSaved(); });
    	}
    },
 
    UpdateZoom:function(){
  		$("div.ui-slider-handle").css("left", (ItinMap.pixelperstop * (ItinMap.map.getZoom()-1)));
  	},
  	returnToSaved:function(){
  		ItinMap.map.returnToSavedPosition();
  		ItinMap.UpdateZoom();
  		return false;
  	},
  	panUp:function(){
  		ItinMap.map.panDirection(0, 1);
  		return false;
  	},
  	panDown:function(){
  		ItinMap.map.panDirection(0, -1);
  		return false;
  	},
  	panLeft:function(){
  		ItinMap.map.panDirection(1, 0);
  		return false;
  	},
  	panRight:function(){
  		ItinMap.map.panDirection(-1, 0);
  		return false;
  	},
  	zoomIn:function(){
  		ItinMap.map.setZoom(ItinMap.cleanZoom((ItinMap.map.getZoom()) + 1));
  		ItinMap.UpdateZoom();
  		return false;
  	},
  	zoomOut:function(){
  		ItinMap.map.setZoom(ItinMap.cleanZoom((ItinMap.map.getZoom()-1)));
  		ItinMap.UpdateZoom();
  		return false;
  	},
  	cleanZoom:function(value){
  		value = Math.round(value);
  		if (value < 1) {
  			value = 1;
  		}
  		if (value > 15)	{
  			value = 15;
  		}
  		return value;
  	},
  	markers:new Array(),
  	createMarker:function(point,name,html,icon, click,zoom){
  	  var marker = new GMarker(point, {icon:icon});

      var infobox_opts ={
        "content":"<a id=\"callout-close\" href=\"#\">&nbsp;</a>"  + html,
        "offsetVertical":-185,
        "height":200,
        "width":325,
        "className":"infobox"
      };

      var ibox = new InfoBox(point, infobox_opts);
      marker.infoBox = ibox;
      GEvent.addListener(marker, "click", function() {
  		  if(!zoom){
          if (ItinMap.map.infoBox) {
            ItinMap.map.removeOverlay(ItinMap.map.infoBox);
          }
          ItinMap.map.infoBox = marker.infoBox;
          ItinMap.map.addOverlay(ItinMap.map.infoBox);
          ItinMap.map.panTo(marker.getLatLng());
          $("#callout-close").click(function(){ItinMap.map.removeOverlay(ItinMap.map.infoBox);return false;});
  		  }
  		  else{
          ItinMap.map.setCenter(point, 4);
  		  }
        return false;
      });
      ItinMap.markers.push(marker);
      return marker;
    },
  	readMap:function(){
      // read the markers from the XML //
      GDownloadUrl("/marker.xml", function (doc) {
        var gmarkersCountry = [];
        var xmlDoc = GXml.parse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");
        // hide the info window, otherwise it still stays open where the removed marker used to be
        //ItinMap.map.getInfoWindow().hide();
        ItinMap.mm.clearMarkers();
        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new GLatLng(lat,lng);
          var name = markers[i].getAttribute("name");
          var type = markers[i].getAttribute("catagory");
          var html = markers[i].getAttribute("html");
          var marker = ItinMap.createMarker(point,name,html,ItinMap.countryicon, 1);
          gmarkersCountry.push(marker);
        }
        ItinMap.mm.addMarkers(gmarkersCountry, 2, 14);
        ItinMap.mm.refresh();
      });
    }
  }

  $(document).ready(function(){
    ItinMap.Render();
    $("#gmap_type_controls li.map_control_1 a").addClass("active");
  });
    