//Progress bar widget
//@author mrcaps
var Progress = {
	PROGWIDTH: 200,
	PROGHEIGHT: 30,
	init: function() {
		Overlay.init();
		this.progbox = new Element("div").setStyles({
			"position":"absolute",
			"width":this.PROGWIDTH,
			"height":this.PROGHEIGHT,
			"padding":"3px",
			"border":"1px solid white",
			"z-index":110
		}).injectInside(document.body);
		this.progbox.fx = {};
		this.progbox.fx.height = new Fx.Style(this.progbox, "height");
		window.addEvent("onresize", function() {
			this.setpos();
		}.bind(this));
		this.progbar = new Element("div").setStyles({
			"height":this.PROGHEIGHT,
			"background-color":"#FFFFFF"
		}).injectInside(this.progbox);
		this.progbar.fx = {};
		this.progbar.fx.width = new Fx.Style(this.progbar, "width", {duration:200});
		this.progbar.fx.height = new Fx.Style(this.progbar, "height");
	},
	//show the progress bar
	show: function(immediate) {
		this.showing = true;
		Overlay.show();
		this.progbar.fx.width.set(0);
		this.setpos();
		this.progbox.setStyle("display","block");
		this.progbox.fx.height[(immediate) ? "set" : "start"](this.PROGHEIGHT);
		this.progbar.fx.height[(immediate) ? "set" : "start"](this.PROGHEIGHT).chain(this.fixdisp.bind(this));
	},
	hide: function(immediate) {
		this.showing = false;
		Overlay.hide();
		this.progbox.fx.height.stop();
		this.progbar.fx.height.stop();
		this.progbox.fx.height[(immediate) ? "set" : "start"](0);
		this.progbar.fx.height[(immediate) ? "set" : "start"](0).chain(this.fixdisp.bind(this));
	},
	//fix the displayable state of the bar
	fixdisp: function() {
		this.progbox.setStyle("display",this.showing ? "block" : "none");
	},
	setpos: function() {
		if (!this.showing) {
			return;
		}
		this.progbox.setStyles({
			left: (window.getWidth() - this.PROGWIDTH)/2+"px",
			top: (window.getHeight() - this.PROGHEIGHT)/2+"px"});
	},
	//set the progress bar to a percent, represented as a fraction
	set: function(frac) {
		this.progbar.fx.width.stop();
		this.progbar.fx.width.start(Math.floor(this.PROGWIDTH * frac));		
	}
};
