/*
 *  @author: Thomas Pink | Netural Communication | t.pink@netural.com
 *  @version: 1.1
 */
(function($){
    var _this = null;
    var methods = {
        init: function(options){
            return this.each(function(){
                methods.showHideLabel($(this));
                $(this).bind("focus.behindscenes",methods.gotFocus);
                $(this).bind("blur.behindscenes",methods.lostFocus);
            });
            
        },
        destroy: function(){
            return this.each(function(){
                $(this).unbind('.behindscenes');
            })       
        },
        gotFocus: function() {
            var label = $(this).parent().children('label[for="'+$(this).attr("id")+'"]');
            label.addClass("labelfocus");
            methods.showHideLabel($(this));
        },
        lostFocus: function() {
            var label = $(this).parent().children('label[for="'+$(this).attr("id")+'"]');
            label.removeClass("labelfocus");
            methods.showHideLabel($(this));
        },
        showHideLabel: function(input) {
            var label = input.parent().children('label[for="'+(input).attr("id")+'"]');
            if(label.hasClass('labelfocus') || input.val().length > 0) {
                label.fadeOut(150);
            } else {
                label.fadeIn(150);
            }
        }
    };
    
    $.fn.behindscenes = function(method){
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        }
        else 
            if (typeof method === 'object' || !method) {
                return methods.init.apply(this, arguments);
            }
            else {
                $.error('Method ' + method + ' does not exist on jQuery.behindscenes');
            }   
    }; 
})(jQuery);

