
	iClientMainBar = function(node, index, pob){
		this.instID = 'iClientMainBar' + parseInt(Math.random()*1000000);
		this.options = new Hash();
		this.pob = pob;
		this.isOpen = false;
		this.index = index;
		this.node = node;
		this.left = 0;
		this.closedWidth = 115; // base width of mainBar
		this.width = 0;
		this.children = new Hash();
		this.childContainers = new Hash();
		this.debug = pob.debug;
		this.queue = pob.queue;
	}
	
	iClientMainBar = iClientMainBar.extendsFrom(iClientBase);
	
	iClientMainBar.prototype.init = function(){
		// set variables
		this.objInit();
		this.options.set('introText', this.getProductProperty(this.node, 'intro'));
		
		// create container		
		var container = this.createContainer();
		container.isMainBar = true;
		this.output = container;
		this.waiterElem = Builder.node('div', {id:'waiterOf'+this.instID, className:'inlineWaiter'}, [Builder.node('img', {src:gRootPath + 'images/waiter.gif', style:'display:block;'} ) ]);
		this.output.appendChild(this.waiterElem);
		//get and create children:
		this.setChildren();
		this.setStartWidth();
		return this.output;
	}

	iClientMainBar.prototype.goTo = function(event, elem){
		if (!elem) var elem = Event.element(event);
		var localChildren = new Array();
		var childProductID = elem.productID;
		if (!this.isOpen){
			this.toggle('', true);
		}
		this.children.each(
			(function(child){
				var productID = child.key;
				child = child.value;
				if (productID != childProductID) {
					child.isOpen = false;
					child.hide();
				}else{
					if (child.isOpen) return;
					if (!child.initialized){
						var childContainer = this.childContainers.get(childProductID);
						var node = child.init();
						childContainer.appendChild(node);
					}
					child.draw();
					localChildren.push(child);
				}
			}).bind(this)			
		)
		$A(localChildren).each(
			(function(child){
				var childContainer = this.childContainers.get(child.productID);
				child.show();
			}).bind(this)
		)
	}


	/**
	 * More or less private functions (though not used privately)
	 */

	iClientBase.prototype.setBottomNavigation = function(){
		var div = $(this.instID + '_footer');
		if (!div){
			var div = Builder.node('div', {className:'barFooter', id: this.instID + '_footer'});
		}else{
			Element.update(div, '');
		}
		this.output.appendChild(div);
		
		if (this.isOpen){
			var img = Builder.node('span', {className:'arrowLeft', id:this.productID + "_closer"}, [' < ']);
			this.addEvent(img, 'click', this.toggle.bind(this));
		}else{
			var img = Builder.node('span', {className:'arrowRight', id:this.productID + "_closer"}, [' > ']);
			img.productID = this.children.keys()[0];
			this.addEvent(img, 'click', this.goTo.bind(this));
		}
		div.appendChild(img);
	}
	
	iClientMainBar.prototype.setContent = function(){
		if (!$(this.instID + '_mainBarContent')){
			var div = Builder.node('div', {id:this.instID + '_mainBarContent', className:'content', style:"display:none;"});
			this.contentContainer = div;
			Element.update(div, this.options.get('introText'));
			this.output.appendChild(div);
			this.show(div);
		}else{
			if (this.isOpen){
				this.hide($(this.instID + '_mainBarContent'));
			}else{
				// hide remaining children
				this.children.each(function(child){child.value.hide()});
				this.show($(this.instID + '_mainBarContent'));
			}
		}
	}
	
	iClientMainBar.prototype.setTitle = function(){
		if (!$('barTitle_' + this.instID)){
			var link = new Element('a', {href:"#"+this.options.get('productName')}).update(this.options.get('productName'));
			var barTitle = Builder.node('div',{className:'barTitle', id:'barTitle_' + this.instID}, [link]);
			this.output.appendChild(barTitle);
			barTitle.productID = this.children.keys()[0];
			link.productID = this.children.keys()[0];
			this.addEvent(barTitle, 'click', this.goTo.bind(this));
		}
	}
	
	iClientMainBar.prototype.setNavigation = function(){
		// Set TOP navigation
		if (!$('barNavigation_' + this.instID)){
			var div = Builder.node('div', {className:'barSubNav', id: 'barNavigation_' + this.instID}, ['']);
			$A(this.node.childNodes).each(
				(function(childNode){
					if (childNode.nodeName == 'product'){
						div.appendChild(this.createNavItem(childNode));
					}
				}).bind(this)
			)
			this.output.appendChild(div);
		}
		var div = $('barNavigation_' + this.instID);
		var i = 0;
		 
		if (this.isOpen){
			$A(div.childNodes).each(
				function(node){
					if (node.nodeName.toLowerCase() != 'a') return;
					node.style.display = 'inline';
				}
			);
		}else{
			$A(div.childNodes).each(
				function(node){
					if (node.nodeName.toLowerCase() != 'a') return;
					if (i>0)	{
						node.style.display = 'none';
					}else{
						node.style.display = 'inline';
					}
					i++;
				}
			);
		}
		//set bottom navigation:
		this.setBottomNavigation();
	}
	
	iClientMainBar.prototype.getParentLink = function(){
		return this.options.get('productName').toString().replace(' ', '_');
	}	
	
	iClientMainBar.prototype.createNavItem = function(child){
		var childName = this.getProductProperty(child, 'name');
		var productID = this.getProductProperty(child, 'product_id');
		var linkName = '#' + this.options.get('productName').toString().replace(' ', '_') + '&' + childName.replace(' ' , "_");
		var spanner = Builder.node('a', {href:linkName,style:'display:none;'},[childName]);
		spanner.productID = productID;
		this.addEvent(spanner, 'click', this.goTo.bind(this));
		return spanner;
	}
	
	iClientMainBar.prototype.setStartWidth = function(){
		var amount = parseInt(this.closedWidth);
		this.width = parseInt(this.closedWidth);
	}	