centerDots = new Array();
liteDots = new Array();

function initMapAnimation()
{
  if ($("map") != undefined)
  {
    centerDots = $$('img.centerLocation');
    setInterval("stepMapAnimation()", 500);
  }
}
function setDotColor(dot, colorIndex)
{
  var currentSrc = dot.src;
  var n = currentSrc.indexOf("carte-sigcentre");
  var path = currentSrc.substring(0, n);
  dot.src = path + "carte-sigcentre-coul" + colorIndex + ".gif";
}
function restoreDotColor(dot)
{
  var currentSrc = dot.src;
  var n = currentSrc.indexOf("carte-sigcentre");
  var path = currentSrc.substring(0, n);
  dot.src = path + "carte-sigcentre.gif";
}
function stepMapAnimation()
{
  var i;
  var newLiteDots = new Array();
  for (i=0; i<liteDots.length; i++)
  {
    if (--liteDots[i].timeRemaining == 0)
    {
      restoreDotColor(liteDots[i].element);
    }
    else
    {
      newLiteDots.push(liteDots[i])
    }
  }
  liteDots = newLiteDots;
  var n = Math.ceil(Math.random()*3);
  for (i=0; i<n; i++)
  {
    var k = Math.floor(Math.random() * centerDots.length);
    if (centerDots[k].id != "centresIdf")
    {
      setDotColor(centerDots[k], Math.floor(Math.random() * 4));
      liteDots.push({
        element: centerDots[k],
        timeRemaining: 2});
    }
  }
}

function mapIdfRollover()
{
  //$('centresIdfOver').show(); 
  imageRollover($('centresIdf'));
  imageRollover($('carte'));
  //$('carteIdfOver').show();
}
function mapIdfRollout()
{
  //$('centresIdfOver').hide(); 
  imageRollout($('centresIdf'));
  imageRollout($('carte'));
  //$('carteIdfOver').hide();
}

function gotoCenter(url)
{
  if (url.substr(0, 7) == 'http://')
  {
    window.open(url, 'extCentre');
  }
  else
  {
    location.href = url;
  }
}
function imageRollover(e)
{
  if (e == null)
    e = this;
  else if (e.target)
    e = e.target;
  if (e.origSrc == null || e.origSrc == e.src)
  {
    e.origSrc = e.src;
    var n = e.src.indexOf('.gif');
    var overSrc = e.src.substr(0, n) + '-over.gif';
    e.src = overSrc;
  }
}
function imageRollout(e)
{
  if (e == null)
    e = this;
  else if (e.target)
    e = e.target;
  if (e.origSrc != null && e.origSrc != e.src)
  {
    e.src = e.origSrc;
  }
}
function menuRollover()
{
  imageRollover(this);
  var s = this.id.substring(5);
  var e = $("bullet_"+s);
  if (e != undefined)
  {
    imageRollover(e);
    if (!e.hasClassName("selected"))
    {
      e.show();
    }
  }
}
function menuRollout()
{
  imageRollout(this);
  var s = this.id.substring(5);
  var e = $("bullet_"+s);
  if (e != undefined)
  {
    imageRollout(e);
    if (!e.hasClassName("selected"))
    {
      e.hide();
    }
  }
}
function homeRollover()
{
  imageRollover($("homeanimation"));
  imageRollover($("satellite"));
}
function homeRollout()
{
  imageRollout($("homeanimation"));
  imageRollout($("satellite"));
}
function initMenu()
{
  var imgs = $$('ul#mainMenu img');
  imgs.each(function(e) {
    if (e.src.indexOf('sep.gif') < 0)
    {
      e.onmouseover = menuRollover;
      e.onmouseout = menuRollout;
    }
  });
  var e = $('homeanimation');
  if (e != null)
  {
    e.onmouseover = homeRollover;
    e.onmouseout = homeRollout;
  }
  e = $('satellite');
  if (e != null)
  {
    e.onmouseover = homeRollover;
    e.onmouseout = homeRollout;
  }
  e = $$('#logo img')[0];
  e.onmouseover = imageRollover;
  e.onmouseout = imageRollout;
}
function initAll()
{
  initMenu();
  initMapAnimation();
}
window.onload = initAll;
