/*
 *   V I D I V I C I
 *   M M X ~ M M X I
 *   Omnia iura reservata.
 */

(function( $ ){

    var methods = {
        init : function() {
            $(this).before('<div class="progressSpinner"></div>');
            $(this).click(function() {
                $(this).submitSpinner('start');
                if ($(this).is('input[type="submit"]')) {
                    $(this).closest('form').submit();
                    return false;
                }
            });
        },
        stop : function() {
            $(this).prev().animate({opacity: "0"}, 300);
            $(this).removeAttr('disabled');
        },
        start : function() {
            $(this).prev().animate({opacity: "1"}, 300);
            $(this).attr('disabled', 'disabled');
        }
    }

    // New name for it
    $.fn.ajaxSpinner = 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.ajaxSpinner' );
        }
    }

    // Deprecated name for it
    $.fn.submitSpinner = 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.submitSpinner' );
        }
    };

})( jQuery );

