$(function() {initPage()});

/* 	-----------------------------------------------------------
		Initialisation for pages on help.rummble.com
		----------------------------------------------------------- */
		
function initPage() {
		$('table.dataTable').colorize({hiliteColor:'none'}	);
		
		// Initialise the forms with some extra polish 
	  $("#quickLogin input").toggleVal({changedClass: "dirty"});
		
		
		// Show extra fields on quick login while it has focus
		$('form#quickLogin input, form#quickLogin button').focus(function(){
				return $(this.parentNode.parentNode).hasClass('compacted') ? showLoginForm(this.parentNode.parentNode) : false;
		});

		//prevent propagation to the document from the quickLogin form
		$('form#quickLogin').click(function(evt){evt.stopPropagation();}).focus(function(evt){evt.stopPropagation();});
		
		//When clicking on a label with a nested input, give focus to the input
		$('form#quickLogin label').click(function(){alert(this);$(this).children('input').focus();})
		
		//re-collapse the form when anything else in the doc gains focus or is clicked
		$(document).click(function(){quickLoginExpanded ? hideLoginForm('#quickLogin') : false;}).focus(function(){quickLoginExpanded ? hideLoginForm('#quickLogin') : false;});

}

/* 	-----------------------------------------------------------
		Global variables - mostly flags for performance on often-used ops
		----------------------------------------------------------- */
		
		var quickLoginExpanded = false; //remember the last state of the form


/* 	-----------------------------------------------------------	
		Two helper functions for the collapsible login form: 
		----------------------------------------------------------- */
function showLoginForm(form) {$(form).addClass('expanded').children('fieldset.extraFields').slideDown('fast').end().removeClass('compacted');quickLoginExpanded = true;return false;}	
function hideLoginForm(form) {$(form).removeClass('expanded').children('fieldset.extraFields').slideUp('fast', function(){$(this.parentNode).addClass('compacted')}).end();quickLoginExpanded = false;return false;}	
