var layersChecked = new Array();	//true if layer is currently enabled

// getInfoURLParameter
// extracts data after the "?" from the URL
// nameLocation is the name of the location which we currently are viewing the more information page of
// layers is an array of numbers, either 0 or 1, for the status of each respective layer
//                 0 means layer is off
//                 1 means layer is on
// returns an object of the nameLocation and layers array
function getInfoURLParameter()
{
	var temp;
	var dataFromURL = window.location.href;

	if(dataFromURL.indexOf("?") > -1 ){
		
		var currentSelection="current";

		if(dataFromURL.substring(dataFromURL.indexOf("?")+ 1).indexOf("?") > -1)
			currentSelection = dataFromURL.substring(dataFromURL.indexOf("?") + 1 , dataFromURL.indexOf("=")-2);

		var currentLocation = dataFromURL.substring(dataFromURL.indexOf("=") + 1, dataFromURL.indexOf("&")).split(',');
		dataFromURL = dataFromURL.substring(dataFromURL.indexOf("&") + 1);
		
		currentLocation[0] *= 1;
		currentLocation[1] *= 1;
		var latLng = {y : currentLocation[0], x : currentLocation[1]};
		
		var currentZoom = dataFromURL.substring(dataFromURL.indexOf("=") + 1, dataFromURL.indexOf("&"));
		dataFromURL = dataFromURL.substring(dataFromURL.indexOf("&") + 1);
		currentZoom *= 1;
		
		var mapType = dataFromURL.substring(dataFromURL.indexOf("=") + 1, dataFromURL.indexOf("&"));
		dataFromURL = dataFromURL.substring(dataFromURL.indexOf("&") + 1);

		var mapSec = dataFromURL.substring(dataFromURL.indexOf("=") + 1, dataFromURL.indexOf("&"));
		
		var layers;
		layers = dataFromURL.substring(dataFromURL.indexOf("&l=") + 3);
		
		return {currentSelection : currentSelection, latLng : latLng, currentZoom : currentZoom, mapType : mapType, mapSec : mapSec, layers : layers};
	}	

	return {currentSelection : "none", latLng : "none", currentZoom : 16, layers : "none", mapSec : "main", mapType : "campus"};
}

urlDataNoMap = getInfoURLParameter();	// this is the object where we store our data received from another page

// showMapLocation
// when "Show this location on the map" is clicked this function is called
// returns to the map sending the building name and layer information in the URL

// To return to a map using the query string, the link must contain 'viewMap'
// For secondary maps they must follow the naming convention 'viewMap-{Sec Map Directory name}'
// examples:
// <a href=javascript:showMapLocation('viewMap')>View Campus Map</a>
// <a href=javascript:showMapLocation('viewMap-special')>View Special Map</a>

// For secondary pages the link must match the string in the first element in the markerDataArray
// If a secondary map location is going to have its own page, the naming convention must
// be '{Sec Map Location}-{Sec Map Directory name}'
// examples:
// <a href=javascript:showMapLocation('braden_auditorium_bra')>Braden Auditorium</a>
// <a href=javascript:showMapLocation('braden_auditorium_bra-special')>Special Event @ Braden Auditorium</a>

function showMapLocation(location)
{
	var goToMap, url;

	//Determine if link wants to go to main map or a secondary map
	//Sets the url for correct folder (root or sec map directory)
	if (location.indexOf('-') > -1)
	{
		goToMap=location.substring(location.indexOf('-') + 1);
		url="/" + goToMap + "/";
	}
	else
	{
		goToMap="main"
		url= "/";
	}

	//If the location is set to viewMap, then there is no new location to link to
	if (location.indexOf('viewMap') > -1)
	{
		location="";
	}

	//If the user wants to return to the map they just came from and
	//and the map to be in the same state as they left it.
	//No new location had beed chosen.
	if (urlDataNoMap.layers!="none" && urlDataNoMap.mapSec==goToMap && location=="")
	{
		url = url + "?s=" + urlDataNoMap.currentSelection +  "&l=" + urlDataNoMap.latLng.y + "," + urlDataNoMap.latLng.x + "&z=" + urlDataNoMap.currentZoom + "&t=" + urlDataNoMap.mapType + "&m=" + urlDataNoMap.mapSec + "&l=" + urlDataNoMap.layers;
	}
	//New location chosen by user
	else if (location != "")
	{
		//Came from Sec Map and a Location was chosen that isn't on the secondary map
		//Redirects to main map
		//At the time of writing this, only locations found under security apply
		if (urlDataNoMap.mapSec != goToMap)
		{
			url = url + "?s=" + location;
		}
		//New Location chosen that returns to the map they just came from
		else if (urlDataNoMap.layers!="none")
		{
			var locationCords = urlDataNoMap.latLng.y + "," + urlDataNoMap.latLng.x;
			url = url + "?s=" + location +  "&l=" + locationCords + "&z=" + urlDataNoMap.currentZoom + "&t=" + urlDataNoMap.mapType + "&m=" + urlDataNoMap.mapSec + "&l=" + urlDataNoMap.layers;
		}
		//No query string
		//Goes to location on specified map
		else
		{
			url = url + "?s=" + location;
		}
	}
	
	window.location.href=url;
}

//Not being implemented
//For turning off elements not needed when displaying secondary pages
//as a modal window on the main map window in an iframe.
function iframeFix()
{
	var dataFromURL = window.location.href;

	if(dataFromURL.indexOf("iframe") > -1)
	{
		document.getElementById('layerIGuide').style.display="none";
		document.getElementById('layerMast').style.display="none";
		document.getElementById('layerNavigation').style.display="none";
		document.getElementById('searchBox').style.display="none";
		document.getElementById('hiddenInfo').style.display="none";
		document.getElementById('layerFooter').style.display="none";
		document.getElementById('showOnSec').style.display="none";
		document.getElementById('wrapBody').style.paddingTop="0px";
		document.getElementById('share_print').style.display="block";
	}
	document.getElementById('hidePage').style.display="none";
}