jQuery(document).ready(function($) {
	var opened = '';
	var listWidth = new Array();

	if ($('li.expanded').length) {
		opened = $('li.expanded');
	}

	$('#navi > li').each(function(i, el) {		
		$(el).mouseenter(function() {
			if (!$(this).hasClass('expanded') && $(this).find('.subnav-wrapper').length) {
				$(this).find('.subnav-wrapper').stop(true);
				$(this).find('.subnav-wrapper').animate({'width': $(this).find('table').width()}, 500);
		
				if (opened !== '') {
					$(opened).find('.subnav-wrapper').stop(true);
					$(opened).find('.subnav-wrapper').animate({'width': 1}, 500);
				}
			}
		}).mouseleave(function() {
			if (!$(this).hasClass('expanded') && $(this).find('.subnav-wrapper').length) {
				$(this).find('.subnav-wrapper').stop(true);
				$(this).find('.subnav-wrapper').animate({'width': 1}, 500);
				
				if (opened !== '') {
					$(opened).find('.subnav-wrapper').stop(true);
					$(opened).find('.subnav-wrapper').animate({'width': $(opened).find('table').width()}, 500);
				}
			}
		});
	});
});
