var map;
var centreP1 = new GLatLng(50.25321461705864, 3.2903623580932617);
var centreP2 = new GLatLng(50.25675423185253, 3.291606903076172);
var centreP3 = new GLatLng(50.255546950930764, 3.291134834289551);
var parcours1;
var parcours2; 
var parcours3;
var toggleState = 1;
var h=250;
var w=430;
var domaine="http://www.bassin-rond.net/pano/";
var indice = "<p><em>Cliquez et glissez sur l'image pour la faire tourner !</em></p>";

// parcours1
//club
var p1= '<h1>Notre club !</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/club/club.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/club/club.xml" /></embed>'+indice;

//pontpaillencourt
var p2= '<h1>Le pont de Paillencourt</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/pontpaillencourt/pontpaillencourt.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/pontpaillencourt/pontpaillencourt.xml" /></embed>'+indice;

//estrun
var p3= '<h1>Sur la rive d\'Estrun</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/estrun/estrun.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/estrun/estrun.xml" /></embed>'+indice;

//pontdesimbeciles
var p4= '<h1>Le pont des imb&eacute;ciles</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/pontdesimbeciles/pontdesimbeciles.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/pontdesimbeciles/pontdesimbeciles.xml" /></embed>'+indice;

//brasmort
var p5= '<h1>Le bras mort</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/brasmort/brasmort.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/brasmort/brasmort.xml" /></embed>'+indice;

//pontsense
var p6= '<h1>Le pont de la Sens&eacute;e</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/pontsense/pontsense.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/pontsense/pontsense.xml" /></embed>'+indice;

//grandgabarit
var p7= '<h1>Le grand gabarit</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/grandgabarit/grandgabarit.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/grandgabarit/grandgabarit.xml" /></embed>'+indice;

//ecluse
var p8= '<h1>L\'&eacute;cluse du pont malin</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/ecluse/ecluse.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/ecluse/ecluse.xml" /></embed>'+indice;

//bassinrond
var p9= '<h1>Le bassin rond</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/bassinrond/bassinrond.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/bassinrond/bassinrond.xml" /></embed>'+indice;

//canotier
var p10= '<h1>Une aire de pique-nique</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/canotier/canotier.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/canotier/canotier.xml" /></embed>'+indice;

//brasparc
var p11= '<h1>L\'Escaut</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/brasparc/brasparc.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/brasparc/brasparc.xml" /></embed>'+indice;

//pointe
var p12= '<h1>La pointe</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/pointe/pointe.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/pointe/pointe.xml" /></embed>'+indice;

//parc
var p13= '<h1>L\'aire de jeu</h1>	<object height="'+h+'" width="'+w+'"><param name="movie" value="'+domaine+'krpano.swf"><param name="flashvars" value="pano='+domaine+'parcours/parc/parc.xml"><param name="allowFullScreen" value="true"><embed src="'+domaine+'krpano.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+h+'" width="'+w+'" allowFullScreen="true" flashvars="pano='+domaine+'parcours/parc/parc.xml" /></embed>'+indice;


var parcoursEncours = "parcours1";
var club;
var paillencourt;
var estrun;
var pont;
var bras;
var pontsense;
var grandgabarit;
var ecluse;
var bassinrond;	
var canotier;
var brasparc;
var pointe;
var parc;
			
