function VisualQueue (maxLength, replenisher) {
	this.div = $('visual_queue');
	this.indicators = this.div.childNodes;
	this.maxLength = maxLength;
	this.replenish = replenisher;
	this.replenish();
}

VisualQueue.prototype.redraw = function () {
	if (!this.div) { return; }
	var dims = document.viewport.getFullDimensions();
	var myWidth = (dims.width - 380);
	this.div.style.width = myWidth + "px";
	this.dX = myWidth/this.indicators.length;

	for (i=0; i<this.indicators.length; i++) {
		var newX = (i*this.dX) + (this.dX/2) - 12;
		var indicator = this.indicators[i];
		new Effect.Move(indicator, {x: newX, mode: 'absolute', duration: 1.0, transition : Effect.Transitions.bounce });
	}
};

VisualQueue.prototype.push = function (item) {
	if (this.redrawTimer) {
		clearTimeout(this.redrawTimer);
		this.redrawTimer = null;
	}

	var queueLength = this.indicators.length;
	var newIndicator = item.getQueueIndicator();
	if (queueLength) {
		var lastIndicator = this.indicators[queueLength-1];
		lastIndicator.nextIndicator = newIndicator;
	} else {
		this.current = newIndicator;
	}
	
	if (queueLength > this.maxLength) { this.div.removeChild(this.indicators[0]); }
	this.div.appendChild(newIndicator);

	this.redrawTimer = setTimeout("Photo.queue.redraw()", 150);
};

VisualQueue.prototype.next = function () {
	if (this.current.nextIndicator) {
		this.current = this.current.nextIndicator;
		if (!this.current.nextIndicator) { this.replenish(); }
		return this.current.item;
	}
};

VisualQueue.prototype.indicate = function (itemToIndicate) {
	for (i=0; i<this.indicators.length; i++) {
		var indicator = this.indicators[i];
		indicator.indicate(indicator.item==itemToIndicate);
	}
};

