var map;

function tm_st(){}
tm_st.prototype = new GControl();
tm_st.prototype.initialize = function(map){
 	var stcontainer = document.createElement("div");
  var streset = document.createElement("span");
  var stmap = document.createElement("span");
  var stsat = document.createElement("span");
  var sthybrid = document.createElement("span");
  var stphys = document.createElement("span");

	streset.setAttribute("class", "mapbuttons");
	streset.setAttribute("id", "streset");
	streset.appendChild(document.createTextNode("Reset"));  
	stcontainer.appendChild(streset);
	GEvent.addDomListener(streset, "click", function() {map.returnToSavedPosition();} );
	stmap.setAttribute("class", "mapbuttons");
	stmap.setAttribute("id", "stmap");
	stmap.appendChild(document.createTextNode("Map"));  
	stcontainer.appendChild(stmap);
	GEvent.addDomListener(stmap, "click", function() {map.setMapType(G_NORMAL_MAP); stmap.setAttribute("class", "mapbuttons active");stsat.setAttribute("class", "mapbuttons");sthybrid.setAttribute("class", "mapbuttons");stphys.setAttribute("class", "mapbuttons");});
	stsat.setAttribute("class", "mapbuttons");
	stsat.setAttribute("id", "stsat");
	stsat.appendChild(document.createTextNode("Satellite"));  
	stcontainer.appendChild(stsat);
	GEvent.addDomListener(stsat, "click", function() {map.setMapType(G_SATELLITE_MAP);stmap.setAttribute("class", "mapbuttons");stsat.setAttribute("class", "mapbuttons active");sthybrid.setAttribute("class", "mapbuttons");stphys.setAttribute("class", "mapbuttons");});
	sthybrid.setAttribute("class", "mapbuttons");
	sthybrid.setAttribute("id", "sthybrid");
	sthybrid.appendChild(document.createTextNode("Hybrid"));  
	stcontainer.appendChild(sthybrid);
	GEvent.addDomListener(sthybrid, "click", function() {map.setMapType(G_HYBRID_MAP);stmap.setAttribute("class", "mapbuttons");stsat.setAttribute("class", "mapbuttons");sthybrid.setAttribute("class", "mapbuttons active");stphys.setAttribute("class", "mapbuttons");});
	stphys.setAttribute("class", "mapbuttons active");
	stphys.setAttribute("id", "stphys");
	stphys.appendChild(document.createTextNode("Physical"));  
	stcontainer.appendChild(stphys);
	GEvent.addDomListener(stphys, "click", function() {map.setMapType(G_PHYSICAL_MAP);stmap.setAttribute("class", "mapbuttons");stsat.setAttribute("class", "mapbuttons");sthybrid.setAttribute("class", "mapbuttons");stphys.setAttribute("class", "mapbuttons active");});
	map.getContainer().appendChild(stcontainer);
	return stcontainer;
};
tm_st.prototype.getDefaultPosition = function() {  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 1));};

function tm_initialise(loc,country){
	map = new GMap2(document.getElementById("googlemapsmall"));
	map.addControl(new tm_st());
	map.addControl(new GSmallMapControl());
	map.enableContinuousZoom();
	map.setMapType(G_PHYSICAL_MAP);
	map.enableDragging();
	GDownloadUrl("/templates/global/gateway.php?json=location-information&loc=" + loc+"&country="+country, function(doc){
		var jsonData = eval('(' + doc + ')');
		var point = new GLatLng(parseFloat(jsonData.gmapdata.cp.lat), parseFloat(jsonData.gmapdata.cp.lng));
		var zoom = jsonData.gmapdata.cp.zoom;
		map.setCenter(point, zoom);
		var icont = new GIcon(); 
		icont.iconSize = new GSize(26, 32);
		icont.iconAnchor = new GPoint(12, 35);
		icont.infoWindowAnchor = new GPoint(12, 0);
		icont.shadowSize = new GSize(42, 32);
		icont.shadow = 'http://s3media.pleasetakemeto.com/images/icon/shadow50.png';
		icont.image = 'http://s3media.pleasetakemeto.com/images/icon/icon-hero.png';
		var marker = new GMarker(point, icont);
		map.addOverlay(marker);
		
		if(jsonData.gmapdata.markers != undefined){
			for(var i = 0 ;i < jsonData.gmapdata.markers.length; i++){
				var point = new GLatLng(parseFloat(jsonData.gmapdata.markers[i].lat), parseFloat(jsonData.gmapdata.markers[i].lng));
				var icont = new GIcon(); 
				icont.iconSize = new GSize(26, 32);
				icont.iconAnchor = new GPoint(12, 35);
				icont.infoWindowAnchor = new GPoint(12, 0);
				icont.shadowSize = new GSize(42, 32);
				icont.shadow = 'http://s3media.pleasetakemeto.com/images/icon/shadow50.png';
				icont.image = 'http://s3media.pleasetakemeto.com/images/icon/icon-location.png?1234';
				var marker = new GMarker(point, icont);
				map.addOverlay(marker);
			}
		}
	});
	
}


