

/**
* Controller Singleton
* taraLabor (zoo2002.de)
* V 0.32 (30-05-2006)
* central registry and manager
**/

// controller singleton
function getController(){
	
	if (!top.controller){
		top.controller = new Controller();
	}
	return top.controller;
}


Controller = Class.create();

Controller.prototype = {
	
	initialize: function(){
		this.bClasses = new Hash();
		this.windows = new Hash();
		this.content = BODY();
		this.activeLang = null;
	},
	
	getLang: function(){
		return this.activeLang;
	},
	
	setLang: function(lang){
		this.activeLang = lang;
	},
	
	// get reference to businessObjectClass
	getBClass: function(className){
		var answer;
		if (answer = this.bClasses.has(className))
			return answer;
		
		return this.addBClass(className);
	},
	
	// add businessObjectClass
	addBClass: function(className){
		if (className){
			var answer = this.bClasses.add(className, new model.BClass(className));
			return answer;
		}
		return null;
	},
	
	// remove businessObjectClass
	removeBClass: function(className){
		return this.bClasses.del(className);
	},
	
	removeBClasses: function(){
		var result = true;
		while(this.bClasses.items.length > 0 && result == true){
			var key = this.bClasses.items[0];
			result = this.removeBClass({id: key});
		}
	},
	
	bClassIsValid: function(className){
		return this.bClasses.has(className);
	},
	
	addWindow: function(properties){
		properties.object.parent = this;
		
		if(!properties.noAppend)
		this.content.appendChild(properties.object.container);
		
		else
		properties.object.noAppend = true;
		
		this.windows.add(properties.id, properties.object);
	},
	
	getWindow: function(properties){
		var answer = null;
		if(answer = this.windows.has(properties.id))
			return answer;
		else
			return null;
	},
	
	removeWindow: function(properties){
		if(!(child = this.windows.has(properties.id)))
			return false;
		
		if(!child.noAppend){
			if(!child.isModal)
				this.content.removeChild(child.container);
			else
				this.content.removeChild(child.blocker);
		}
		
		this.windows.del(properties.id);
		return true;
	},
	
	removeWindows: function(){
		var result = true;
		while(this.windows.items.length > 0 && result == true){
			var key = this.windows.items[0];
			result = this.removeWindow({id: key});
		}
	}
};

