﻿/*
 * jQuery UI ProgressBar
 *
 * Depends:
 *	ui.core.js
 */
(function($) {
    $.widget("ui.progressbar", {
	    init: function() {
		    //  wrap the element in the required markup
		    $(this.element)
		        //  build the DIV strucutre
		        .html('<div id="progress-indicator"></div><div id="progress-label"></div>');
    		
    		//  kick off the animation
    		if(this.options.autostart){
		        this.start();
		    }
	    },
    	
	    start: function() {
	        var o = this.options;
			
	        //  start the animation
            $('#progress-indicator', this.element)
                //  queue up the animation function
                .queue(function(){$.ui.progressbar.animations[o.animation](this, o);})
                //  and let it rip
                .dequeue();       
	    }	    
    });

    $.extend($.ui.progressbar, {
	    defaults: {
	        autostart:true,
	        interval:5,
	        animation:'slide'
	    },
	    animations : {
	        slide: function(e, options) {
                //  set the width to zero
                bar = $(e);
                div = $("#progress");
                label = $("#progress-label");
                bar.height(0);
                //  animate
                
                var i = 0;
                
                var t = setInterval(function() {
						
						if( i < options.value )
						{
							i++;
						
							if( i <= 1500 )
							{
								var pixels = Math.round( i * 289 / 1500 );
							
								bar.height( pixels );
								div.css("padding-top", ( 373 - pixels ) + "px");
								div.height( 50 + pixels );
							}
							
							label.html( i );
						}
						else
						{
							clearInterval(t);
						}						
					}, options.interval); 
	        }
	    }
    });
})(jQuery);
