Prototype.Browser.IE6=Prototype.Browser.IE &&
parseInt(navigator.userAgent.substring
(navigator.userAgent.indexOf("MSIE")+5))==6;

Prototype.Browser.IE7=Prototype.Browser.IE &&
parseInt(navigator.userAgent.substring
(navigator.userAgent.indexOf("MSIE")+5))==7;

Prototype.Browser.IE8=Prototype.Browser.IE &&
parseInt(navigator.userAgent.substring
(navigator.userAgent.indexOf("MSIE")+5))==8;


	var currentDropDownIndex = -1;

	function showDropDown(index){
			var mainDropDown = $('mainDropDown' + index);
			//if(Element.visible(mainDropDown)) return;

			var leftOffset = -2;
			var widthCorrection = 1;	
			var dropDownTopBar = $('dropDownTopBar' + index);
			var mainMenuLi = $('mainMenuLi' + index);

			if (index==0) { leftOffset = -1; widthCorrection=2; }
			dropDownTopBar.show();
			mainDropDown.blindDown({ duration: 0.3, queue: { position: 'end', scope: 'dropdown' } , afterFinish:hideOthers(index) });
			mainMenuLi.down().next('a').setStyle('color:#bf0025');
			currentDropDownIndex = index;
	}	

	function checkMouseOut(event, index){
		var mainDropDown = $('mainDropDown' + index);
		var dropDownTopBar = $('dropDownTopBar' + index);	
		var pointerX = Event.pointerX(event);
		var pointerY = Event.pointerY(event);

		var elementMinX = Element.positionedOffset(dropDownTopBar).left + 4;
		var elementMaxX = elementMinX + mainDropDown.getWidth() - 20;
		var elementMinY = Element.positionedOffset(dropDownTopBar).top + 4;
		var elementMaxY = elementMinY + mainDropDown.getHeight();

		if(pointerX <= elementMinX || pointerX >= elementMaxX || pointerY <= elementMinY || pointerY >= elementMaxY)
			hideDropDown(index);
	}
	
	function hideOthers(index){
		var queue = Effect.Queues.get('dropdown');
		queue.each(function(effect) { if (effect.element.id != 'mainDropDown' + index && effect.element.id != 'dropDownTopBar' + index) effect.cancel(); });

		var otherMenuIndex = 0;
		while ($('mainDropDown' + otherMenuIndex)!=null){
			if (otherMenuIndex!=index)
				hideDropDown(otherMenuIndex);
			otherMenuIndex++;
		}
	}
	
	function hideDropDown(index){
		var mainDropDown = $('mainDropDown' + index);
		mainDropDown.hide();
		var dropDownTopBar = $('dropDownTopBar' + index);
		dropDownTopBar.hide();
		$('mainMenuLi' + index).down().next('a').setStyle('color:#000000');
		$('container').stopObserving('mouseout', function(event) { checkMouseOut(mainDropDown, dropDownTopBar, event, index) });
		if (currentDropDownIndex == index) currentDropDownIndex = -1;
	}
	
	function initMenu(){
		var index = 0;

		while ($('mainDropDown' + index)!=null){		  
			var leftOffset = -2;
			var widthCorrection = 1;
			if (index==0) { leftOffset = -1; widthCorrection=2; }

			if (Prototype.Browser.IE7) {
				if (index==0)
					leftOffset = 0;
				else
					leftOffset = -1;

				var image = $('dropDownTopBar' + index).firstDescendant('img');
				image.makePositioned();
				image.setStyle({top: '-1px'});
			}

			$('dropDownTopBlinder' + index).setStyle({width:$('mainMenuLi' + index).getDimensions().width-widthCorrection + 'px',top:'-1px',left:'1px'});			
			$('dropDownTopBar' + index).clonePosition('mainMenuLi' + index, {setHeight:false, offsetLeft:leftOffset, offsetTop:0});
			$('dropDownTopBar' + index).setStyle({width:$('mainMenuLi' + index).getDimensions().width-widthCorrection+2 + 'px'});
			$('mainDropDown' + index).clonePosition('mainMenuLi' + index, {setHeight:false, setWidth:false, offsetLeft:leftOffset, offsetTop:26});	

			var containerOffsetRight = Element.positionedOffset($('container')).left + $('container').getWidth();
			var dropDownOffsetRight = Element.positionedOffset($('mainMenuLi' + index)).left + 200;
			if (dropDownOffsetRight > containerOffsetRight) {
				var deltaOffset = dropDownOffsetRight-containerOffsetRight;
				$('mainDropDown' + index).clonePosition('mainMenuLi' + index, {setHeight:false, setWidth:false, offsetLeft:leftOffset-deltaOffset, offsetTop:26});
				$('dropDownTopBlinder' + index).setStyle({left: (deltaOffset+1) + 'px'});				
			}

			index++;
		}	
	}	


Event.observe( window, 'load', initMenu);