////////////////////////////////////////////////////////////////////////////////
// Zoom to town currently selected on the town dropdown.
////////////////////////////////////////////////////////////////////////////////
function zoom_town()
{
   	var w = document.town.townList.selectedIndex;
   	var selected_text = document.town.townList.options[w].value;

	if (selected_text == 'All')
		zoomToAll();
	if (selected_text == 'City Centre')
		zoomToCityCentre();
	if (selected_text == 'Headingley')
		zoomToHeadingley();
	if (selected_text == 'Leeds Metropolitan University')
		zoomToLeedsMetropolitanUniversity();
	if (selected_text == 'University of Leeds')
		zoomToUniversityofLeeds();
	if (selected_text == 'Roundhay Park')
		zoomToRoundhayPark();
	if (selected_text == 'Temple Newsam')
		zoomToTempleNewsam();
	if (selected_text == 'Elland Road')
		zoomToEllandRoad();
}

function zoomToAll()
{
    zoomTo(-1.544266,53.805922,11);
}

function zoomToBeeston()
{
    zoomTo(-1.567612,53.771645,13);
}

function zoomToCityCentre()
{
    zoomTo(-1.545467,53.799333,13);
}

function zoomToHeadingley()
{
    zoomTo(-1.5833,53.8168,13);
}

function zoomToLeedsMetropolitanUniversity()
{
    zoomTo(-1.593,53.8268,13);
}

function zoomToUniversityofLeeds()
{
    zoomTo(-1.5539,53.8081,13);
}

function zoomToRoundhayPark()
{
    zoomTo(-1.5025,53.834,13);
}

function zoomToTempleNewsam()
{
    zoomTo(-1.4669,53.7844,13);
}

function zoomToEllandRoad()
{
    zoomTo(-1.5715,53.7779,13);
}


////////////////////////////////////////////////////////////////////////////////
//Show the map. 
////////////////////////////////////////////////////////////////////////////////
function showEvent(systemCodeNumber)
{
	mapFrame.location = '../map/map.jsp?lon=-1.544266&lat=53.805922&town=All&zoom=14&id=' + systemCodeNumber;
}
 // Map options
function MapOptionsObject(){

	var toggleCount = 0;
	var scrollTimeout = 0;
	var scrollStep = 50;

	this.toggleKey = function() {
	
		if(scrollTimeout==0){
	
		if(toggleCount%2 == 0){
			toggleCount = 1;
			this.scrollKeyDown();
		}
		else{
			toggleCount = 0;
			this.scrollKeyUp();			
		}
		
		}
	
	}

	this.scrollKeyDown = function() {
	
		clearTimeout(scrollTimeout);
		scrollTimeout = 0;
		
		var maxScrollHeight = dwr.util.byId("map_options_frame").offsetHeight + 5;
		var shutterObject = dwr.util.byId("map_options_shutter");
		
		this.doScrollKeyDown(shutterObject,maxScrollHeight);
		
	}
	
	this.doScrollKeyDown = function(shutterObject,maxScrollHeight) {
	
		var currentHeight = shutterObject.offsetHeight;
		
		if(currentHeight < (maxScrollHeight - scrollStep)){
			shutterObject.style.height = (currentHeight + scrollStep) + "px";	
			scrollTimeout = setTimeout(function(){mapOptions.doScrollKeyDown(shutterObject,maxScrollHeight)},10);
		}
		else{
			shutterObject.style.height = maxScrollHeight + "px";
			clearTimeout(scrollTimeout);
			scrollTimeout = 0;
		}
	
	}

	this.scrollKeyUp = function() {
	
		clearTimeout(scrollTimeout);
		scrollTimeout = 0;
	
		var minScrollHeight = 0;
		var shutterObject = dwr.util.byId("map_options_shutter");
	
		this.doScrollKeyUp(shutterObject,minScrollHeight);
		
	}
	
	this.doScrollKeyUp = function(shutterObject,minScrollHeight) {
	
		var currentHeight = shutterObject.offsetHeight;
		
		if(currentHeight > (minScrollHeight + scrollStep)){
			shutterObject.style.height = (currentHeight - scrollStep) + "px";	
			scrollTimeout = setTimeout(function(){mapOptions.doScrollKeyUp(shutterObject,minScrollHeight)},10);
		}
		else{
			shutterObject.style.height = minScrollHeight + "px";
			clearTimeout(scrollTimeout);
			scrollTimeout = 0;
		}
	
	}

}
