var start = new Date(2011, 11 - 1, 18, 1, 10);
/*format YYYY, MM-1, DD, HH, MM*/
var start_time = start.getTime();

var end = new Date(2012, 12 - 1, 19, 1, 1);
var end_time = end.getTime();

(function($) {
    $.fn.progressbar = function(options) {
        var opts = $.extend({}, $.fn.progressbar.defaults, options);
        var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

        if (o.manual == false) {
            var auto_refresh = setInterval(
                function() {
                    var current = new Date();
                    var current_time = current.getTime();
                    var time_max = (end_time - start_time);
                    var time_elapsed = (current_time - start_time);

                    var percent_to_calculate = (time_elapsed * 100) / time_max;
                    var percent = percent_to_calculate.toFixed(0);
                    if (current_time > end_time)
                        percent = 100;

                    var new_top = parseInt(((100 - percent) * o.bar_height) / 100);
                    $this = $(this);
                    $("#progressbar_bar").css('top', new_top + 'px');
                    $("#percent").css('top', new_top - 15 + 'px');
                    var new_height = parseInt((percent * o.bar_height) / 100);
                    $("#progressbar_bar").height(new_height);
                    $("#percent").html(percent + "<span>%</span>");
                    $("#progressbar_bar").show();
                    $("#percent").show();
                }
                , 1000);
        }
        else {
            var percent_value = o.percent;
            var new_top = parseInt(((100 - percent_value) * o.bar_height) / 100);
            $("#progressbar_bar").css('top', new_top + 'px');
            $("#percent").css('top', new_top - 15 + 'px');
            var new_height = parseInt((percent_value * o.bar_height) / 100);
            $("#progressbar_bar").height(new_height);
            $("#percent").html(percent_value + "<span>%</span>");
            $("#progressbar_bar").show();
            $("#percent").show();
        }
    };

    $.fn.progressbar.defaults = {
        percent:0,
        manual:false,
        bar_height:0
    };

})(jQuery);

