var menu = {
	build: function(menuId,duration,ease){
		var menuContainer = jQuery('#'+menuId);
		var menu = jQuery('#'+menuId+' ul');
		var menuLi = menu.children('li');


		/*allineo il marker sul primo elemento o sull'elemento attivo*/
		var firstObj;
		var firstObjIndex;
		if (menu.find('li.active:eq(0)').size() === 0){
			firstObj = menu.children('li:eq(0)');
			firstObjIndex = 0;
		}
		else{
			firstObj = menu.find('li.active:eq(0)');
			firstObjIndex = menu.children('li').index(menu.find('li.active:eq(0)'));
		}
		var position = parseInt(((((firstObjIndex)*2)+1)*parseInt(firstObj.css('margin-left')))+(firstObj.children('a').outerWidth()*(firstObjIndex)));
		jQuery(menuContainer).css({backgroundPosition:position+'px 0px'});
		
		/*gestisco lo spostamento del marker in base al mouseenter sull'elemento corrente*/
		jQuery(menuLi).each(function(i){
			var curObj = this;
			var curObjIndex = i;
			jQuery(curObj).children('a').prepend('<span class="lines">&nbsp;</span>');
			jQuery(curObj).bind('mouseenter', function(){
				if(jQuery(this).queue().length < 1){
					var position = parseInt(((((curObjIndex)*2)+1)*parseInt(jQuery(curObj).css('margin-left')))+(jQuery(curObj).children('a').outerWidth()*(curObjIndex)));
					jQuery(menuContainer).animate({backgroundPosition:position+'px 0px'},duration,ease);
				}
			});
		});
	}
}


jQuery(document).ready(function(){
	menu.build('menuist',500,'easeOutExpo');
});
