﻿$.extend($.ui.progressbar.animations, {
    fancy: function(e, options) {
        //  set the width to zero
        $(e).width(0);
        //  animate
        var args = arguments;
        $(e)
                .animate({ width: '75%' }, options.speed)
                .animate({ width: '25%' }, options.speed)
                .animate({ width: '100%' }, options.speed)
                .animate({ width: '0%' }, options.speed, function() { args.callee.call(this, e, options); });
    },
    glow: function(e, options) {
        //  set the width to zero
        $(e).css({ opacity: '0.1', width: '0px' });
        //  animate
        var args = arguments;
        $(e)
                .animate({ width: '100%' }, { duration: options.speed, queue: false })
                .animate({ opacity: '1.0' }, options.speed)
                .queue(function() {
                    $(this).width(0);
                }).dequeue()
                .animate({ width: '100%' }, { duration: options.speed, queue: false })
                .animate({ opacity: '0.1' }, options.speed, function() { args.callee.call(this, e, options); });
    }
});    

function ViewProgress() {
    $('#glow .progress').progressbar({ animation: 'glow', autostart: false });
    $('#glow .progress').progressbar('start');
}
function PollingFileTransferProgress() {
    setTimeout(function() {
        CheckFileTransferProgressByWs(1,
            function(val) {
                if (val < 100) {
                    $('#progressval').html(val + ' %');
                    setTimeout(function() { PollingFileTransferProgress() }, 5000);
                }
                else {
                    setTimeout(function() { HideProgressBar(); }, 5000);
                }
            },
            function() { HideProgressBar(); }
            )
    },
            5000);
}
function ViewFileTransferProgress() {
    $('#glow .progress').progressbar({ animation: 'glow', autostart: false });
    CheckFileTransferProgressByWs(1,
        function(val) {
            centerPopup(); loadPopup();
            $('#glow .progress').progressbar('start');
            $('#glow .progress').progressbar({ value: val });
            $('#progressval').html(val + ' %');
            setTimeout(function() { PollingFileTransferProgress() }, 5000);
        }, function() { HideProgressBar(); }
        );
    }
    function ViewFileTransferProgress2(deviceid, OnEnd) {
        $('#glow .progress').progressbar({ animation: 'glow', autostart: false });
        CheckFileTransferProgressByWs(deviceid,
        function(val) {
            if (val < 100) {
                centerPopup(); loadPopup();
                $('#glow .progress').progressbar('start');
                $('#glow .progress').progressbar({ value: val });
                $('#progressval').html(val + ' %');
            }
            else { HideProgressBar(deviceid); OnEnd(); }
        }, function() { HideProgressBar(deviceid); OnEnd(); }
        );
    }

    function HideProgressBar(id) {HideProgressBay(id,false); }
    function HideProgressBar(id,resetfileprogress) {        
        $('#glow .progress').progressbar('stop');
        $('#glow .progress').progressbar({ value: 100 });
        $('#progressval').html('100 %');
        disablePopup();
        if (resetfileprogress) { ResetFileTransferProgress(id); }
    }

