$(function(){
	var menu_item_count = 0;
	var menu_item_left = 0;
	$('#o-header ul.menu li.o-menu-top-ithem').each(function(){
		menu_item_count ++;
		$(this).data('menu',{
			item:menu_item_count,
			left:menu_item_left
		});
		var left = $(this).width() + 15;
		menu_item_left += left;
		$(this).css('width', left + 'px');
		if( $(this).find('ul').length > 0 ){
			$(this).bind('mouseover',function(){
				$('#o-menu-top-ithem-podl').css('width', $('#o-top-menu').css('width'));
				var item_data = $(this).data('menu');
				var a_lefgth = 0;
				$(this).addClass('hover');
				$(this).find('ul').css('display','block');
				$(this).find("ul a").each(function(){
					if( a_lefgth < $(this).width() ) a_lefgth = $(this).width();
				});
				if( a_lefgth < $(this).width() ) a_lefgth = $(this).width() - 30;
				$(this).find("li .o-menu-right").css('width', (a_lefgth+14+23) + 'px');
				$(this).find("li a").css('width', a_lefgth + 'px');
				if( $( '#o-menu-top-ithem-podl #' + $(this).attr('id') + '_bottom' ).length != 1 ){
					//alert( $(this).attr('id') );
					var center = $(this).find('a').width();
// 					if( a_lefgth < center + 46 ) var width = a_lefgth + 26;
// 					else var width = center + 46;
					var html = '';
					html += '<div id="' + $(this).attr('id') + '_bottom" class="o-top-menu-bottom">';
					html += '  <div class="left"></div>';
					html += '  <div class="center"></div>';
					html += '  <div class="right"></div>';
					html += '  <div class="last"></div>';
					html += '</div>';
					$('#o-menu-top-ithem-podl').width( $('#o-header ul.menu').width() );
					$('#o-menu-top-ithem-podl').append(html);
					$('#o-menu-top-ithem-podl #' + $(this).attr('id') + '_bottom').css('position','absolute').width( a_lefgth+14+23+9 ).css('left', item_data.left + 'px');
					$('#o-menu-top-ithem-podl #' + $(this).attr('id') + '_bottom .center').css('width', center + 'px');
					$('#o-menu-top-ithem-podl #' + $(this).attr('id') + '_bottom .last').css('width', (a_lefgth - center - 1) + 'px');
// 					alert( $(this).left() );
				} else {
					$( '#o-menu-top-ithem-podl #' + $(this).attr('id') + '_bottom' ).css('display','block');
				}
				$(this).find('.o-menu-bottom-shadow').css('width', (a_lefgth + 26) + 'px');
			});
			$(this).bind('mouseout',function(){
				$(this).removeClass('hover');
				$(this).find('ul').css('display','none');
				$( '#o-menu-top-ithem-podl #' + $(this).attr('id') + '_bottom' ).css('display','none');
			});
		}
	});
});
