var page = {
	bufferStream : function(url, time)
	{
		var prog = new progress(document.getElementById("progress"), time * 1000, function(){ window.location = url });
		prog.start();
	}

}

function progress(obj, duration, onFinish) {
	
	this.obj = obj;
	this.duration = duration;
	this.onFinish = onFinish;
	
	this.elapsed = 0;
	
	this.progressObj;
	this.progressStateObj;
	
	this.start = function()
	{
		this.progressObj = document.createElement("DIV");
		this.progressObj.className = "progress";
		this.progressStateObj = document.createElement("DIV");
		this.progressStateObj.className = "state";
		
		obj.appendChild(this.progressObj);
		obj.appendChild(this.progressStateObj);
		
		this.loop();
	}
	this.loop = function()
	{
		var that = this;
		
		if(this.elapsed <= this.duration)
		{
			var percentage = (this.elapsed / this.duration) * 100;
			
			this.progressObj.style.width = percentage + "%";
			this.progressStateObj.innerHTML = Math.round(percentage) + "%";
			
			this.elapsed += 100;
			window.setTimeout(function(){ that.loop() }, 100);
		}
		else
		{
			this.onFinish();
		}
	}
	
}
