/**********************
CUSTOMIZABLE
***********************/
var images_total = 10; // total number of images available for display
var images_download_max = 6; // total number of images to download on each page (to limit bandwith)
var images_prefix = 'fileadmin/templates/main/images/animation/pog';
var images_suffix = '.gif';
var pog_total = 4;
/**********************
NOT CUSTOMIZABLE
***********************/
var images = new Array();
var images_obj = new Array();
var images_pogs = new Array();
var images_cursor = 0;
var pog_last = 0;
var pog_random_ajust = 100 / ( pog_total - 1 );
var images_ramdom_ajust = 100 / images_total;
 
function start_animation() {
 var i;
 var selected_img;
 var selected;
 var z = 0;
 if ( images_download_max <= pog_total ) return false;
 // select randow images according to the max images to download
 for ( i=0; i<images_download_max ; i++ ) {
  selected = false;
  while ( ! selected ) {
   // select a random image
   selected_img = Math.round( ( Math.random() * 100 / images_ramdom_ajust ) );
   // make sure it is not already selected
   if ( ! in_array( images , selected_img ) ) selected = true;
   z++;
   if ( z > 200 ) selected = true;
  }
  // add image in array
  images.push( selected_img );
  // force download
  images_obj[ selected_img ] = new Image();
  images_obj[ selected_img ].src = images_prefix + selected_img + images_suffix;
 }
 // construc images_pog array
 for ( i=0; i<pog_total; i++ ) {
  images_pogs.push( true );
 }
 // start animation
 interval = window.setInterval("anim()", 2000);
}
 
function anim() {
 // select pog
 var pog = select_pog();
 var pog_id = 'pog' + pog;
 // select imgage
 var img = select_img();
 // keep track of wich pog display wich images
 images_pogs[pog] = img;
 // change image source
 document.getElementById(pog_id).src = images_prefix + img + images_suffix;
}
 
function in_array( arr , x ) {
 var arr;
 var x;
 var e;
 for ( i=0; i<arr.length; i++ ) {
  if ( arr[i] == x ) {
   return true;
  }
 }
 return false;
}
 
function select_img() {
 var selected = false;
 var loop_protect = false;
 var img;
 var z = 0;
 var key;
 while ( ! selected ) {
  key = Math.round( ( Math.random() * 100 / ( 100 / ( images.length - 1 ) ) ) );
  img = images[ key ];
  if ( ! in_array( images_pogs , img ) ) selected = true;
  z++;
  if ( z > 200 ) {
   selected = true;
  }
 }
 return img;
}
 
function select_pog() {
 var selected = false;
 var pog;
 var z = 0;
 while ( ! selected ) {
  pog = Math.round( ( Math.random() * 100 / pog_random_ajust ) );
  if ( pog != pog_last ) selected = true;
  z++;
  if ( z > 200 ) selected = true;
 }
 pog_last = pog;
 return pog;
}
 

var menuTimeout = new Array()
 
function getObj(name) {
 if (document.getElementById) {
  this.obj = document.getElementById(name)
  this.style = document.getElementById(name).style
 } else
 if (document.all) {
  this.obj = document.all[name]
  this.style = document.all[name].style
 }
}
 
function afficher(choixmenu){
 var DHTML = (document.getElementById || document.all)
 if (DHTML) {
  if (menuTimeout[choixmenu]) {
   clearTimeout(menuTimeout[choixmenu])
  }
  x = new getObj(choixmenu)
  x.style.visibility="visible"
 }
}
 
function afficherdelai(choixmenu) {
 var DHTML = (document.getElementById || document.all)
 if (DHTML) {
  if (menuTimeout[choixmenu]) {
   clearTimeout(menuTimeout[choixmenu])
  }
  menuTimeout[choixmenu] = setTimeout("afficher('"+choixmenu+"')",100)
 }
}
 
function cacher(choixmenu) {
 var DHTML = (document.getElementById || document.all)
 if (DHTML) {
  if (menuTimeout[choixmenu]) {
   clearTimeout(menuTimeout[choixmenu])
  }
  menuTimeout[choixmenu] = setTimeout("timeoutcacher('"+choixmenu+"')",250)
 }
}
 
function timeoutcacher (choixmenu){
 var DHTML = (document.getElementById || document.all)
 if (DHTML) {
  x = new getObj(choixmenu)
  x.style.visibility="hidden"
 }
}