/***
 * Creates new box manager manages all boxes on current site
 */
function boxManager() {
	this.boxes = new Array();

	var current = this;

	// Sets the event handler
	if(document.layers) window.captureEvents(Event.KEYDOWN);
	document.onkeydown = function(e) { current._keydown(e); }; // fire event for keydown
}

// Checks keydown event
boxManager.prototype._keydown = function (e) {
	var boxManager = this.boxManager;
	
	if(!e) e = window.event;
	var keyCode = (e.keyCode)? e.keyCode: e.charCode;

	if(keyCode == '27') {
		this.closeBoxes();
	}
};

// Close boxes
boxManager.prototype.closeBoxes = function () {
	for(var b=0;b<this.boxes.length;b++) {
		if(getObjectName(this.boxes[b]) == 'filterbox') {
			this.boxes[b].closeFilterbox();
		} else if(getObjectName(this.boxes[b]) == 'box') {
			this.boxes[b].closeBox();
		}
	}
};

boxManager.prototype.addBox = function (box) {
	if(getObjectName(box) == 'filterbox' ||
		getObjectName(box) == 'box') {

		this.boxes[this.boxes.length] = box;
	}
};

boxManager.prototype.getBox = function (boxId) {
	var box = null;
	for(var b=0;b<this.boxes.length;b++) {
		if(this.boxes[b].id == boxId) {
			return this.boxes[b];
		}
	}

	return null;
};
