main.events.onload.addEvent(function () {
	
	var submenu_controller = new function () {
		
		var self		= this;
		var container	= document.getElementById('menu');
		
		
		var init =  function () {
			if (container.tagName.toLowerCase() == 'ul') {
				menuRoll();
			}
		};
		
		var menuRoll = function () {
			for ( var i = 0; i < container.children.length; i++ ) {
				var child1 					= container.children[i];
				if (child1.tagName !== undefined) {
					if (child1.tagName.toLowerCase() == 'li'){
						for ( var x = 0; x < child1.children.length; x++ ) {
							var child2 			= child1.children[x];
							if (child2.className == 'submenu') {
								setLeft(child2);
							} else if (child2.className == 'twoborders') {
								setWidth(child2);
							}
						}
					}
				}
			}
			
		};
		
		var setWidth = function (o) {
			var p 			= o.parentNode;
			o.style.width	= (p.offsetWidth - 8) + 'px';
			return;
		};
		
		var setLeft = function (o) {
			var p			= o.parentNode;
			var width = getUlWidth(o);
			if (navigator.appName == 'Microsoft Internet Explorer') {
				o.style.width = width + 'px';
				if (width < 400) {
					o.style.left	= ((p.offsetLeft - width) + 60) + 'px';
				} else {
					o.style.left	= (p.offsetLeft - width) - 150 + 'px';
					o.style.width 	= width + 150 + 'px';
				}
			} else {
				if (width < 400) {
					o.style.left	= ((p.offsetLeft - width) + 60) + 'px';
				} else {
					o.style.left	= (p.offsetLeft - width) + 'px';
				}
				o.style.width	= width + 'px';
			}
			return;
		};
		
		var getUlWidth = function (o) {
			var a_ = 0;
			var count = 0;
			for ( var i in o.children ) {
				if (o.children[i].offsetWidth !== undefined) {
					if (o.children[i].className != 'left' && o.children[i].className != 'right') {
						a_ += (o.children[i].offsetWidth + 12);
						count++;
					} else {
						a_ += o.children[i].offsetWidth;
					}
				}
			}
			if (count == 1) {
				for ( var i in o.children ) {
					if (o.children[i].offsetWidth !== undefined) {
						if (o.children[i].className != 'left' && o.children[i].className != 'right') {
							a_ += (200 - o.children[i].offsetWidth);
							o.children[i].style.width = '200px';
						}
					}
				}
			}
			return a_;
		};
		
		init();
	}();

});
