// JavaScript Document

$(document).ready(function () {
							
	$(".menu_item").bind("mouseenter", function(e){
		
		if (!$(this).hasClass('active_item')) {
		
			if ($(this).hasClass('first_item'))			$(this).addClass("first_item_orange");
			else if ($(this).hasClass('last_item'))		$(this).addClass("last_item_orange");
			else if ($(this).hasClass('white_item'))	$(this).addClass("white_item_orange");
			else 										$(this).addClass("orange_item");
			
			
			
			if ($(this).prev('.menu_item:first').hasClass('white_item')) 
				$(this).prev('.menu_item:first').addClass("orange_item_left_white");
			else
				$(this).prev('.menu_item:first').addClass("orange_item_left");
			
		}
			
    });
	
	$(".menu_item").bind("mouseleave", function(e){
												
        $(this).removeClass("orange_item");
		$(this).removeClass("first_item_orange");
		$(this).removeClass("last_item_orange");
		$(this).removeClass("white_item_orange");

		$(this).prev('.menu_item:first').removeClass("orange_item_left");
		$(this).prev('.menu_item:first').removeClass("orange_item_left_white");
    });
	
	
	$(".first_row .menu_item").bind("mouseenter", function(e){
		
		if (!$(this).hasClass('active_item')) {
			
			var firstRowWidthSum	=	0;
			var this_width			=	$(this).width();
			
			$(this).prevAll().each(function (i) {
				firstRowWidthSumPrev	=	firstRowWidthSum;
				firstRowWidthSum		+=	$(this).width();
			});
			
			firstRowWidthSumPrev	=	firstRowWidthSum;
			firstRowWidthSum			+=	this_width;
			
			var secondRowWidthSum	=	0;
			
			$(".second_row .menu_item").each(function (i) {
				secondRowWidthSum	+=	$(this).width();
				
				if (secondRowWidthSum < firstRowWidthSum && secondRowWidthSum > firstRowWidthSumPrev) {
					$(this).addClass('under_item');
					if ($(this).hasClass('first_item'))	$(this).addClass('first_under_item');
																		
					//alert(' secondRowWidthSum: '+secondRowWidthSum+'\n firstRowWidthSum: '+firstRowWidthSum+'\n firstRowWidthSumPrev:' + firstRowWidthSumPrev);
				}
				
			});
		}
	});
	

	$(".first_row .menu_item").bind("mouseleave", function(e){
		
		$(".second_row .menu_item").removeClass('under_item');
		$(".second_row .menu_item").removeClass('first_under_item');
		
	});
	
	$(".menu_item").bind("click", function(e){
		
		$(this).children().children().each(
			function (i) {
			    goTo($(this).attr('href'))
			  }		
		);
	});
	

});





