// create closure
(function($) {
	// plugin definition
	$.fn.fieldtip = function(options) {
		
		// build main options before element iteration
		var opts = $.extend({}, $.fn.fieldtip.defaults, options);
		
		// iterate and adjust each matched element
		return this.each(function() {
			$this = $(this);
			// build element specific options
			var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
			
			// perform plugin actions
			if ($this.val().length == 0) {
				if (o.tipclass != null) {
					$this.addClass(o.tipclass);
				}
				if (o.notipclass != null) {
					$this.removeClass(o.notipclass);
				}
				$this.val($this.attr(o.tipattribute));
			}
			$this.focus( function() {
				$this = $(this);
				if ( $this.val() == $this.attr(o.tipattribute)) {
					if (o.tipclass != null) {
						$this.removeClass(o.tipclass);
					}
					if (o.notipclass != null) {
						$this.addClass(o.notipclass);
					}
					$this.val("");
				}
			}).blur( function() {
				$this = $(this);
				if ( $this.val().length == 0) {
					if (o.tipclass != null) {
						$this.addClass(o.tipclass);
					}
					if (o.notipclass != null) {
						$this.removeClass(o.notipclass);
					}
					$this.val($this.attr(o.tipattribute));
				}
			});
		});
	};
	
	// plugin defaults
	$.fn.fieldtip.defaults = {
		tipattribute: 'title',
		tipclass: 'tip',
		notipclass: null
	};
	
// end of closure
})(jQuery);