$.fn.hint = function () {
    return this.each(function () {
        var input = $(this);
        if (input.attr('type')!='text' && input[0].tagName != 'TEXTAREA'){
            return;
            }
        
        var form = $(this.form);
        var label = form.find('label[for=' + $(this).attr('id') + ']');
        var text = label.text()
        label.hide();
        
        function remove() {
            if (input.val() === text && input.hasClass('blur')) {
                input.val('').removeClass('blur');
                }
            }

        input.blur(function () {
            if (this.value === '') {
                input.addClass('blur').val(text);
            }
        }).focus(remove).blur();
        form.submit(remove);
        $(window).unload(remove); // handles Firefox's autocomplete
    });
};

$(document).ready(function(){
	/* Input Hints */
    $("input.search_q").hint();
    $("textarea#user_details_text").hint();
    $("#video_details_text").hint();
    $(".smartform textarea").hint();

	/**** Autocompletion ****/
	/* The guy that wrote this plugin was retarded - json dude.*/
	
	/*Top Search Bar */
	$("input.search_q").autocomplete("/search/autocomplete", {
		formatItem: function(item) {
			return item[0].split(":")[1];
  		}
	}).result(function(event, item) {
  		location.href = item[0].split(":")[0];
	});

	/* Save changes button autoshow*/
	$(".save_change").each(function(){
		var x = $(this);
		x.hide();
		$("#" + $(this).attr('rel')).focus(function(){
			x.slideDown('fast');
		});
	});
});



