$(document).ready(function(){
	var flashfile = $('#header-flash').text();
	$('#header-flash').text('');
	
	if ($('.news-description').length > 0) {

   	$('.news-description').jScrollPane();
   
      $('#news1').hover(function() {
         $('#desc1').css('visibility', 'visible');
      }, function() {
       	$('#desc1').css('visibility', 'hidden');
      });
   
      $('#news2').hover(function() {
        	$('#desc2').css('visibility', 'visible');
      }, function() {
         $('#desc2').css('visibility', 'hidden');
      });
   
      $('#news3').hover(function() {
         $('#desc3').css('visibility', 'visible');
      }, function() {
         $('#desc3').css('visibility', 'hidden');
      });
   }

	if (flashfile) {
		flashembed("header-flash",
			{ src: flashfile,
			  width: 960,
			  height: 408,
			  wmode: 'transparent'
	        }
		);
	}

	$('.menu > li').hover(function() {
  	  x = $(this).position().left + 25;
	  w = $(this).width();

	  if(!$('#menu-red').height()) {
		$('#menu-red').css('left', x);
		$('#menu-red').width(w);
		$('#menu-red').animate({
		  height: '6'
		  }, 500);
	  }
	  else {
	    $('#menu-red').stop();
	    $('#menu-red').animate({
		  left: [x, 'easeOutCubic'],
		  width: w,
		  height: '6'
	    }, 1000);
	  }
	});
	$('.menu > li > a > img').hover(function() {
	  $(this).css('background-color', '#b60000');
	});

	$('.menu > li > a > img').mouseout(function() {
	  $(this).animate({
	  	backgroundColor: '#808080'
	  }, 500);
	});
	$('.menu').mouseleave(function() {
	  $('#menu-red').stop();
	  $('#menu-red').animate({
	    height: '0'
	  }, 400);
	});

	$("a").attr("href", function(){
	  return "#" + $(this).attr("href");
	});

	$('.text-box').animate({
	  opacity: [1, 'easeOutCubic'],
	  top: [0, 'easeOutCubic']
	}, 1000);

	$("a").click(function(){
	  ind = $(this).attr("href");
	  $('.text-box').animate({
		opacity : [0, 'easeOutCubic'],
		top : [30, 'easeOutCubic']
	  }, 500, function(){
		location.href = ind.substring(1);
	  });
	});

    $('a.email').each(function(i) {
        var text = $(this).text();
        var address = text.replace("(chiocciola)", "@");
        $(this).attr('href', 'mailto:' + address);
		$(this).text(address);
	});

});
