$(document).ready(function(){

$('.wrapper').hide();

$('#menu ul:first').addClass('genitore');



$('.wrapper').fadeIn(200,function () {

$('#foglio, #testafoglio, #footer').animate({"top": "-90px"}, 1000);

});







$('#menu a, #logo a').click(function(){
      var href= $(this).attr('href');
      
 
      $('.wrapper').fadeOut( 1000, function(){
         
            window.location=href;

      })

      return false;
})





if($('body').hasClass('page-child')){

var x_current = $('#menu ul li.current_page_parent').position().left;
var larghezza_li_current = $('#menu ul li.current_page_parent').width() + 14;
var spostamento_current = x_current;
$('#slider').css('left', spostamento_current);
$('#cen').css('width', larghezza_li_current);
}


else {
	
	var x_current = $('#menu ul li.current_page_item').position().left;
	var larghezza_li_current = $('#menu ul li.current_page_item').width()+ 14;
	var spostamento_current = x_current;
	$('#slider').css('left', spostamento_current);
	$('#cen').css('width', larghezza_li_current);
	
}







$('#menu ul.genitore > li').hover(function(){
var x_current = $('#menu ul li.current_page_item').position().left;
var larghezza_li_current = $('#menu ul li.current_page_item').width()+ 14;
var spostamento_current = x_current;
var x = $(this).position().left;
var spostamento = x;
var larghezza_li = $(this).width()+ 14;
var larghezza_slider = larghezza_li + 'px';
$('#slider').stop().animate({left: spostamento});
$('#cen').stop().animate({width: larghezza_slider}, 500);


},function(){

$('#slider').stop().animate({left: '+=0'},function(){

$('#slider').animate({left: spostamento_current},function(){
$('#cen').animate({width: larghezza_li_current});

});

});

}


);










});











