/* animations de la page d'accueil de DBI 2010 */

addLoadEvent( function() {init_accueil()} )

// INITS
function init_accueil() {
	rounded_init()					// Arrondi sur les coins des sous-menus
	photos_init()					// Placement ds photos
}


// Paramètres
var	tab_opacity=new Array(0,15,100,15,100,15,100,15,100), 	// opacité des photos
	photos_delayinit=800,									// Délai avant l'affichage de la première
	photos_interval=150										// Délai entre 2 affichages


// Boucle d'affichage des images, lance l'affichage des textes à la fin
function photos_init(photo_nb) {
	if(typeof(photo_nb)=='undefined') var photo_nb=-1
	var delay=photo_nb==-1? photos_delayinit : photos_interval
	photo_nb=get_randomphoto()
	if(photo_nb!=-1) setTimeout('photo_on('+photo_nb+')',delay)
	else text_move()
}

// Détermine quelle photo afficher
// Retourne le nr de photo (0..n) si OK, ou -1 si toutes les photos sont déjà affichées
function get_randomphoto() {
	var next0=1+Math.floor(Math.random()*4),read=0,img_nb=0,next=next0
	do {
		read++
		if(tab_opacity[img_nb]>0) next--
		if(next) {
			img_nb++
			if(img_nb==tab_opacity.length) img_nb=0
		}
	} while(read<tab_opacity.length*next0 && next>0)
	return(next? -1 : img_nb)
}

// Positionnement et affichage de l'image Nr photo_nb (0..n)
function photo_on(photo_nb) {
	var x,y,obj
	y=Math.floor(photo_nb/3)
	x=photo_nb-3*y
	if(tab_opacity[photo_nb]) {
		obj=document.getElementById('photo'+photo_nb)
		if(obj) {
			obj.style.left=(x*175+10)+'px'
			obj.style.top=(y*175+8)+'px'
			obj.style.opacity=tab_opacity[photo_nb]/100
			obj.style.filter="alpha(opacity="+tab_opacity[photo_nb]+')'
			obj.style.display='block'
			tab_opacity[photo_nb]=-tab_opacity[photo_nb]	// verrouille cette photo pour la prochaine recherche aléatoire
		}
	}
	photos_init(1)
}


// -------- Textes
var grille=new Array(-10,-1,-10,-1,-10,-1,-10,-1,-10),
	couleur=new Array('ffffff','ffffff','ffffff','ffffff','ffffff','ffffff','ffffff','ffffff','ffffff'),
	news=new Array(
		'<b>Conseil et§courtage</b>§en fichiers BtoB§Français et§internationaux'
		,'<b>Gestion</b>§de bases§de données'
		,'<b>Audit</b>§et connaissance§client'
		,'<b>Bienvenue</b>§Welcome§Willkommen§Bienvenida§Benvenuto'
	),
	i,x,y,n,flying=-1,
	max=2,			// nb de textes allumés simultanément
	delay=1600,		// delai entre 2 actions
	step=8,			// step alpha
	textes_init=false


// Affichage aléatoire des textes.
// Cette fonction et lancée à la fin de l'initialisation des photos
function text_move() {
	var t,i,j,todel

	if(!textes_init) {
		// génération des éléments HTML
		// Ils sont placés dans le conteneur 'textes-container' de la page HTML afin d'être positionnés au bon endroit
		textes_init=true
		var html='',container=document.getElementById('textes-container')
		if(container) {
			for(i in grille) {
				if(grille[i]!=-10) {
					y=Math.floor(i/3)
					x=i-3*y
					html+= '<table border="0" cellpadding="0" cellspacing="0" width="167" '
						+ 'id="flying-container-'+i+'" style="z-index:1;position:absolute;left:'+(11+x*175)+'px;top:'+(7+y*175)+'px"><tr>'
						+ '<td id="flying-'+i+'" style="text-align:center;vertical-align:middle;width:167px;height:167px;color:#'+couleur[i]
						+ ';font-size:17px">&nbsp;</td></tr></table>'
				}
			}
			container.innerHTML=html
		}
	}

	// détermination du texte à allumer
	flying++;if(flying==news.length) flying=0		// texte à afficher
	do { t=Math.floor((grille.length)*Math.random());if(t==grille.length) t-- } while(grille[t]>-1 || grille[t]==-10)	// endroit où le placer

	// détermination du texte à éteindre, s'il existe
	todel=flying-max; if(todel<0) todel+=news.length
	for(i in grille) if(grille[i]==todel) {
		x_fade('flying-container-'+i,'100:0:'+step)
		grille[i]=-1
	}

	// affichage du nouveau
	grille[t]=flying
	document.getElementById('flying-'+t).innerHTML=news[flying].replace(/§/g,'<br />')
	x_fade('flying-container-'+t,'0:100:'+step)	
	setTimeout("text_move()",delay)
}
