// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

jQuery(function() {
	
	// Focus the first input on the page...
	var inputs = jQuery('input[type=text]');
	if(inputs.length > 0) {
		var first_input = inputs[0];
		first_input.focus();
	}
	
	// Turn all our form buttons into pretty buttons...
	var submit_buttons = jQuery("input.submit-button");
	for(var i = 0; i < submit_buttons.length; i++) {
		var submit_button = jQuery(submit_buttons[i]);
		var submit_val = submit_button.val();
		submit_button.before('<a href="#" class="button submit-button" id="submit_button_' + i + '"><span>'+ submit_val +'</span></a>');
		// submit_button.hide();
		submit_button.addClass('hideme');
	
		var new_submit_button = jQuery('#submit_button_' + i);
		new_submit_button.click(function(e) {
			e.preventDefault();
		
			// Update button text 
			var new_submit_val = "Please wait...";
			jQuery(this).html('<span>' + new_submit_val +'</span>');
		
			// Submit form
			var enclosing_form = jQuery(this).parents('form')[0];
			enclosing_form.submit();
		
			// Disable button
			jQuery(this).attr("disabled", true);
	  });
	}
});

