﻿  function initialize() {
  function HomeControl(controlDiv, map) {

  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv.style.padding = '5px';

  // Set CSS for the control border
  var controlUI = document.createElement('DIV');
  controlUI.style.backgroundColor = 'white';
  controlUI.style.borderStyle = 'solid';
  controlUI.style.borderWidth = '1px';
  controlUI.style.borderColor= '#194a7c';
  controlUI.style.cursor = 'pointer';
  controlUI.style.textAlign = 'center';
  controlUI.title = 'Plan';
  controlDiv.appendChild(controlUI);

  // Set CSS for the control interior
  var controlText = document.createElement('DIV');
  controlText.style.fontFamily = 'Arial,sans-serif';
  controlText.style.fontSize = '12px';
  controlText.style.color = '#194a7c';
  controlText.style.paddingLeft = '4px';
  controlText.style.paddingRight = '4px';
  controlText.innerHTML = 'Plan';
  controlUI.appendChild(controlText);

  // Setup the click event listeners: simply set the map to Chicago
  google.maps.event.addDomListener(controlUI, 'click', function() {
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
  });
}  
function HomeControl2(controlDiv2, map) {
  // Set CSS styles for the DIV containing the control
  // Setting padding to 5 px will offset the control
  // from the edge of the map
  controlDiv2.style.padding = '5px';

  // Set CSS for the control border
  var controlUI2 = document.createElement('DIV');
  controlUI2.style.backgroundColor = 'white';
  controlUI2.style.borderStyle = 'solid';
  controlUI2.style.borderWidth = '1px';
  controlUI2.style.borderColor= '#194a7c';
  controlUI2.style.cursor = 'pointer';
  controlUI2.style.textAlign = 'center';
  controlUI2.title = 'Mixte';
  controlDiv2.appendChild(controlUI2);

  // Set CSS for the control interior
  var controlText2 = document.createElement('DIV');
  controlText2.style.fontFamily = 'Arial,sans-serif';  
  controlText2.style.color= '#194a7c';
  controlText2.style.fontSize = '12px';
  controlText2.style.paddingLeft = '4px';
  controlText2.style.paddingRight = '4px';
  controlText2.innerHTML = 'Mixte';
  controlUI2.appendChild(controlText2);

  // Setup the click event listeners: simply set the map to Chicago
  google.maps.event.addDomListener(controlUI2, 'click', function() {
map.setMapTypeId(google.maps.MapTypeId.HYBRID);
  });
}
    geocoder = new google.maps.Geocoder();
	mylatlng = new google.maps.LatLng(dude, john);	
    var myOptions = {
      zoom: 17,
      center: (mylatlng),
      mapTypeId: google.maps.MapTypeId.ROADMAP,
	     mapTypeControl: false,

    navigationControl: true,
    navigationControlOptions: {
        style: google.maps.NavigationControlStyle.SMALL,
        position: google.maps.ControlPosition.TOP_LEFT
    }
    }
		var imageMarqueur = new google.maps.MarkerImage('http://www.sortir-a-rennes.com/img/A_marquer_fat_'+cat+'.png', new google.maps.Size(32, 46), new google.maps.Point(0,0), new google.maps.Point(16, 46));
    map = new google.maps.Map(document.getElementById("map_lieu"), myOptions);
        var marker = new google.maps.Marker({
            position: mylatlng,
			map: map, 
			icon: imageMarqueur,
			shadow: ombreMarqueur
        });
  // Create the DIV to hold the control and call the HomeControl() constructor
  // passing in this DIV.
  var homeControlDiv = document.createElement('DIV');
  var homeControl = new HomeControl(homeControlDiv, map);

  homeControlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv); 
  
  var homeControlDiv2 = document.createElement('DIV');
  var homeControl2 = new HomeControl2(homeControlDiv2, map);

  homeControlDiv2.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv2);
        var infoWindow = new google.maps.InfoWindow;
        downloadUrl('http://www.sortir-a-rennes.com/xml/all.xml', function(data) {
        var xml = request.responseXML;

	
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var souscat = markers[i].getAttribute("souscat");
		  if (souscat==caty||caty=="") {
          var name = markers[i].getAttribute("name");
          var namebis = markers[i].getAttribute("namebis");
          var thumb = markers[i].getAttribute("thumb");
			var cat = markers[i].getAttribute("cat");
			var lat=  parseFloat(markers[i].getAttribute("lat"));
            var lng=  parseFloat(markers[i].getAttribute("lng"));
          point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));

		if (lat!=dude && lng!=john) {  
          var html = '<img width="40px" height="40px"src="http://www.sortir-a-rennes.com/thumbs/'+ thumb +'"><a href="http://www.sortir-a-rennes.com/'+ cat +'/'+ souscat +'/'+ namebis +'">' + name + '</a>';
          imageMarqueur = new google.maps.MarkerImage('http://www.sortir-a-rennes.com/img/A_marquer_'+cat+'.png', new google.maps.Size(10,10), new google.maps.Point(0,0), new google.maps.Point(4, 4));
	   var marker2 = new google.maps.Marker({
            position: point,
			map: map, 
			icon: imageMarqueur,
        });
          bindInfoWindow(marker2, map, infoWindow, html);
		  }
		  			  		  }
        }
      });

  }
    function bindInfoWindow(marker, map, infoWindow, html, point) {
      google.maps.event.addListener(marker, 'click', function() {

		map.setZoom(16);
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
		map.setCenter(point);
      });
    }

    function downloadUrl(url, callback) {
     request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;
		  
    request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}

    var ombreMarqueur = new google.maps.MarkerImage('http://www.sortir-a-rennes.com/img/marker-shadow.png', new google.maps.Size(50, 35), new google.maps.Point(0,0), new google.maps.Point(0, 35));
