
	iClientController = function(mainContainer){
		this.instID = 'iClientController' + parseInt(Math.random()*1000000);
		this.minBarWidth = 160;
		this.children = new Hash();
		this.container = $(mainContainer);
		this.debug = 0;
		this.waiterElem = $('waiter');
		this.queue = new Array();
//		gwps.addEvent(window, 'resize', resize);
	}

	iClientController = iClientController.extendsFrom(iClientBase);
	
	iClientController.prototype.init = function(){
		this.waiter();
		this.getChildObjects(1, this.setBarObjects.bind(this));
		this.addEvent(window, 'resize', this.resizeChildren.bind(this));
	}
	
	iClientController.prototype.setBarObjects = function(req){
		var DOM = req.responseXML.getElementsByTagName('product').item(0);
		var i = 0;
		$A(DOM.childNodes).each(
			(function(aNode){
				if (aNode.nodeName == 'product'){
					var newBar = new iClientMainBar(aNode, i, this);
					this.container.appendChild(newBar.init());
					newBar.draw();
					this.children.set(i, newBar);
					i++;
				}
			}).bind(this)
		);
		this.setSize();
		this.unWaiter();
		if (window.location.hash){
			setTimeout(
				(function(){
					var hash = window.location.hash.toString().replace("#", '');
					var loc = hash.split("&");
					// recursively try to open children:
					this.openChildren(this.children, loc);
				}).bind(this),
				750
			)
		}
		setTimeout(this.resizeContent.bind(this), 2000);
	}
	
	iClientController.prototype.openChildren = function(children, locationArray){
		var selectedChild = '';
		var secondChild = '';
		var activeChild = ''; 
		var dummyElem = '';
		children.values().each(
			(function(child){
				if (child.options.get('productName') == locationArray[0].toString().replace("_", " ") ){
					selectedChild = child;
					// lookup productID
					
					locationArray = locationArray.reverse();
					locationArray.pop();
					locationArray = locationArray.reverse();
					// second part of array:
					var productID = child.children.keys()[0];
					child.children.keys().each(
						function(secondChildID){
							secondChild = child.children.get(secondChildID);
							secondChild.init();
//							secondChild.draw();
							if (locationArray[0].toString().replace("_", " ")  == secondChild.options.get('productName')){
								productID = secondChildID;
								activeChild = secondChild;
							}
							secondChild.initialized = false;
						}
					)
					
					dummyElem = new Element('div');					
					dummyElem.productID = productID;
					dummyElem.hide();
					
					this.container.insert(dummyElem);
					child.goTo('', dummyElem);
					dummyElem.remove();
				}
			}).bind(this)
		)
		setTimeout( (function(){
						if (locationArray.length > 0) {
							locationArray = locationArray.reverse();
							locationArray.pop();
							locationArray = locationArray.reverse();
							if (locationArray.length > 0){
								activeChild.children.keys().each(
									(function(childID){
										var child = activeChild.children.get(childID);
										if (locationArray[0].toString().replace("_", " ")  == child.options.get('productName')){
											var childContainer = activeChild.childContainers.get(childID);
											
											var node = child.init();
											childContainer.appendChild(node);
											child.draw();
											child.show();
											activeChild.setSize();
										}
									}).bind(this)
								)
							}
						}
					}).bind(this), 500);
	}
