/* JS component of the Thoroughbred Heritage Horse Farm Tours website
 * [js/jquery.horse.js]
 * Daniel Ott
 * 10-Feburary-2009
 *
 * Make the site turbo-awesome using jquery effects, ajax, etc.
 */

$(document).ready(function() {

	// Update DOM using JS for accessibility type stuff
	$("body").addClass("with-js");					// Add one class, and screen.css takes care of the rest
	$(".requires-js").removeClass("requires-js");	// Can now show the things that we hid when we thought JS wasn't gonna be involved
	$(".noscript").remove();						// Can get rid of things that having JS makes obsolete.


	
	// Put a google map on the page.  I do it this way so we can say the xhtml source is valid and not be lying.
	$("#google_map_placeholder").html('<iframe width="450" height="200" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;source=embed&amp;s=AARTsJpKlvVdTXnx6SJYNA8h2lmZPrGeJA&amp;msa=0&amp;msid=117312886488730670067.000462825e9e7842a4d52&amp;ll=38.049105,-84.501472&amp;spn=0.006759,0.019312&amp;z=15&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;source=embed&amp;msa=0&amp;msid=117312886488730670067.000462825e9e7842a4d52&amp;ll=38.049105,-84.501472&amp;spn=0.006759,0.019312&amp;z=15" style="color:#0000FF;text-align:left">View Larger Map</a></small>');



	// Make our form nice and usable
	$("#reservation_date").datepicker();
	$("#new_reservation").ajaxForm({dataType: "json", success: function(result) {

		// Update the user interface when the ajax call is done
		$("#reservation_submit").show();
		$("#ajax_progress").hide();
		
		if (result.status == 1) {			// Known error status.
			alert(result.message);
		} else if (result.status == 0) {	// I'm making a note here, huge success.
			$("#new_reservation").html('<h3>Thank you!</h3><p>'+result.message+'</p>');
		} else if (result.status == -1) {	// Unknown error status.
			alert(result.message);
		} else {							// The server has been blown up probably.
			alert("We aren't sure what went wrong, but your reservation request was unable to be sent.  Please call us to ensure a reservation.")
		}

	}, beforeSubmit: function(){

		// Update the user interface
		$("#reservation_submit").hide(); 
		$("#ajax_progress").show();

	}});



	// I don't like Microsoft Internet Explorer, and no one else should either.
	if ($.browser.msie)
		$("#discourage_msie").show();
	else
		$("#discourage_msie").remove();


		
	// The key to making the page all fancy nice scrolly
	$.localScroll({
	   target:"#sections"
	});



	// Make images do neat things.
	$("#images").cycle("fade");
	$("#scroller").cycle({
		fx: 'scrollDown', 
	    timeout: 10000
	});


	
	// Prevent spam, or at least try.
	$.get("token.php", function(txt) {
		$("#new_reservation").append('<input type="hidden" name="reservation[ts]" id="reservation_ts" value="' + txt + '" />');
	});
});