/** Helps with basic tab functionality.
 * Joshua Logsdon
 * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License
 * Requires: jQuery v1.3+
 */
// Avoid collisions
;if(window.jQuery) (function($) {
	
	// plugin definition
	$.fn.logsdon_toggle_val = function(options)
	{
		// Extend our default options with those provided.
		// Note that the first arg to extend is an empty object -
		// this is to keep from overriding our "defaults" object.
		var opts = $.extend({}, $.fn.logsdon_toggle_val.defaults, options);
		
		// Other way of extending default options without needing properties
		//var config = {'foo': 'bar'};
		//if (settings) $.extend(config, settings);
		
		// Plugin code
		this.each(function()
		{
			var $input = $(this);
			// Combine classes for toggling, removing spaces in case either is blank
			var blur_and_focus_classes = (opts.blur_class +' '+ opts.focus_class).replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			
			if ( $input.val() == '' )
			{
				$input.toggleClass( opts.blur_class )
					.val( opts.default_val );
			}
			
			$input.focus(function(){
				if ( $input.val() == opts.default_val )
				{
					$input.toggleClass( blur_and_focus_classes )
						.val('');
				}
			}).blur(function(){
				
				if ( opts.sticky == true && $input.val() == '' )
				{
					$input.toggleClass( blur_and_focus_classes )
						.val( opts.default_val );
				}
			});
			
			return;
		});
	
		return this;
	};
	
	// plugin defaults - added as a property on our plugin function
	$.fn.logsdon_toggle_val.defaults = {
		'default_val': '',
		'sticky': true,
		'blur_class': '',
		'focus_class': ''
	};
	
	/*
	// Default implementation
	$(document).ready(function() {
		$('.toggle_val').logsdon_toggle_val({
			'default_val': 'test', 
			'sticky': true, 
			'blur_class': 'italic'
		});
	});
	*/
	
// Avoid collisions
})(jQuery);