//***********************************************************
// Trail Locator Project
// The Trans Canada Trail
// http://www.tctrail.ca
// 
// Coding by Stephane Simard
// ssoutbox-tctrail@yahoo.com
//************************************************************


// Variable global
// Contenant des overlays
var geoMarkerOverlay = new Array();
var trailInfoOverlay = null;
var pavMarker = null;
var pavInfo = null;


//-------------------------------------------------------------------------------------------
// Creation des marker de position dans la recherche Geocoding

function createGeoMarker(latlng, adress)
{
	// Marker icon settings
	var markerIcon = new GIcon();
	markerIcon.image = "images/marker.png";
	markerIcon.shadow = "";
    markerIcon.iconSize = new GSize(20, 15);
    markerIcon.shadowSize = new GSize(0, 0);
	markerIcon.iconAnchor = new GPoint(0, 0);
	markerIcon.infoWindowAnchor = new GPoint(0, 0);
	markerIcon.infoShadowAnchor = new GPoint(0, 0);
		
	// Create marker html iformation
	var html = '<table class="infoWinText" border="0" cellpadding="4" cellspacing="0"><tr><td height="30" width="100%" class="infoWinTitle" nowrap>' + adress;
	html = html + '&nbsp;&nbsp;<a href="javascript:geoMarkerOverlay[' + geoMarkerOverlay.length + '].hide();"><img src="images/closeinfo.png" border="0" align="top" title="'+ lang(15) +'"></a></td></tr></table>';
	
	// Create marker and infoWin
	var marker = new GMarker(latlng, markerIcon);
	var infoWin = new classInfoWin(map, "infowin", "images/infowin.png");
	
	// Add on MAP
	map.addOverlay(marker);
	map.addOverlay(infoWin);
		
	infoWin.openOnMarker(marker, html);	// Ouvrir le html texte
	geoMarkerOverlay.push(infoWin);		// Garde l'overlay en mémoire
	
	// Sur event click du marker - ouvre et ferme l'infoWin
	GEvent.addListener(marker, "click", function(latlng) 
	{
		// Si dans tools calcul distance, ignorer event sur click et mettre un marker de distance
		if(document.getElementById("distanceDiv").style.display == "block")
				clickDistanceEvent(null, marker.getPoint());
		else{
			if(infoWin.isHidden() == true)
				infoWin.showme();
			else	
				infoWin.hide();
		}
	});
}


//-------------------------------------------------------------------------------------------
// Creation des marker de position dans la recherche de pavilions

function createPavMarker(latlng, name, image)
{
	// Enlever marker precedent
	if(pavMarker != null)
	{
		pavInfo.remove();
		map.removeOverlay(pavMarker);
	}
 	
	// Marker icon settings       
	var markerIcon = new GIcon();
	markerIcon.image = "images/pav.png";
	markerIcon.shadow = "";
    markerIcon.iconSize = new GSize(20, 17);    
    markerIcon.shadowSize = new GSize(0, 0);
	markerIcon.iconAnchor = new GPoint(0, 0);
	markerIcon.infoWindowAnchor = new GPoint(0, 0);
	markerIcon.infoShadowAnchor = new GPoint(0, 0);

	// Create marker html iformation
	var html = '<table border="0" cellpadding="4" cellspacing="0"><tr><td height="30" width="100%" class="infoWinTitle" nowrap>' + name;
	html = html + '&nbsp;&nbsp;<a href="javascript:pavInfo.hide();"><img src="images/closeinfo.png" border="0" align="top" title="'+ lang(15) +'"></a></td></tr>';
	html = html + '<tr><td><img border="0" src="'+ image +'"></td></tr>';
	html = html + '<tr><td nowrap class="infoWinLink"><a href="javascript:showInfoPavDiv(\'' + name + '\');">'+ lang(22) +'</a></td></tr></table>';   
		
	// Create marker and infoWin
	pavMarker = new GMarker(latlng, markerIcon);
	pavInfo = new classInfoWin(map, "infowin", "images/infowin.png");
	
	// Add on MAP
	map.addOverlay(pavMarker);
	map.addOverlay(pavInfo);
	pavInfo.openOnMarker(pavMarker, html);	// Ouvrir le html texte
	
	// Sur event click du marker - ouvre et ferme l'infoWin
	GEvent.addListener(pavMarker, "click", function()
	{
		// Si dans tools calcul distance, ignorer event sur click et mettre un marker de distance
		if(document.getElementById("distanceDiv").style.display == "block")
				clickDistanceEvent(null, pavMarker.getPoint());
		else{
			if(pavInfo.isHidden() == true)
				pavInfo.showme();
			else
				pavInfo.hide();
		}
	});
}


//-------------------------------------------------------------------------------------------
// Creation des infoWin pour les sentiers
	
function createInfoWin(arrow, latlng, province, number, name) 
{
	// Create marker html iformation
	var html = '<table class="infoWinText" border="0" cellpadding="4" cellspacing="0"><tr><td height="30" width="100%" class="infoWinTitle" nowrap>' + name;
	html = html + '&nbsp;&nbsp;<a href="javascript:removeInfoWin();"><img src="images/closeinfo.png" border="0" align="top" title="'+ lang(15) +'"></a></td></tr>';
	html = html + '<tr><td nowrap>Province: ' + province + '</td></tr>';
	html = html + '<tr><td nowrap>'+ lang(16) + number + '</td></tr>';
	html = html + '<tr><td nowrap class="infoWinLink"><a href="javascript:addFavorite();">'+ lang(20) +'</a></td></tr>';
	html = html + '<tr><td nowrap class="infoWinLink"><a href="javascript:showInfoTrailDiv(\'' + number + '\');">'+ lang(17) +'</a></td></tr></table>';   
	
	// Mettre l'image de la flèche avec le infowin
	if(arrow == true)
		var imgPath = "images/infowin.png";
	else
		var imgPath = "";
	
	// Create infoWin 
	trailInfoOverlay = new classInfoWin(map, "infowin", imgPath);
	map.addOverlay(trailInfoOverlay);			// Add on map
	trailInfoOverlay.openOnMap(latlng, html);	// Ouvrir le html texte
}


//-------------------------------------------------------------------------------------------
// Remove l'infoWin
	
function removeInfoWin() 
{
	if(trailInfoOverlay != null)
	{
		trailInfoOverlay.remove();
		trailInfoOverlay = null;
	}
}

