﻿(function($) {
    $.extend($.ui.progressbar, {
        defaults: {
            value: 0,
            speed: 1000,
            animation: 'slide'
        },
        animations: {
            slide: function(e, options) {
                var barWidth = $(e).parent().width();
                var slideWidth = (barWidth * options.value) / 100;
                //  animate
                var args = arguments;
                $(e).animate({ width: slideWidth }, options.speed, function() { /*args.callee.call(this, e, options);*/ });
            },
            slideback: function(e, options) {
                //  set the width to zero
                $(e).width(0);
                //  animate
                var args = arguments;
                $(e)
                     .animate({ width: $(e).parent().width() }, options.speed)
                     .animate({ width: 0 }, options.speed, function() { args.callee.call(this, e, options); });
            },
            slidethru: function(e, options) {
                //  set the position and left
                $(e).css({ width: 0, position: 'absolute', left: '0px' });
                //  animate
                var args = arguments;
                $(e)
                     .animate({ width: $(e).parent().width() }, options.speed)
                     .animate({ left: $(e).parent().width() }, options.speed, function() { args.callee.call(this, e, options); });
            },
            fade: function(e, options) {
                //  set the width to zero
                $(e).css({ width: 0, opacity: '1.0' });
                //  animate
                var args = arguments;
                $(e)
                     .animate({ width: $(e).parent().width() }, options.speed)
                     .animate({ opacity: '0.0' }, options.speed, function() { args.callee.call(this, e, options); });
            }
        }
    });
})(jQuery);


function AnimateJQueryProgressBar(id, animation, _value, _speed) {
    $.ui.progressbar.animations[animation]($(id), { speed: _speed, value: _value });
}
