function getFocusedElement() {
	if ($.browser.msie || $.browser.opera) {
		return document.activeElement;
	}
	return null;
}

(function($){
$.fn.overlabel = function() {
    this.each(function(index) {
        var label = $(this); var field;
        var id = this.htmlFor || label.attr('for');
        if (id && (field = document.getElementById(id))) {
            var control = $(field);
            label.addClass("overlabel-apply");
            if (field.value !== '' || field == getFocusedElement()) {
                label.css("text-indent", "-1500px");
            }
            control.focus(function () {label.css("text-indent", "-1500px");}).blur(function () {
                if (this.value === '') {
                    label.css("text-indent", "0px");
                }
            });
            control.keydown(function (e) { 
                var evt = e || window.event;
                if (evt.keyCode != 9) {label.css("text-indent", "-1500px");} 
                return true;
            });
            label.click(function() {
                var label = $(this); var field;
                var id = this.htmlFor || label.attr('for');
                if (id && (field = document.getElementById(id))) {
                    field.focus();
                }
            });
        }
    });
}
})(jQuery);
