/****************************************
 *    	    Google Maps API v3 	        *
 * 	       pour Concept2 France         *
 * 										*
 * carte:								*
 *   Stade Pierre de Coubertin (Hotels)	*
 *   Paris XVIe					        *
 ***************************************/

 //<![CDATA[

function initialize_hotels(){
	var map = new google.maps.Map(document.getElementById("map_hotels"),{
		center: new google.maps.LatLng(48.835103623370514, 2.2563976049423218),
		zoom: 14,
		scaleControl: true,
	    navigationControl: true,
	    navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN },
	    mapTypeControl: false,
	    mapTypeId: google.maps.MapTypeId.HYBRID
	});
	var infoBox = new BFInfoWindow();
	// Change this depending on the name of your PHP file
	downloadUrl("gmaps/hotels_xml.php", function(data){
		var xml = parseXml(data);
		var markers = xml.documentElement.getElementsByTagName("marker");
		for (var i = 0;i < markers.length;i++){
			var name = markers[i].getAttribute("name");
			var address = markers[i].getAttribute("address");
			var type = markers[i].getAttribute("type");
			var point = new google.maps.LatLng(
				parseFloat(markers[i].getAttribute("lat")),
				parseFloat(markers[i].getAttribute("lng"))
			);
			var html = "<strong class=\"GmapTitle\">" + name + "</strong><div>" + address.replace(";", "<br />") + "</div>";
			var marker = new google.maps.Marker({
				map: map,
				position: point,
				icon: 'http://www.open-concept2.fr/gmaps/icons/hotel_icon.jpg'
			});
			bindInfoWindow(marker, map, infoBox, html);
		}
	});
	// Stade Pierre de Coubertin
		var stadeCoubertin = new google.maps.Marker({
			position: new google.maps.LatLng(48.835103623370514, 2.2563976049423218),
		    map: map,
		    icon: 'http://www.open-concept2.fr/gmaps/icons/c2_icon.png'
		});
		var stadeCoubertin_info = '<strong class="GmapTitle">Stade Pierre de Coubertin</strong><div>82 avenue Georges Lafont<br />75016 PARIS</div>';
		google.maps.event.addListener(stadeCoubertin, 'click', function() {
	  		infoBox.set_content(stadeCoubertin_info);
			infoBox.open(map,stadeCoubertin);
		});
}

function bindInfoWindow(marker, map, infoBox, html){
	google.maps.event.addListener(marker, 'click', function(){
		infoBox.set_content(html);
		infoBox.open(map,marker);
	});
}

function downloadUrl(url, callback){
	var request = window.ActiveXObject ?
		new ActiveXObject('Microsoft.XMLHTTP') :
		new XMLHttpRequest;
		
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			request.onreadystatechange = doNothing;
			callback(request.responseText, request.status);
		}
	};
	
	request.open('GET',url,true);
	request.send(null);
}
function parseXml(str){
	if(window.ActiveXObject){
		var doc = new ActiveXObject('Microsoft.XMLDOM');
		doc.loadXML(str);
		return doc;
	} else if(window.DOMParser) {
		return (new DOMParser).parseFromString(str, 'text/xml');
	}
}
function doNothing(){}

//]]>