function initialize() {
  if (GBrowserIsCompatible()) {
    parcours1 = new GGeoXml("http://www.bassin-rond.net/pano/parcours/parcours1.kml");
	parcours2 = new GGeoXml("http://www.bassin-rond.net/pano/parcours/parcours2.kml");
	parcours3 = new GGeoXml("http://www.bassin-rond.net/pano/parcours/parcours3.kml");
	
    map = new GMap2(document.getElementById("map")); 
	map.setMapType(G_SATELLITE_MAP);
	
	var baseIcon = new GIcon();
        baseIcon.iconSize=new GSize(32,32);
        baseIcon.shadowSize=new GSize(56,32);
        baseIcon.iconAnchor=new GPoint(16,32);
        baseIcon.infoWindowAnchor=new GPoint(16,0);

	var depart = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon2.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon2s.png");
    var etape   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal4/icon38.png", null, "http://maps.google.com/mapfiles/kml/pal4/icon38s.png");     

	club = new GMarker(new GLatLng(50.25452863571367,3.295745459174713),depart);
	  GEvent.addListener(club, 'click', function() {
		map.openInfoWindowHtml(club.getLatLng() ,p1,{onCloseFn :recentre});
	  });
	paillencourt = new GMarker(new GLatLng(50.24900240721125,3.280363082885742),etape);
	  GEvent.addListener(paillencourt, 'click', function() {
		map.openInfoWindowHtml(paillencourt.getLatLng() ,p2,{onCloseFn :recentre});
	  });
	estrun = new GMarker(new GLatLng(50.251197742191444,3.2931196689605713),etape);
	  GEvent.addListener(estrun, 'click', function() {
		map.openInfoWindowHtml(estrun.getLatLng() ,p3,{onCloseFn :recentre});
	  });
	pont = new GMarker(new GLatLng(50.255334301690446,3.299964666366577),etape);
	  GEvent.addListener(pont, 'click', function() {
		map.openInfoWindowHtml(pont.getLatLng() ,p4,{onCloseFn :recentre});
	  });
	bras = new GMarker(new GLatLng(50.25695315588684,3.2982265949249268),etape);
	  GEvent.addListener(bras, 'click', function() {
		map.openInfoWindowHtml(bras.getLatLng() ,p5,{onCloseFn :recentre});
	  });
	
	pontsense = new GMarker(new GLatLng(50.25197141271322,3.281975359704135),etape);
	  GEvent.addListener(pontsense, 'click', function() {
		map.openInfoWindowHtml(pontsense.getLatLng() ,p6,{onCloseFn :recentre});
	  });
	grandgabarit = new GMarker(new GLatLng(50.25601197189619,3.281312795837623),etape);
	  GEvent.addListener(grandgabarit, 'click', function() {
		map.openInfoWindowHtml(grandgabarit.getLatLng() ,p7,{onCloseFn :recentre});
	  });
	ecluse = new GMarker(new GLatLng(50.26678442732776,3.301607045969195),etape);
	  GEvent.addListener(ecluse, 'click', function() {
		map.openInfoWindowHtml(ecluse.getLatLng() ,p8,{onCloseFn :recentre});
	  });
	bassinrond = new GMarker(new GLatLng(50.25524872838024,3.303418027306047),etape);
	  GEvent.addListener(bassinrond, 'click', function() {
		map.openInfoWindowHtml(bassinrond.getLatLng() ,p9,{onCloseFn :recentre});
	  });
	canotier = new GMarker(new GLatLng(50.24951008741536,3.2813501358032227),etape);
	  GEvent.addListener(canotier, 'click', function() {
		map.openInfoWindowHtml(canotier.getLatLng() ,p10,{onCloseFn :recentre});
	  });
	brasparc = new GMarker(new GLatLng(50.256768,3.3024),etape);
	  GEvent.addListener(brasparc, 'click', function() {
		map.openInfoWindowHtml(brasparc.getLatLng() ,p11,{onCloseFn :recentre});
	  });
	pointe = new GMarker(new GLatLng(50.261432,3.298774),etape);
	  GEvent.addListener(pointe, 'click', function() {
		map.openInfoWindowHtml(pointe.getLatLng() ,p12,{onCloseFn :recentre});
	  });
	parc = new GMarker(new GLatLng(50.257056,3.30004),etape);
	  GEvent.addListener(parc, 'click', function() {
		map.openInfoWindowHtml(parc.getLatLng() ,p13,{onCloseFn :recentre});
	  });
	
	GEvent.addListener(map, 'clearoverlays', addParcours);
	
   	//map.setUIToDefault();
	var customUI = map.getDefaultUI();
	customUI.maptypes.physical = false;
	map.setUI(customUI);
		
	showParcours('parcours1');
  }
} 


function showParcours(p)
{
	parcoursEncours = p;
	map.clearOverlays();
}

function addParcours()
{
	switch(parcoursEncours)
	{
		case 'parcours1':
			map.setCenter(centreP1, 15);
			
			map.addOverlay(club);
			map.addOverlay(paillencourt);
			map.addOverlay(estrun);
			map.addOverlay(pont);
			map.addOverlay(bras);
			map.addOverlay(parc);
			map.addOverlay(parcours1);
			
			break;
		
		case 'parcours2':
			map.setCenter(centreP2, 14);
		
			map.addOverlay(pontsense);
			map.addOverlay(grandgabarit);
			map.addOverlay(ecluse);
			map.addOverlay(bassinrond);
			map.addOverlay(canotier);
			map.addOverlay(parcours2);
		
			break;
			
		case 'parcours3':
			map.setCenter(centreP3, 15);
			
			map.addOverlay(pontsense);
			map.addOverlay(grandgabarit);
			map.addOverlay(club);
			map.addOverlay(bras);
			map.addOverlay(canotier);
			map.addOverlay(brasparc);
			map.addOverlay(pointe);
			map.addOverlay(parc);
			map.addOverlay(parcours3);
			
			break;
	}
}

function recentre()
{
	switch(parcoursEncours)
	{
		case 'parcours1':
			map.panTo(centreP1);
			break;
		case 'parcours2':
			map.panTo(centreP2);
			break;
		case 'parcours3':
			map.panTo(centreP3);
			break;
	}
}

function recentreP1()
{
	map.panTo(centreP1);
}

function recentreP2()
{
	map.panTo(centreP2);
}

function recentreP3()
{
	map.panTo(centreP3);
}

function toggleMyKml() {
	alert(map.getCenter());
  
}
