// JavaScript Document
// gestion des animations principales du site avec jQuery 1.6.1

// vitesse d'animation pour les images de profil
var vitesseProfil = 250;

// variable pour l'animation hub photos
var margTopPhoto = 13;

// variable pour l'animation des tweets
var margTopTweet = 0;
// variable setInterval pour les tweets
var setIntTweet;

// variable setInterval pour les hotnews
var setIntHotnews;

// variable de stockages du nombre d'onglet dans le menu des sliders
var nbLigne = 0;
var ligneSlide = 0;
var marginTopSlide = 0;
var marginLeftSlide = 0;
var setIntSlide;

$(document).ready( function(){
  
  // ----- gestion de l'animation du hub photos -----------------------------------------------------------------------
  setInterval(function () {
          margTopPhoto = margTopPhoto + 123;
          if( margTopPhoto >= ($(".headerPhotos").first().children("a").children("img").length * 123) ){ margTopPhoto = 13; }
                    
          $(".headerPhotos").children("a").animate({
              marginTop: "-"+margTopPhoto+'px'
            }, vitesseProfil);
        }, 5000);
  // ----/ gestion de l'animation du hub photos -----------------------------------------------------------------------
  
  // ----- gestion de l'animation du hub des tweets -----------------------------------------------------------------------
  setIntTweet = setInterval("showNextTweet('+')", 15000);
  
  $("#PrevTweet").click( function(){
    clearInterval(setIntTweet);
    showNextTweet('-');
    setIntTweet = setInterval("showNextTweet('+')", 15000);
    
    return false;
  });
  
  $("#NextTweet").click( function(){
    clearInterval(setIntTweet);
    showNextTweet('+');
    setIntTweet = setInterval("showNextTweet('+')", 15000);
    
    return false;
  });
  // ----/ gestion de l'animation du hub des tweets -----------------------------------------------------------------------
  
  
  // ----- gestion de l'animation du hub hotnews -----------------------------------------------------------------------
  $("#titleNews").slideUp(vitesseProfil);
  setIntHotnews= setInterval(function () { $("#titleNews").slideToggle(vitesseProfil); }, 7500);
  
  $(".linkHotnews").mouseenter( function(){
    clearInterval(setIntHotnews);
    $("#titleNews").slideDown(vitesseProfil);
  });
  
  $(".linkHotnews").mouseleave( function(){
    setIntHotnews= setInterval(function () { $("#titleNews").slideToggle(vitesseProfil); }, 7500);
  });
  // ----/ gestion de l'animation du hub hotnews -----------------------------------------------------------------------
  
});
// ----- fonction de gestion des tweets ---------------------------------------------------------------------------
function showNextTweet(signe) {
  if( signe == '-' ) {
    margTopTweet = margTopTweet - 162;
    if( margTopTweet < 0 ) { margTopTweet = 162*4; }
  } else {
    margTopTweet = margTopTweet+ 162;
    if( margTopTweet > (162*4) ) { margTopTweet = 0; }
  }
  
  $(".tweetList").animate({
    marginLeft: "-"+margTopTweet+'px'
  }, vitesseProfil);
}
