$(document).ready(function(){

	$("body").addClass("jsok");

	$.jqwidont.auto(false);
	$('p')
		.filter(function(){
			// Exclude paragraphs with form controls
			return $(this).find(":input").size() == 0;
		})
		.widont();

	if ( $("body").attr("id") == "directions" ){

		$('#map').jmap('init',{
			'mapType': G_NORMAL_MAP,
			'mapCenter': [40.8722, -81.3637],
			'mapZoom': 13,
			'mapShowjMapsIcon': false,
			'mapEnableType': true
		});

		var showdefaultpin = function(){
			$('#map').jmap('AddMarker',{
				'pointLatLng': [40.8722, -81.3637],
				'pointHTML': '<span id="map-cgbcpoint"><b>Canton Grace Brethren Church</b><br />6283 Market Avenue North<br />Canton, Ohio 44721</span>',
				'centerMap': true
			}, function(marker, options){
				$('#mapform').bind('submit', function(){
					$('#map').jmap('RemoveMarker', marker);
					return false;
				});
			});
		};
		showdefaultpin();

		$('#mapform').bind('submit', function(){

			// Begin directions search
			$('#map').jmap('SearchDirections',{
				'query': $('#mapform-address').val() + ' to 6283 Market Avenue North, Canton, Ohio 44721',
				'returnType': 'getLocations',
				'panel': '#map-directions'
			}, function(result, options){

				// Hide error message
				$("#errormsg").hide().text("");
				if (result.getStatus().code !== 200){
					// Got an error, show message
					$("#errormsg").show().text("Oops! We couldn't look up the address you entered. Try another?");
					// Place default pin and center map
					showdefaultpin();
				}

			});

			return false;

		});
	} // if ( $("body").attr("id") == "directions" )
});