var fhiMap; //global to refer to the map

$(document).ready(function(){
	var mapOptions = {
		"mapCanvas": "mapCanvas"
	}
	fhiMap = new Map_constructor(mapOptions);
	fhiMap.initMap(); //write the map
	
	var theDate = new Date(); //js date object for today, TODO: this is client based, should we use server date?
	var daysAhead = 14; //set a default to two weeks ahead, this should never be used becasue we update it below
	
	switch(theDate.getDay()){ //calculate the number of days ahead to show, TODO: this could be a forumla, TODO: might be better if this were data driven?
		case 0: //Sunday
			daysAhead = 12;
			break;
		case 1: //Monday
			daysAhead = 11;
			break;
		case 2: //Tuesday
			daysAhead = 10;
			break;
		case 3: //Wednesday
			daysAhead = 9;
			break;
		case 4: //Thursday
			daysAhead = 8;
			break;
		case 5: //Friday
			daysAhead = 14;
			break;
		case 6: //Saturday
			daysAhead = 13;
			break;
	}

	var datePickerOpts = {
		"dayNamesMin": ["S","M","T","W","Th","F","Sa"],
		"gotoCurrent": true,
		"maxDate": daysAhead,
		"minDate": theDate,
		"hideIfNoPrevNext": true,
		"showOtherMonths": true,
		"selectOtherMonths": true,
		"dateFormat": "@", //use unix timestamp
		"onSelect": function(){
			fhiMap.filterDate(this.value);
		}
	}
	$('#constructionDateCalendar').datepicker(datePickerOpts); //create the datepicker

	$('#searchTown').bind('change',function(){ //listen for change of the search town select box
		fhiMap.getLatLng(this.value);
	});

	$('#searchAddressBtn').bind('click',function(){ //listen for click of the search address button
		fhiMap.getLatLng($('#searchAddress').val());
	});

	$('#controlForm').bind('submit',function(){ //prevent the form from submitting
		return false;
	});

	$('#searchAddress').bind('keypress',function(event){ //if the user hits enter in the address search box, submit the search
		if(event.which=='13'){
			$('#searchAddressBtn').click();
		}
	});
	
	//$('#cleanWaterProjects').bind('click',function(){ //listen for a click on the cleanWater checkbox
	//	fhiMap.toggleCleanWaterLayer(this.checked);
	//});
});

