var speedLogoDown=250;
var speedLogoUp=400;

var ploufplouf = function(tablo){
  return(tablo[Math.floor(Math.random() * tablo.length)]);
}

$('#logo img').hover(
  function(){
    $('#logo').stop(true).animate({
      height:'380px',
      'background-position-y': '333px'
    },speedLogoDown,'swing');
  }, function(){
    $('#logo').stop(true).animate({
      height:'200px',
      'background-position-y': '153px'
    },speedLogoUp,'swing', function(){
      if(Math.random() >0.7 ){
        $('#logo p').empty(); 
        $('#logo p').append(ploufplouf(
          ["&uarr; &uarr; &darr; &darr; &larr; &rarr; &larr; &rarr; <br/>a b start",
          "I can resist anything, <br/>except temptation.",
          "Who put pineapple juice <br/>in my pineapple juice?",
          "I am not different, <br/>unlike everyone.",
          "I am not different, <br/>unlike everyone.",
          "I am not different, <br/>unlike everyone.",
          "I am not different, <br/>unlike everyone.",
          "A lui. Ça fera plaisir<br/> à plus d'un.",
          "To her. She shall <br/> know herself.",
          "Si quelqu'un qui doit tout <br/> à Bach, c'est bien Dieu."
          ]
        ));
      }; 
    });
});

$("a.scroll").click(function(event){
  event.preventDefault();
  var goTo=$(this).attr('href');
  var distance = Math.abs($(this).offset().top-$(goTo).offset().top);
  var vitesse=Math.sqrt(distance/5000)*800/200;
  var temps=distance/vitesse;
  $.scrollTo(goTo, temps,'swing');
});

$('#toplink').click(function(){
  var distance=$('body').scrollTop();
  var vitesse=Math.sqrt(distance/5000)*800/200;
  var temps=distance/vitesse;
  $.scrollTo(0,temps,'swing');
});

if($('.sous-menu').length){ // SI SOUS MENU
  $('#menu a').hover(
    function(){
      if($(this).attr('name')=="GO"){
        $('.arrow-down').css({'border-top-color':'#FF0'});
      };
    }, 
    function(){
      $('.arrow-down').css({'border-top-color':'#000'});
    }
  );
}
else{ // SI PAS SOUS MENU
  $('#menu a').hover(
    function(){
      $('.arrow-down').css({'border-top-color':'#FF0'});
    }, 
    function(){
      $('.arrow-down').css({'border-top-color':'#000'});
    }
  );
};


    var $sidebar   = $("#aside");
    var $window    = $(window);
    var offset     = $sidebar.offset();
    var topPadding = 20;

if($sidebar.offset() && $sidebar.height()<$window.height()){
$window.scroll(function() {
    if(2*$window.height()<$('body').height()) {
        if ($window.scrollTop() > offset.top) {
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top + topPadding
            },500,'swing');
        } else {
            $sidebar.stop().animate({
                marginTop: 0
            });
        }
    }
});
}
