/**
 * @author thomasghys
 */

// --------------- PUB -----------
var prevAd = 2;
var maxpub = 0;
var adTimer = null;
var autoMove = false;
var adSpeed = 25000; // timing between 2 images
var adTimer = setTimeout("changePub()", adSpeed);

function pause() {
    autoMove = true;
    change_pauseplay();
}

function clickchiffre(id) {
    pause();
    appchangePub(id);
}

function appchangePub(id) {
/*	fade('home_ad_'+prevAd,100,0,10);*/
   	document.getElementById('home_ad_'+prevAd).style.display='none';
 // document.getElementById('home_ad_'+prevAd).className='hidden';
	fade_test('home_ad_'+id,0,100,1,3);
    document.getElementById('home_ad_'+id).className= '';
    document.getElementById('button_ad_'+prevAd).className= 'button_up';
    document.getElementById('button_ad_'+id).className= 'button_down';
    prevAd = id;
    if (adTimer != null) clearTimeout(adTimer);
    if (autoMove) adTimer = setTimeout("changePub()", adSpeed); 
    return false;
}

function changePub() {
    id = prevAd + 1;
    if (id > maxpub) id = 1;
    appchangePub(id);
}

function precedente() {
    pause();
    id = prevAd - 1;
    if (id <= 0) id = maxpub;
    appchangePub(id);
}

function suivante() {
    pause();
    changePub();
}

function change_pauseplay() {
    if (autoMove) {
        if (adTimer != null) clearTimeout(adTimer);
        adTimer = null;
        autoMove = false;
        document.getElementById("button_play").src="media/images/button_play.gif";
    } else {
        adTimer = setTimeout("changePub()", adSpeed); 
        autoMove = true;
        document.getElementById("button_play").src="media/images/button_pause.gif";
    }
}

function fade_test (div, start, end, time, vitesse) {
   if (start<0 || end > 100) alert("use : start>=0 && end<=100");
   else {
      var elt=document.getElementById(div);
   if (start == 0 && end > 0) {
      elt.style.display = "block";
   }
   else if (start == 0 && end == 0) {
      elt.style.display="none";
   }
   if(document.all)
      elt.style.filter="alpha(opacity="+start+")";
   else
      elt.style.setProperty("-moz-opacity", (start/100), "");
   if (start!=end) {
      if (start<end) {
         setTimeout("fade_test('"+div+"',"+(start+vitesse)+","+end+","+time+","+vitesse+")",time);
      }
      else
         setTimeout("fade_test('"+div+"',"+(start-vitesse)+","+end+","+time+","+vitesse+")",time);
      }
   }
}

// --------------- /PUB -----------

