//-- Add support for placeholder attribute on input fields for old browsers that don't support it
//-- Props to http://www.cssnewbie.com/cross-browser-support-for-html5-placeholder-text-in-forms/ where this is based off, though improved
jQuery(document).ready(function($) {
	$.support.inputPlaceholder = false;
	$.support.textareaPlaceholder = false;
	
	var testInput = document.createElement('input');//-- Some browsers don't support placeholder at all
	if ('placeholder' in testInput) {
		$.support.inputPlaceholder = testInput;
	}
	
	var testTextarea = document.createElement('textarea');//-- Some browsers support placeholder on input, but not on textarea
	if ('placeholder' in testTextarea) {
		$.support.textareaPlaceholder = true;
	}
	
	var selectors = '';
	
	if (!$.support.inputPlaceholder) {
		selectors = 'input:text, input:password, textarea';
	} else if (!$.support.textareaPlaceholder) {
		selectors = 'textarea';
	}
		
	if (!$.support.inputPlaceholder || !$.support.textareaPlaceholder) { 
		var active = document.activeElement;
		$(selectors).live('focus', function () {
			if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
				$(this).val('').removeClass('has-placeholder');
			}
		}).live('blur', function () {
			if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
				$(this).val($(this).attr('placeholder')).addClass('has-placeholder');
			}
		});
		$(selectors).blur();
		$(active).focus();
		$('form').live('submit', function () {
			$(this).find('.has-placeholder').each(function() { $(this).val(''); });
		});
	}
});
