//
// add classes to form elements for styling
//
jQuery(document).ready(function($) {
//	$("input:first").focus();	// set cursor at first form element

	// set cursor at first form element, excluding the page search
	$("form").not("#search-form").find("input:first").focus();

	$(":radio").each(function(){ $(this).addClass("radio"); });
	$(":checkbox").each(function(){ $(this).addClass("checkbox"); });

	// text input elements
	$(":text").each(function(){ $(this).addClass("textInput"); });
	$(".textInput").focus(function(){ $(this).addClass("focus"); });
	$(".textInput").blur(function(){ $(this).removeClass("focus"); });
	$("textarea").focus(function(){ $(this).addClass("focus"); });
	$("textarea").blur(function(){ $(this).removeClass("focus"); });

	// buttons
	$(":submit").each(function(){ $(this).addClass("button"); });
	$(":button").each(function(){ $(this).addClass("button"); });
	$(".button").hover(
		function(){ $(this).addClass("hover"); }, 
		function(){ $(this).removeClass("hover"); }
	);
});



//
// fix "display: inline-block" for Mozilla
//
if (document.addEventListener) {
	document.addEventListener('DOMContentLoaded', clean_form, false);
}

function clean_form(){
  // Hide forms
  $( 'form.clean_form' ).hide().end();
  
  // Processing
  $( 'form.clean_form' ).find( 'li > label' ).not( '.noclean' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();

  // Show forms
  $( 'form.clean_form' ).show().end();
}