$(document).ready(function() {
	
	$(document).ajaxError(function() {
		if(window.console && window.console.error) {
			console.error(arguments);
		}
	});
		 
	$.ajaxSettings.traditional = true;      // Workaround for jquery-1.4.x auto serialization in url (see $.param() )
												// TODO: fix is to treat the second parameter in the result callback of an autocomplete as an array.
	
	Galleria.loadTheme('/js/plugins/galleria/themes/classic/galleria.classic.min.js');
	
	
	
	///// Hinting  //////////////////////
	//
	$(":input").live('focusin', function() {
		var $this = $(this);
		$this.css('background-color', "#F3EDB6");
		if($(this).hasClass('hinted')) {
			$(this).attr('value', '');		// Clear the hint
			$(this).removeClass('hinted');  // Remove hinted class so it won't apply to new input
		}
	}).live('focusout', function() {
		$(this).css('background-color', '#fff');
		if($(this).val() == '') {
			if($(this).attr('hint') != '') {
				
				var hint = $(this).attr('hint'); // derive the hint from the tag attribute
				$(this).addClass('hinted');		 // reset the hinting class
				$(this).val(hint);				 // restore the value of the hint
			}
		}
		
	});
	
	//
	///////////////
	
	$(".external").live('click', function(e) {
		var href = $(this).attr("href");
		
		var twin = window.open(href);
		e.preventDefault();
	});
	
	/////////////////
	// Poor man's vertical accordion
	$(".seclabel").live('click', function() {
		if($(this).hasClass('openSec')) {
			$(this).removeClass('openSec').next().slideUp();
		}
		else {
			$(".openSec").removeClass('openSec').next().slideUp();
			$(this).addClass('openSec').next().slideDown();
		}
	}).mouseover(function() {
		$(this).addClass('over');
	}).mouseout(function() {
		$(this).removeClass('over');
	});
	
});
