var Containers = {
	
	container_array: new Array(),
	zindex: 10,
	
	add: function(id, draggable) {
		this.container_array.push(new container(id, draggable));
		this.makeDraggable();	
		this.makeOnTop(id);
	},
	
	remove: function(id) {
		array_pull(id, this.container_array);
	},
	
	veil: function(id) {
		veil.show('container_' + id);
		for(i=0; i<this.container_array.length; i++) {
			if(this.container_array[i].id == id) {
				this.container_array[i].veiled = true;	
			}
		}
	},
	
	makeDraggable: function() {
		$j('.container').draggable({ handle: 'h2', opacity: 0.8, stack: {group: 'container', min:50 } });
	},
	
	makeOnTop: function(id) {
		for(i=0; i<this.container_array.length; i++) {
			if((this.container_array[i].id == id) && (this.container_array[i].draggable != false)) {
				if(($('container_' + id).style.zIndex != this.zindex)) {
					$('container_' + id).style.zIndex = this.zindex++;
				}
			}
		}
	},
	
	close: function(id) {
		xajax_removeElement(id);
		for(i=0; i<this.container_array.length; i++) {
			if((this.container_array[i].id == id) && (this.container_array[i].veiled === true)) {
				veil.hide();
			}
		}
		this.remove(id);
	},
	
	refresh: function(module, id, vars, div) {
		xajax.$(div).innerHTML = '<div style="height:100px; text-align:center;"><div style="height:60px; background-color:#E2E4E7; margin:20px; border:1px solid #2B3159;"><img src="' + host + '/images/ajax-loader.gif" style="margin-top:15px;"></div></div>';
		xajax.call('createContainer', {callback:renderLoading, parameters:[module, id, vars]});
		xajax.call('removeElementChildren', {parameters:[div]});
	},
	
	collapse: function(id, module, reload_vars) {
		//if(in_array(id, this.container_array)) {
			xajax.call('taskbarCommand', {mode:'synchronous', parameters:['addElement', 'global', id, module, reload_vars]});
			xajax.call('taskbarCommand', {parameters:['display']});
			this.close(id);
		//}
	}
}

container = function(id, draggable) {
	this.id = id;
	this.draggable = draggable;
	return this;
}
