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


//-------------------------------------------------------------------------------------------
//  ZOOM CLASS

// Setting up zoom for TLocator
//  this.zoom = new Array(3, 5, 7, 9, 11, 13, 15, 17)
// Ex: tlocator zoom 0 = index array 0 of this.zoom (zoom google API 3)
// Ex: tlocator zoom 1 = index array 1 of this.zoom (zoom google API 5)

function classTLocatorZoom(zoomArray, extendLevel, startZoom)
{
	this.zoom = zoomArray;					// TLocator zoom array
	this.minZoom = 0;						// Minimun zoom (0)
	this.maxZoom = this.zoom.length - 1;	// Maximun Zoom (7)
	this.extendZoom = extendLevel;			// Show Extend Polyline at Zoom 3
	this.actualZoom = startZoom;			// Start with zoom 0
	
}

	// Find a Google Zoom in zoom array and return is index  
	classTLocatorZoom.prototype.findZoomInArray = function(Gzoom)
	{
			for (var i = this.maxZoom; i >= this.minZoom; i--)
			{
				if(this.zoom[i] <= Gzoom)
					return i;
			}
	}

	// Get actual zoom and return Google Zoom 
	classTLocatorZoom.prototype.getZoom = function()
	{
		return this.zoom[this.actualZoom];
	}

	// INSTANCE  GLOBAL
	var mapZoom = new classTLocatorZoom(new Array(3, 5, 7, 9, 11, 13, 15, 17), 3, 0);

	
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
// Show zoom level in the zoom level menu with red color

function updateZoomMenu()
{
	for (var i=0; i<mapZoom.zoom.length; i++)
	{
		var id = i + ""; // String Transformation
		document.getElementById(id).style.backgroundColor ='#979F7A';
	}
			
	var zoomId = mapZoom.actualZoom;
	zoomId += '';
	document.getElementById(zoomId).style.backgroundColor ='#FF1009';
}


//-------------------------------------------------------------------------------------------
// Zoom out

function zoomOut()
{
	if(mapZoom.actualZoom == mapZoom.minZoom)
		alert(lang(5)); // message - You have reached the minimum zoom level of the map
	else{	
		mapZoom.actualZoom--;
		
		// If zoom minimun(3) - Show MAP Canada and center with CanadianView
		if (mapZoom.actualZoom == mapZoom.minZoom) 
		{
			document.getElementById("canadaDiv").style.display = "block"; 
			perform("map.setCenter(CanadianView, mapZoom.getZoom())");
		}
		else	// Apply new zoom
			perform("map.setZoom(mapZoom.getZoom())");	
	}
}


//-------------------------------------------------------------------------------------------
// Zoom in

function zoomIn()
{
	if(mapZoom.actualZoom == mapZoom.maxZoom)
	{
		alert(lang(6)); // message - You have reached the maximun zoom level of the map
		hideLoadingMsg();
	}else{
		mapZoom.actualZoom++;
		perform("map.setZoom(mapZoom.getZoom())");	// Apply new zoom
	}
}


//-------------------------------------------------------------------------------------------
// Manuel Zoom 

function manuelZoom(value, item)
{
	// If it's not a red zoom (actual zoom)
	if(item.backgroundColor != "#ff1009" && item.backgroundColor != "rgb(255, 16, 9)")
	{
		hideZoomMenu();					// Close menu
		mapZoom.actualZoom = value;		// new zoom value
		
		// If zoom minimun(3) - Show MAP Canada and center with CanadianView
		if (mapZoom.actualZoom == mapZoom.minZoom) 
		{
			document.getElementById("canadaDiv").style.display = "block"; 
			perform("map.setCenter(CanadianView, mapZoom.getZoom())");
		}
		else	// Apply new zoom
			perform("map.setZoom(mapZoom.getZoom())"); 
	}
}

