﻿// JScript File

// arrays to hold copies of the markers and html used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
var i = 0;
var linkid = "activite"+i;
var lastlinkid="";
var bounds = new GLatLngBounds();
var map;

function CreateMarkerAndPoint2(Lat,Lng,name,URL,html,CatID)
{
	// add the points  
	var LinkIDCreate="activite"+i;  
	var LinkIDCreate2=i;
	var point = new GLatLng(Lat,Lng);
	var marker = createMarker(point,name,html,CatID);
	GEvent.addListener(marker, "click", function() {
		document.location.href=URL;
	});
	map.addOverlay(marker);
	bounds.extend(point);
}

// A function to create the marker and set up the event window
function createMarker(point,name,html,CatID) {
	// use a custom icon with letter A - Z
	//var letter = String.fromCharCode("A".charCodeAt(0) + i);
	var imgName = "A";
	if (CatID==2){
	    imgName = "D";
	}
	if (CatID==3){
	    imgName = "R";
	}
	var myIcon = new GIcon(G_DEFAULT_ICON, "/medias/communs/pushpins/map/" + imgName + ".png");
	myIcon.shadow="/medias/communs/pushpins/map/ombre.png";
	myIcon.printImage = "/medias/communs/pushpins/map/" + imgName + ".png";
	myIcon.mozPrintImage = "/medias/communs/pushpins/map/" + imgName + ".png";
	myIcon.shadowSize=new GSize(27,28);
	myIcon.iconSize=new GSize(21,21);
	myIcon.iconAnchor=new GPoint(0,21);
	
	var marker = new GMarker(point, {icon:myIcon,title: name});
	
	// save the info we need to use later for the side_bar
	gmarkers[i] = marker;
	i++;
	return marker;
}

function SetInitLayoutCarte() {
	var strUrl = window.location.href;
	var intPosition = strUrl.indexOf('#');
	if(intPosition > 0){
		lastlinkid = strUrl.substring(intPosition+1);
		var aHighlight = getElementsByName_iefix(lastlinkid);
		for(i=0;i<aHighlight.length;i++)
			aHighlight[i].firstChild.className="innerItem listHighlight";
	}
}


function getElementsByName_iefix(name) {
     var rootList = document.getElementById("escListeAct");
     var elem = rootList.getElementsByTagName("li");
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          //att = elem[i].getAttribute("name");
          att = elem[i].className;
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


// This function picks up the click and opens the corresponding info window
function myclick(i) {
	linkid="activite"+i;
	GEvent.trigger(gmarkers[i], "click");
}

function initialize() {
	if (GBrowserIsCompatible()) {
		var mapDiv = document.getElementById("escCarte");
		// create the map
		map=new GMap2(mapDiv);
        map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		//map.addControl(new  GScaleControl());
		map.setCenter(new GLatLng(45.629405,-73.487549),5);
		var CopyrightDiv = mapDiv.firstChild.nextSibling;
		CopyrightDiv.className = "escCarteCopy";
	} else {
		alert("Désolé, Google Maps n'est pas compatible avec ce navigateur \n Sorry, Google Maps is not compatible with this browser");
	}
}