var Interval = 0;
var delta = 4;
var delay = 40;
var phase = "STAY";

function MonteMascot(type)
{
  var relaunch = 0;
  var topRange = 0;
  var mascot=document.getElementById('mascot');
  if (mascot.offsetTop>1)
  {
    mascot.style.top = (mascot.offsetTop - delta) + "px";
    relaunch = relaunch+1;
  }
  else
    mascot.style.top = "0px";

  if (type == 2) // graph (Ventes)
  {
    topRange = 10;
    var graph=document.getElementById('graph');
    if (graph.offsetTop>topRange)
    {
      graph.style.top = (graph.offsetTop - delta) + "px";
      relaunch = relaunch+1;
    }
    else
      graph.style.top = topRange + "px";
  }

  if (type == 3) // colab (Team)
  {
  // colab1
    topRange = 10;
    var colab1=document.getElementById('colab1');
    if (colab1.offsetTop>topRange)
    {
      colab1.style.top = (colab1.offsetTop - delta) + "px";
      relaunch = relaunch+1;
    }
    else
      colab1.style.top = topRange + "px";

  // colab2
    topRange = 25;
    var colab2=document.getElementById('colab2');
    if (colab2.offsetTop>topRange)
    {
      colab2.style.top = (colab2.offsetTop - delta) + "px";
      relaunch = relaunch+1;
    }
    else
      colab2.style.top = topRange + "px";
  }

  if (type == 4) // contact
  {
    topRange = 30;
    var contact=document.getElementById('contact');
    if (contact.offsetTop>topRange)
    {
      contact.style.top = (contact.offsetTop - delta) + "px";
      relaunch = relaunch+1;
    }
    else
      contact.style.top = topRange + "px";
  }

  if (relaunch > 0)
  {
    if (Interval)
    	clearInterval(Interval);
    Interval = setInterval("MonteMascot("+type+")",delay-(5*relaunch));
  }
  else
  {
    if (Interval)
    	clearInterval(Interval);
    Interval = 0;
    phase = "STAY";
  }
}

function DescendMascot(type)
{
  var relaunch = 0;
  var topRange;

  // home
  topRange = 70;
  var mascot=document.getElementById('mascot');
  if (mascot.offsetTop<topRange)
  {
    mascot.style.top = (mascot.offsetTop + delta) + "px";
    relaunch = relaunch+1;
  }
  else
    mascot.style.top = topRange+"px";

// graph (Ventes)
  topRange = 100;
  var graph=document.getElementById('graph');
  if (graph.offsetTop<topRange)
  {
    graph.style.top = (graph.offsetTop + delta) + "px";
    relaunch = relaunch+1;
  }
  else
    graph.style.top = topRange + "px";

  // colab1
  topRange = 100;
  var colab1=document.getElementById('colab1');
  if (colab1.offsetTop<topRange)
  {
    colab1.style.top = (colab1.offsetTop + delta) + "px";
    relaunch = relaunch+1;
  }
  else
    colab1.style.top = topRange + "px";

  // colab2
  topRange = 130;
  var colab2=document.getElementById('colab2');
  if (colab2.offsetTop<topRange)
  {
    colab2.style.top = (colab2.offsetTop + delta) + "px";
    relaunch = relaunch+1;
  }
  else
    colab2.style.top = topRange + "px";

  // contact
  topRange = 99;
  var contact=document.getElementById('contact');
  if (contact.offsetTop<topRange)
  {
    contact.style.top = (contact.offsetTop + delta) + "px";
    relaunch = relaunch+1;
  }
  else
    contact.style.top = topRange + "px";

  if (relaunch > 0)
  {
//    setTimeout("DescendMascot("+type+")",delay-(5*relaunch));

    if (Interval)
      clearInterval(Interval);
    Interval = setInterval("DescendMascot("+type+")",delay-(5*relaunch));
  }
  else
  {
    if (Interval)
      clearInterval(Interval);
    Interval = 0;
    if (type != 0)
    {
      phase = "UP";
      MonteMascot(type);
    }
  }
}

function AnimeMascot(type)
{
  phase = "DOWN";
  DescendMascot(type);
}


function RetourMascot(type)
{
  if (phase == "DOWN")
    MonteMascot(type);
  else
    DescendMascot(type);
}

