﻿// A TextualZoomControl is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).

// We define the function first
function TextualZoomControl() {
}

// To "subclass" the GControl, we set the prototype object to
// an instance of the GControl object
TextualZoomControl.prototype = new GControl();

// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
TextualZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var zoomInDiv = document.createElement("div");
  this.setButtonStyle_(zoomInDiv);
  container.appendChild(zoomInDiv);
  zoomInDiv.appendChild(document.createTextNode("Zoom In"));
  GEvent.addDomListener(zoomInDiv, "click", function() {
    map.zoomIn();
  });

  var zoomOutDiv = document.createElement("div");
  this.setButtonStyle_(zoomOutDiv);
  container.appendChild(zoomOutDiv);
  zoomOutDiv.appendChild(document.createTextNode("Zoom Out"));
  GEvent.addDomListener(zoomOutDiv, "click", function() {
    map.zoomOut();
  });

  map.getContainer().appendChild(container);
  return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
TextualZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

// Sets the proper CSS for the given button element.
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "underline";
  button.style.color = "#0000cc";
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}


function animate() {    
      map.panTo(new GLatLng(51.2105332583623,2.830352783203125));
    }

//<![CDATA[
function load(map_info,zone,coordx,coordy) {
	if (GBrowserIsCompatible()) {
		var baseIcon = new GIcon();
		baseIcon.iconSize=new GSize(53,52);
		//baseIcon.shadowSize=new GSize(20,22);
		//baseIcon.iconAnchor=new GPoint(6,20);
		//baseIcon.infoWindowAnchor=new GPoint(5,1);
		//var un = new GIcon(baseIcon, 'http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/images/m1.png', null, 'http://labs.google.com/ridefinder/images/mm_20_shadow.png');
		
		// Create our "tiny" marker icon
		var blueIcon = new GIcon();
		blueIcon.iconSize=new GSize(32,32);
		blueIcon.iconAnchor=new GPoint(0,0);
		blueIcon.infoWindowAnchor=new GPoint(12,12);
		blueIcon.image = "http://www.location-de-vacances.be/images/maison.gif";

		// Create our "tiny" marker icon
		var redIcon = new GIcon();
		redIcon.iconSize=new GSize(66,65);
		redIcon.iconAnchor=new GPoint(33,30);		
		redIcon.image = "http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/images/m3.png";

		


		
		function createMarker(point,html,icon) {
			var marker = new GMarker(point,icon);
			GEvent.addListener(marker, 'click', function() {
				marker.openInfoWindowHtml(html);
			});			
			return marker;
		}
		
		function createGroupMarker(point,html,montxt,adsid,pays,x,y) {
		
		opts = { 
	"icon": redIcon,
	"clickable": true,
	"labelText": montxt,
	"labelClass": "maplabels",
	"labelOffset": new GSize(-11, -5)
	};
			//var marker = new GMarker(point,opts);
			var marker = new LabeledMarker(point, opts);

			
			GEvent.addListener(marker, 'click', function() {
				location.href = "http://www.location-de-vacances.be/carte.cfm?pays="+pays+"&r1="+adsid+"&x="+x+"&y="+y+"" ;
			});
			return marker;
		}

		
	if (zone == 0){ var monzoom = map_info.zoom;}	
	else{var monzoom = map_info.zoom+2;} 
	
	if (coordx == 0){ var monx = map_info.x;}	
	else{var monx = coordx;} 
	
	if (coordy == 0){ var mony = map_info.y;}	
	else{var mony = coordy;} 
	
		var Macarte = new GMap2(document.getElementById('EmplacementDeMacarte'));
		Macarte.setCenter(new GLatLng(monx, mony), monzoom);
		Macarte.addControl(new TextualZoomControl());
		// Macarte.addControl(new GSmallMapControl());
		// Macarte.addControl(new GMapTypeControl());

		// var gx = new GGeoXml("http://www.xxx.fr/kml_gg_r11.kml");
		// Macarte.addOverlay(gx);


	zurl = map_info.xml;	
	zurl = zurl+"&r1="+zone;
	GDownloadUrl(zurl, function(data, responseCode) {	
	  // To ensure against HTTP errors that result in null or bad data,
	  // always check status code is equal to 200 before processing the data
	  if(responseCode == 200) {
    var xml = GXml.parse(data);
	//alert(data);
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                              parseFloat(markers[i].getAttribute("lng")));
      adsid= markers[i].getAttribute("adsid");
      city= markers[i].getAttribute("city");
      detail= markers[i].getAttribute("detail");	
      zicon= markers[i].getAttribute("icon");
      profil= markers[i].getAttribute("profil");
	if (profil == 1){ tag = '<img src="/profil/t/'+adsid+'.jpg">'}	
	else{tag = '<img src="/profil/t/'+adsid+'.jpg" width="120">'}
      var html = '<div id="alfa"><div id="bravo" style="min-height: 90px; height: 90px;"><table width="320" height="100"><tr><td>'+tag+'</td><td width="165"><b>Location&nbsp;de&nbsp;vacances&nbsp;r&eacute;f.'+adsid+'<br>'+city+'<br><br><a href="/apropos.cfm?id='+adsid+'">'+detail+'</a></b></td></tr></table></div></div>';      
	if (zicon == 1){ var marker = createMarker(point, html,blueIcon);}	
	else{var marker = createGroupMarker(point, html,profil,adsid,city,markers[i].getAttribute("lat"),markers[i].getAttribute("lng"));}      
     Macarte.addOverlay(marker);
    }
	
  } else if(responseCode == -1) {
    //alert("Data request timed out. Please try later.");
  } else { 
    //alert("Request resulted in error. Check XML file is retrievable.");
  }
});



	}else{
		alert('Désolé, mais votre navigateur n\'est pas compatible avec Google Maps');
	}  

}
//]]>

