// JavaScript Document
jQuery(document).ready(function($) {
	
	if ($("input[placeholder]").length > 0) {
		$('label').filter(function(index) {
		  return $(this).attr('for') == $("input[placeholder]").attr('id');
		}).remove();
		if ( !supports_input_placeholder() ) {
			$("input[placeholder]").css('color', '#a9a9a9');
			activatePlaceholders();
		}
	}
	
	/*
	
	*/
	
	// TODO: eventually replace with better jQuery code.
	function activatePlaceholders() {
		var inputs = document.getElementsByTagName('input');
		for (var i=0;i<inputs.length;i++) {
			if (inputs[i].getAttribute('type') == 'text') {
				if (inputs[i].getAttribute('placeholder') && inputs[i].getAttribute('placeholder').length > 0) {
					inputs[i].value = inputs[i].getAttribute('placeholder');
					inputs[i].onfocus = function() {
						if (this.value == this.getAttribute('placeholder')) {
							this.value = '';
							this.style.color = '';
						}
						return false;
					}
					inputs[i].onblur = function() {
						if (this.value.length < 1) {
							this.value = this.getAttribute('placeholder');
							this.style.color = '#a9a9a9';
						}
					}
				}
			}
		}
	}
	
	/*jQuery(document).bind("ready", function(event) {
	  jQuery(".placeholder").each(function(element) {
	
		var element = jQuery(element);
		var text = element.attr("rel");
		var form = item.parents("form:first");
	
		if (item.val() === "") {
		  item.val(text);
		}
	
		item.bind("focus.placeholder", function(event) {
		  if (item.val() === text)
			item.val("");
		});
	
		item.bind("blur.placeholder", function(event) {
		  if (item.val() === "")
			item.val(text);
		});
	
		form.bind("submit.placeholder", function(event) {
		  if (item.val() === text)
			item.val("");
		});
	  });
	});*/
	
	
	
	/*$('input[type=text]').focus(function(){ 
		if( $(this).val() == $(this).attr('placeholder') ) {
			$(this).val('');
		}
	});
	$('input[type=text]').blur(function(){
		if($(this).val() == '') {
			$(this).val($(this).attr('placeholder'));
		} 
	});*/

	
	// thanks Dive into HTML5
	function supports_input_placeholder() {
		var i = document.createElement('input');
		return 'placeholder' in i;
	}
});