$(document).ready(function()
{

	//SetupDedicationsScroller();

	// Setup external links
	SetupExternalLinks();
	
	//	Convert city search to dropdown boxes
	SetupCitySearcher();
	
	//	Setup date pickers
	//SetupDatePickers();
	
	SetupDeleteVerifications();
});


function SetupDedicationsScroller()
{
	swfobject.embedSWF("/_flash/dedications.swf", "walk-toward-cure", "430", "55", "7.0.19.0");
}


function SetupDatePickers()
{
	Date.format = 'yyyy-mm-dd';
	$('input.date-picker').datePicker();
}

function SetupExternalLinks()
{
	$("a.external").click(function()
	{
		window.open($(this).attr("href"), "SuperWalkWindow");
		return false;
	});
	$("a.popup").click(function()
	{
		window.open($(this).attr("href"), "SuperWalkWindow");
		return false;
	});
}


function SetupCitySearcher()
{	
	// Replace the link with a select box
	$(".city-searcher").html("<select id=\"city-searcher-province\" name=\"province\"></select>");
	
	//	Populate the select box via an XHR
	$("#city-searcher-province").addOption("--", " ");
	$("#city-searcher-province").ajaxAddOption("/_app/superwalks.php", null, false);
	$("#city-searcher-province").selectOptions("--", true);
	
	
	//	Handle Province selection
	$("#city-searcher-province").change(function()
	{
		// Skip the "please select" first option
		if( $("#city-searcher-province").selectedValues()[0] == "--")
		{
			$("#city-searcher-city").remove();
			return false;
		}
		
		if( $("#city-searcher-city").length <= 0 )
		{
			$(".city-searcher").append("<select id=\"city-searcher-city\" name=\"city\"></select>");
		}
		else
		{
			$("#city-searcher-city").removeOption(/./);
		}
		
		$("#city-searcher-city").ajaxAddOption("/_app/superwalks.php?province=" + $("#city-searcher-province").selectedValues()[0], null, false);
		
		$("#city-searcher-city").change(function()
		{
			// Skip the "please select" first option
			if( $("#city-searcher-city").selectedValues()[0] == "--")
			{
				return false;
			}
			window.location ="/city.php?city=" + $("#city-searcher-city").selectedValues()[0];
		});
	});
}


function SetupDeleteVerifications()
{
	
	$('a.record-delete').click(function(){
		return confirm("Are you sure you want to permanently delete this record?");
	});
}