var place_info = {};
place_info[0] = {map:{x: 41.87194, y:12.56738, zoom: 5, xml: "data.cfm?pays=1"}, places:["Tour Place 1", "Place 2", "Place 3"]};
place_info[1] = {map:{x: 41.87194, y:12.56738, zoom: 6, xml: "data.cfm?pays=1"}, places:["Italy Place 1", "Place 2", "Place 3"]};
place_info[2] = {map:{x: 40.463666, y:-3.757324, zoom: 5, xml: "data.cfm?pays=2"}, places:["Spain Place 1", "Place 2", "Place 3"]};
place_info[3] = {map:{x: 46.225453, y:4.130859, zoom: 6, xml: "data.cfm?pays=3"}, places:["France Place 1", "Place 2", "Place 3"]};
place_info[4] = {map:{x: 50.503887, y:4.469936, zoom: 7, xml: "data.cfm?pays=4"}, places:["Belgium Place 1", "Place 2", "Place 3"]};	
place_info[5] = {map:{x: 39.399872, y:-8.224454, zoom: 6, xml: "data.cfm?pays=5"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[6] = {map:{x: 46.985749, y:8.514404, zoom: 6, xml: "data.cfm?pays=6"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[7] = {map:{x: 39.051043, y:23.060303, zoom: 6, xml: "data.cfm?pays=7"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[8] = {map:{x: 51.670738, y:5.95459, zoom: 6, xml: "data.cfm?pays=8"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[9] = {map:{x: 43.944318, y:15.732422, zoom: 6, xml: "data.cfm?pays=9"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[10] = {map:{x: 31.70823, y:-8.964844, zoom: 5, xml: "data.cfm?pays=10"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[11] = {map:{x: 47.284695, y:16.435547, zoom: 6, xml: "data.cfm?pays=11"}, places:["Portugal Place 1", "Place 2", "Place 3"]};
place_info[12] = {map:{x: 52.368445, y:-1.625977, zoom: 6, xml: "data.cfm?pays=12"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[13] = {map:{x: 50.913193, y:10.019531, zoom: 6, xml: "data.cfm?pays=13"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[14] = {map:{x: 52.998036, y:-7.338867, zoom: 6, xml: "data.cfm?pays=14"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[15] = {map:{x: 64.950845, y:-18.28125, zoom: 6, xml: "data.cfm?pays=15"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[16] = {map:{x: 61.104037, y:26.367188, zoom: 6, xml: "data.cfm?pays=16"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[17] = {map:{x: 60.661697, y:15.996094, zoom: 6, xml: "data.cfm?pays=17"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[18] = {map:{x: 54.86312, y:10.107422, zoom: 6, xml: "data.cfm?pays=18"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[19] = {map:{x: 46.069166, y:14.765625, zoom: 8, xml: "data.cfm?pays=19"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[20] = {map:{x: 44.335374, y:18.127441, zoom: 7, xml: "data.cfm?pays=20"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[21] = {map:{x: 44.178002, y:20.961914, zoom: 6, xml: "data.cfm?pays=21"}, places:["Portugal Place 1", "Place 2", "Place 3"]};
place_info[22] = {map:{x: 47.036189, y:19.335938, zoom: 6, xml: "data.cfm?pays=22"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[23] = {map:{x: 49.734895, y:15.446777, zoom: 6, xml: "data.cfm?pays=23"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[24] = {map:{x: 48.745082, y:19.621582, zoom: 6, xml: "data.cfm?pays=24"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[25] = {map:{x: 41.619275, y:21.665039, zoom: 7, xml: "data.cfm?pays=25"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[26] = {map:{x: 42.72657, y:19.204102, zoom: 7, xml: "data.cfm?pays=26"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[27] = {map:{x: 34.9712, y:33.266602, zoom: 8, xml: "data.cfm?pays=27"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[28] = {map:{x: 41.074934, y:20.01709, zoom: 7, xml: "data.cfm?pays=28"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[29] = {map:{x: 40.107207, y:30.805664, zoom: 7, xml: "data.cfm?pays=29"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[30] = {map:{x: 42.647967, y:25.455322, zoom: 7, xml: "data.cfm?pays=30"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[31] = {map:{x: 47.170795, y:28.608398, zoom: 7, xml: "data.cfm?pays=31"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[32] = {map:{x: 45.68981, y:25.048828, zoom: 7, xml: "data.cfm?pays=32"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[33] = {map:{x: 51.804992, y:19.182129, zoom: 7, xml: "data.cfm?pays=33"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[34] = {map:{x: 55.844071, y:38.056641, zoom: 6, xml: "data.cfm?pays=34"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[35] = {map:{x: 0.591787, y:37.880859, zoom: 7, xml: "data.cfm?pays=35"}, places:["Portugal Place 1", "Place 2", "Place 3"]};	
place_info[36] = {map:{x: 14.326841, y:-14.414062, zoom: 8, xml: "data.cfm?pays=36"}, places:["Sénégal Place 1", "Place 2", "Place 3"]};	
place_info[37] = {map:{x: 34.938785, y:10.371094, zoom: 7, xml: "data.cfm?pays=37"}, places:["Tunisie Place 1", "Place 2", "Place 3"]};	
place_info[38] = {map:{x: 33.41188, y:2.988281, zoom: 7, xml: "data.cfm?pays=38"}, places:["Algérie Place 1", "Place 2", "Place 3"]};	
place_info[39] = {map:{x: -30.013299, y:24.521484, zoom: 6, xml: "data.cfm?pays=39"}, places:["Afrique du Sud  1", "Place 2", "Place 3"]};	
place_info[40] = {map:{x: 39.00951, y:-91.582031, zoom: 5, xml: "data.cfm?pays=40"}, places:["Etats-Unis e Place 1", "Place 2", "Place 3"]};	
place_info[41] = {map:{x: 50.88, y:-72.597656, zoom: 5, xml: "data.cfm?pays=41"}, places:["Etats-Unis e Place 1", "Place 2", "Place 3"]};	


function changeOutput(id,zone,coordx,coordy){
	
	var div = $("#most_visited:first");
	
	//Clear previous places
	div.html("");
	
	var info = place_info[id];
	if(!info){
		return;
	}
	
	//Add new places
	var places = info.places;
	for(var i = 0; i < places.length; i++){		
		div.append("<div><a href='javascript:animate();'>" +places[i]+ "</a></div>");
	}
	
	//Change map id
	load(info.map,zone,coordx,coordy);
}

