$(function() {
	
	// Hide Flash Messages With Close Button
	$('#baseapp-flash .baseapp-icon-left').click(function() {
		$(this).parent().parent().slideUp();
		return false;
	});
	
	// Give Buttons Hover and Active States
	$(function() {
		$("a.baseapp-button:not(.ui-state-disabled), button.baseapp-button:not(.ui-state-disabled)")
			.hover(
				function(){ 
					$(this).addClass("ui-state-hover"); 
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				})
			.mousedown(function() { $(this).addClass("ui-state-active"); })
			.mouseup(function() { $(this).removeClass("ui-state-active"); });
	});
	
	// Change Input Fields Class on Focus
	$('input[type="text"], input[type="password"], textarea').focus(function() {
		$(this).addClass("ui-state-active");
	});
	
	$('input[type="text"], input[type="password"], textarea').blur(function() {
		$(this).removeClass("ui-state-active");
	});
	
	// Change Buttons Class on Focus
	$('.baseapp-button').focus(function() {
		$(this).addClass("ui-state-hover");
	});
	
	$('.baseapp-button').blur(function() {
		$(this).removeClass("ui-state-hover");
	});
	
	$('input.baseapp-focus:last').focus();
	
});

// Setup Ajax To Work Properly With Rails Requests
jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader('Accept', 'text/javascript')} });