function placeholderSupport() {
	var testinput = document.createElement('input');
	return !!('placeholder' in testinput);
}

function addPlaceholder(el) {
	// do couple of error checks, return true so outside loop (if one exists) can continue
	if (placeholderSupport() || !el) return true;
	var ph = el.getAttribute('placeholder');
	if (!ph) return true;
	
	// set as placeholder if value is empty and then use class as flag (instead of checking value)
	if (!el.value || el.value=='') {
		if ('password'!=el.getAttribute('type')) el.value = ph;
		$(el).addClass('placeholder');
	}
	
	if ('password'==el.getAttribute('type')) {
		addPlaceholderForPass(el);
	}
	else {
		$(el).focusin(function(){
			if ($(this).hasClass('placeholder')) {
				$(this).removeClass('placeholder');
				$(this).val('');
			}
		});
		
		$(el).focusout(function(){
			if ( $.trim($(this).val())==='' ) {
				$(this).val(ph);
				$(this).addClass('placeholder');
			}
		});
	}
}

function addPlaceholderForPass(el) {
	el = $(el);
	var span = $('<span/>',{
		'class': el.attr('class')+' placeholder',
		text: el.attr('placeholder'),
		css: {
			border:		'none',
			cursor:		'text',
			position:	'absolute',
			background:	'transparent',
			top:		el.position().top,
			left:		el.position().left,
			lineHeight: 22+'px',
			paddingLeft:parseFloat(el.css('paddingLeft'))+3+'px'
		}
	}).insertAfter($(el));
	
	el.focusin(function(){
		if (el.hasClass('placeholder')) {
			span.hide();
			el.removeClass('placeholder');
		}
	});
		
	el.focusout(function(){
		if ( $.trim(el.val())==='' ) {
			span.show();
			el.addClass('placeholder');
		}
	});
	
	// periodically check the password field for content
	// in case an auto form filler has kicked in and filled it
	var flag = false;
	setInterval( function() {
		if (!flag && $.trim(el.val())!='') {
			span.hide();
			flag = true;
		}
	}, 250 );
}

$(document).ready(function(){
	$('input[placeholder]').each( function(i,e){
		addPlaceholder(e);
	});
});

