var map;
var map2;
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 active");
	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");
	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_listing(listing_id, entity,country){
	process = function(doc){
		map = new GMap2(document.getElementById("googlemaplisting"));
		map.checkResize();
		map.addControl(new tm_st());
		//map.addControl(new GScaleControl());
		map.addControl(new GSmallMapControl());
		map.enableContinuousZoom();
		map.enableDragging();
		bounds = new GLatLngBounds();
		var jsonData = eval('(' + doc + ')');
		var point = new GLatLng(parseFloat(jsonData.gmapdata.lat), parseFloat(jsonData.gmapdata.lng));
		var zoom = jsonData.gmapdata.zoom;
		map.setCenter(point, zoom);
		map.checkResize();
		if(jsonData.gmapdata.showmarker == "yes"){
			var icont = new GIcon();
			//icont.iconSize = new GSize(20, 34);
			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);
		}
	}
	GDownloadUrl("/webapp/wcs/stores/ConsumerDirectStorefrontAssetStore/Destination/proxy.jsp?json=listing-overview&listing_id=" + listing_id+ "&entity="+entity+"&country="+country, process);
}

function tm_initialise(loc,country){
	process = function(doc){
		map2 = new GMap2(document.getElementById("googlemapsmall"));
		map2.checkResize();
		map2.addControl(new tm_st());
		//map.addControl(new GScaleControl());
		map2.addControl(new GSmallMapControl());
		map2.enableContinuousZoom();
		map2.enableDragging();
		bounds = new GLatLngBounds();
		var jsonData = eval('(' + doc + ')');
		var point = new GLatLng(parseFloat(jsonData.gmapdata[0].lat), parseFloat(jsonData.gmapdata[0].lng));
		var zoom = jsonData.gmapdata[0].zoom;
		map2.setCenter(point, zoom);
		map2.checkResize();
	}
	GDownloadUrl("/webapp/wcs/stores/ConsumerDirectStorefrontAssetStore/Destination/proxy.jsp?json=region-information&loc=" + loc+"&country="+country, process);
}

