// Patch jquery for use with Prototype
jQuery.noConflict(); 

/*
 * Usage: 
 *   jQuery("input[name=q]")
 *      .val("Search")    // set an initial value if it doesn't already exist
 *      .clearonfocus();  // prepare the element for clearing on focus
 */

jQuery.fn.clearonfocus = function() {
	jQuery(this)
		.bind('focus', function() {
			jQuery(this).addClass('focus');					
			// Set the default value if it isn't set
			if ( !this.defaultValue ) this.defaultValue = this.value;
			// Check to see if the value is different
			if ( this.defaultValue && this.defaultValue != this.value ) return;
			// It isn't, so remove the text from the input
			this.value = '';
		})
		.bind('blur', function() {
			// If the value is blank, return it to the defaultValue
			if ( this.value.match(/^\s*$/) ) { 
				this.value = this.defaultValue; 
			}
			jQuery(this).removeClass('focus');			
		});
};

jQuery(function() {

	/* add class="last" */
	jQuery('dl:last-child').addClass('last');
	
	/* add class="first" */
	jQuery('h2:first-child').addClass('first');
	
	/* Pander to IE6 inadequacies */
	jQuery('input[type=checkbox]').addClass('checkbox');
	jQuery('input[type=submit]').addClass('submit');
	
	/* Clear text inputs on focus */
	jQuery('input[type=text]').addClass('text');
	//jQuery('input[type=text]').clearonfocus();
	
	/* Add a wrapper to the expanding nav */
	jQuery('body:not(#t_home) #search-nav div.contents').wrap('<div class="scarf"></div>').prepend('<span id="search-nav_gradient_top"></span><span id="search-nav_gradient_bottom"></span>');

	/* Add a wrapper to the expanded nav menu lists */
	jQuery('body:not(#t_home) #search-nav div.contents dl').wrapAll('<div class="list-scarf clearfix"></div>');

	/* Expand and contract on click */
	jQuery('#search-nav_expander').bind('click',function() {
		if(!(jQuery(this).hasClass('open'))) {
			jQuery(this).addClass('open');
			jQuery('#search-nav div.contents').show('slow')
			jQuery('#search-nav div.scarf').addClass('open');
		} else if(jQuery(this).hasClass('open')) {
			jQuery(this).removeClass('open');
			jQuery('#search-nav div.contents').hide('slow');
			jQuery('#search-nav div.scarf').removeClass('open');			
		}
	});

// Using Prototype and Lightview instead as it has a slideshow and just works / looks better dammit.
/*	jQuery("#search-results ul li a").prettyPhoto({
			padding: 35
	});	*/
	
/* Using Prototip instead because it rocks. 
	jQuery('#search-results li a').tooltip({ 
		showURL: false
	}); */
		
});