(function($){
		
	var settings = {
		colors : {
			blur : '#bbb',
			focus : '#ddd',
			normal : '#000'
		},
		placeholder : 'Enter Something...'
	}

	var methods = {
		init : function(options) {
			return this.each(function() {
			
				if(options !== undefined) {
					if('validate' in options) {
						methods.validate = options.validate;
					}
				}

				if($(this).is('div')) {
					var str = $(this).text();
					$(this).text('');
					
					if(str) {
						var opts = $.extend({},settings,{placeholder:str},options);
					} else {
						var opts = $.extend({},settings,options);
					} 

					var input = $('<input type="text" class="input-placeholder" value="' + opts.placeholder + '">').css('color',opts.colors.blur).appendTo($(this));
				} else {
					var input = $(this);
					var str = input.val()
					//input.text('');
					input.val('');

					if(str) {
						var opts = $.extend({},settings,{placeholder:str},options);
					} else {
						var opts = $.extend({},settings,options);
					}

					input.addClass('input-placeholder').css('color',opts.colors.blur).val(opts.placeholder);
				}

				$.data($(this)[0],'changed',false);
				input.bind({
					focusin : function() {
						$(this).css('color',opts.colors.focus);
					},
					mouseup : function() {
						if(!$.data($(this)[0],'changed')) {
							if (!$(this)[0].setSelectionRange)
							{ $(this).val(''); }
							else if ($(this)[0].createTextRange)
							{
								var part = $(this)[0].createTextRange();
								if (part.moveStart)
									part.moveStart("character", 0);
								if (part.moveEnd)
								part.moveEnd("character", 0);
								if (part.select)
									part.select();
							}
							else if ($(this)[0].setSelectionRange)
							{
								$(this)[0].setSelectionRange(0,0);
							}
						}
				
					},
					focusout : function() {
					
						if($(this).val() === '') {
							$(this).val(opts.placeholder);
							$.data($(this)[0],'changed',false);

							$(this).bind({
								keydown : function() {
									$.data($(this)[0],'changed',true);
									$(this).val('');
									$(this).css('color',opts.colors.normal);
									$(this).unbind('keydown');
									$(this).unbind('focusin');
								},
								focusin : function() {
									$(this).css('color',opts.colors.focus);
									if (!input[0].setSelectionRange)
									{ $(input[0]).val(''); }
									else if (input[0].createTextRange)
									{
										var part = input[0].createTextRange();
										if (part.moveStart)
											part.moveStart("character", 0);
										if (part.moveEnd)
											part.moveEnd("character", 0);
										if (part.select)
											part.select();
									}
									else if (input[0].setSelectionRange)
									{
										input[0].setSelectionRange(0,0);
									}
								}
							});
						}

						if(!$.data($(this)[0],'changed')) {
							$(this).css('color',opts.colors.blur);
						}

					},
					keydown : function() {
						$.data($(this)[0],'changed',true);
						$(this).val('');
						$(this).css('color',opts.colors.normal);
						$(this).unbind('keydown');
						$(this).unbind('focusin');
					}
				});
			});
		},
		destroy : function() {
			if($(this).is('div')) {
				$(this).find('input').remove();
			} else {
				$(this).unbind('keydown').unbind('focusin').unbind('focusout').unbind('mouseup');
				$(this).removeClass('input-placeholder');
			}

		},
		length : function() {
			if($(this).is('div')) {
				return $(this).find('input').val().length;
			} else {
				return $(this).val().length;
			}
		},
		isActive : function() {
			return !$.data($(this)[0],'changed');
		},
		validate : function() {
			return $.data($(this)[0],'changed');
		}
	}

		
	$.fn.placeholder = function(method) {
		// Meithod calling logic
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.simple.placeholder' );
		}
	}
})(jQuery);
