/*--------------------------------------------------------------------------------
Javascript Website Ninamondo
jchappe@club-internet.fr
Nov.2008
--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
Fonctions player flash
--------------------------------------------------------------------------------*/
var flashMovie;
function initFlash() {
  if (document.getElementById) {
    flashMovie = document.getElementById("moviePlayer");
  }
}

// loading media in the player
function loadMedia(url) {
  if (flashMovie) {
    flashMovie.loadMedia(url);
  }
} 

// random play track in the player
function randomPlay() {
  if (flashMovie) {
    flashMovie.randomPlay();
  }
}
    
// random play jingle in the player
function randomExtraPlay() {
  if (flashMovie) {
    flashMovie.randomExtraPlay();
  }
}
   
// stop playing current track in the player
function stopMP3() {
  if (flashMovie) {
    flashMovie.stopMP3();
  }
}

// stop playing current jingle in the player
function stopExtraMP3() {
  if (flashMovie) {
    flashMovie.stopExtraMP3();
  }
}
    
// playing a selected track in the player
function playID(id) {
  if (flashMovie) {
    flashMovie.playID(id);
  }
}
    
// playing a selected jingle in the player
function playExtraID(id) {
  if (flashMovie) {
    flashMovie.playExtraID(id);
  }
}
  
// wait for the page to fully load before initializing
//~ window.onload = initFlash;


/*--------------------------------------------------------------------------------
Fonctions 'boules'
--------------------------------------------------------------------------------*/
// init. values
sineValue  = 0;
sineActive = 0;

var yBall = new Array(5);
var xBall = new Array(5);

yBall[0]=150;			/* les ordonnées initiales des 5 boules */
yBall[1]=106;
yBall[2]=73;
yBall[3]=92;
yBall[4]=200;	// 220;

xBall[0]=-466;			/* les abcisses initiales des 5 boules */
xBall[1]=-285;
xBall[2]=150;
xBall[3]=250;
xBall[4]=350;	// 320;


function initBalls()
{
  for(i=0;i<5;i++)
  {
    document['sq'+i+'_back'].style.position = 'absolute';	/* remplace simplement l'expression : style="position:absolute; left: 50%; margin-left:-460;" */
    document['sq'+i+'_back'].style.left = '50%';
    document['sq'+i+'_back'].style.marginLeft = xBall[i];

    document['sq'+i+'_top'].style.position = 'absolute';
    document['sq'+i+'_top'].style.left = '50%';
    document['sq'+i+'_top'].style.marginLeft = xBall[i];

    Element.setOpacity('ball_'+i+'_top', 0.0);			/* les boules illuminées ('ball_n_top') démarrent en invisibles (opacité minimale) */
  }
}


function doSineWave()
{
  if (sineActive)
  {
    if (sineValue > 6.00)
      sineValue = 0;
    else
      sineValue+= 0.22;

    for (i=0; i<5; i++)
    {
      // document['sq'+i].style.top = (Math.sin(sineValue-(0.44*i))*20);
      document['sq'+i+'_back'].style.bottom = yBall[i] + (Math.sin(sineValue-(0.44*3*i))*6);
      document['sq'+i+'_top'].style.bottom = yBall[i] + (Math.sin(sineValue-(0.44*3*i))*6);
    }

    // setTimeout("doSineWave()",20,"Javascript")
    setTimeout("doSineWave()",110,"Javascript");
  }
}


function SineStartStop(szLangTxt) {
  initSine();
  txt = sineActive ? "Stop" : "Start";
  stopzeballs.innerHTML = "<a href=\"javascript:SineStartStop('" + szLangTxt + "');\">" + szLangTxt + " " + txt + "</a>";
}


function initSine() {
  if(!sineActive) {
    sineActive = 1;
    doSineWave();
  }
  else
    sineActive = 0;
}


/*--------------------------------------------------------------------------------
Play/stop jingle sur passage de la souris sur les boules, avec fade in/out
luminescence.
--------------------------------------------------------------------------------*/
function BallIn(num)
{
  new Effect.Opacity('ball_'+num+'_top', {duration:0.5, from:0.0, to:1.0});	/* fade in lumière de la boule 'num' (p.ex.: 'ball_1_top') */
  playExtraID(num);
}

function BallOut(num)
{
  new Effect.Opacity('ball_'+num+'_top', {duration:0.8, from:1.0, to:0.0});	/* fade out lumière de la boule 'num' (p.ex.: 'ball_1_top') */
  stopExtraMP3();
}


/*--------------------------------------------------------------------------------
Travail sur le chargement des images.
ShowAll() est appelé sur <body onload>, parce qu'il faut savoir que le onload
de body n'est exécuté que... Quand toutes les images de la page sont chargées
(c'est exactement ce qu'on recherche !).
--------------------------------------------------------------------------------*/
function ShowAll()
{
    for(i=0;i<5;i++)
    {
      document['sq'+i+'_back'].style.visibility = "visible";
      document['sq'+i+'_top'].style.visibility = "visible";
    }

    document.getElementById("floral_left").style.background = "url('images/frame_left.gif') no-repeat";
    document.getElementById("floral_left").style.visibility = "visible";

    document.getElementById("content").style.visibility = "visible";

    document.getElementById("menu_bak").style.background = "url('images/menu_bak.jpg') no-repeat";
    document.getElementById("menu_bak").style.visibility = "visible";

    for(i=1;i<10;i++)
    {
      id='menu_'+i;
      document.getElementById(id).style.visibility = "visible";
    }

    document.getElementById("butterfly_1").style.visibility = "visible";

    document.getElementById("language").style.visibility = "visible";

    document.getElementById("player").style.visibility = "visible";
    initFlash();
    setTimeout("playID(0)",200,"Javascript");		// bon, c'est un truc de malade, mais il faut une TEMPO !! entre la déclaration du player (var FlashMovie dans initFlash) et son utilisation !!!
}

/*---------------------------------eoscript-------------------------------------*/
