$(document).ready(function() {
	var remember_nav = true;

	/**
	  * Get all input elements and  use some JS to make the IE :hover work and make the form nice and pretty :-)
	  **/
	if($('input.field') != null) {
		$('input.field').each(function() {
			// Mouseover effect
			$(this).mouseover(function() {
				$(this).addClass('fhover');
			});
			// Mouseout effect
			$(this).mouseout(function() {
				$(this).removeClass('fhover').addClass('field');
			});
			// Focus effect
			$(this).focus(function() {
				$(this).addClass('ffocus');
			});
			// Blur effect
			$(this).blur(function() {
				$(this).removeClass('ffocus').addClass('field');
			});
		});
	}

	if($('textarea.tarea') != null) {
		$('textarea.tarea').each(function() {
			// Mouseover effect
			$(this).mouseover(function() {
				$(this).addClass('thover');
			});
			// Mouseout effect
			$(this).mouseout(function() {
				$(this).removeClass('thover').addClass('tarea');
			});
			// Focus effect
			$(this).focus(function() {
				$(this).addClass('tfocus');
			});
			// Blur effect
			$(this).blur(function() {
				$(this).removeClass('tfocus').addClass('field');
			});
		});
	}

	/**
	  * Focus on the first form item if available
	  **/
	setInitialFocus();

	$('#loading_area').ajaxStart(function() {
		$(this).show();
	});


});

function setInitialFocus() {
	var found = false;

	for (f=0; f < document.forms.length; f++) {
		for(i=0; i < document.forms[f].length; i++) {
			if (document.forms[f][i].type != "hidden" && document.forms[f][i].disabled != true) {
				document.forms[f][i].focus();
				found = true;
			}

			if (found == true) {
				break;
			}
		}

		if (found == true) {
			break;
		}
	}
}
