/* Textfield Placeholders - jQuery Plugin
 * Author: Palle Zingmark, www.palleman.nu
 * Released with the MIT License: http://www.opensource.org/licenses/mit-license.php
 */
(function($){
	$.fn.TextfieldPlaceholders = function(){
		return this.each(function() {
			var $parent = $(this);
			$parent.find('input:text[value=""]').each(function(i){
				var $input = $(this);
				var $placeholder = $($input).attr('placeholder');
				var $basecolors = ['#000000','rgb(0, 0, 0)'];
				var $color = $($input).css('color');
				var $hascolor = jQuery.inArray($color,$basecolors);
				if(typeof $placeholder == 'undefined' || $placeholder == ''){
					$placeholder = $parent.find('label[for="'+ $($input).attr('id') +'"]').text();
				}
				if(typeof $placeholder == 'string' || $placeholder != ''){//## OR ABORT
					$($input).attr('value', $placeholder);
					$($input).attr('title', $placeholder);
					if($hascolor || $hascolor != -1){
						$(this).css('color','#aeaeae');
					}
					$($input).bind('focus', function(){
						if($(this).attr('value') == $placeholder){
							$(this).attr('value','');
							$(this).css('color',$color);
						}
					}).bind('blur', function(){
						if($(this).attr('value') == $placeholder || $(this).attr('value') == ''){
							$(this).attr('value',$placeholder);
							if($hascolor || $hascolor != -1){
								$(this).css('color','#aeaeae');
							}
						}
					});
				}
			});
		});
	};
})(jQuery);