/***********************************/

premierBloc=true;
noSequence = 1;
noMedia = 1;
nbreElementsGalerie = 0;

function afficherHeader(urlVideo,urlDiapo,titreDiapo) {

	var so = new SWFObject("flash/header/header_preload.swf", "flash_ouverture", "980", "303", "8", "#000000");
	
	so.addVariable("allowScriptAccess", "sameDomain");
	so.addParam("wmode", "transparent");
	so.addVariable("quality", "high");
	
	if(urlDiapo == ''){
		
		urlDiapo = new Array();
		
		if(ficheProduction=='1'){
			//Image générique de production
			urlDiapo.push('generique_header_01.jpg');
		}else{
			//Corpo
			urlDiapo.push('Velo_header_07.jpg');
			urlDiapo.push('velo_header_06.jpg');
                        urlDiapo.push('VAA_header_01.jpg');
			urlDiapo.push('VAA_header_02.jpg');
                        urlDiapo.push('BAL_header_01.jpg');
			urlDiapo.push('BAL_header_10.jpg');
			urlDiapo.push('corpo_header_02.jpg');
			urlDiapo.push('corpo_header_03.jpg');
			urlDiapo.push('corpo_header_04.jpg');
			urlDiapo.push('corpo_header_05.jpg');
			urlDiapo.push('corpo_header_06.jpg');
			urlDiapo.push('corpo_header_07.jpg');
			urlDiapo.push('corpo_header_08.jpg');
			

			urlDiapo = randomizeArray(urlDiapo);
		}
		urlDiapo = urlDiapo.join(';');
		titreDiapo = '';
	}
	
	//urlVideo = "";
	
	so.addVariable("ITEM_TO_LOAD", "flash/header/header.swf");
	so.addVariable("PATH_MEDIAS", pathMedias);
	so.addVariable("PATH_MEDIAS_FULL", pathMediasFull);
	so.addVariable("MEDIA_FILENAME", urlVideo);
	so.addVariable("DIAPO_LISTE_IMAGES", urlDiapo);
	so.addVariable("DIAPO_TITRE", titreDiapo);
	
	so.write("header");
}

function afficherEquipe() {
	
	//var so = new SWFObject("flash/header/equipe.swf", "flash_ouverture", "980", "303", "8", "#000000");
	var so = new SWFObject("medias/equipe_header.swf", "flash_ouverture", "980", "303", "8", "#000000");
	
	so.addVariable("allowScriptAccess", "sameDomain");
	//so.addParam("wmode", "transparent");
	so.addVariable("quality", "high");
	
	so.addVariable("PATH_MEDIAS", pathMedias);
	
	so.write("header");
}

function randomizeArray(o){
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
}

function loadFLV(idBloc,pathFile,autoplay) {
	
	//var idBloc = creerBlocFlash();
	
	var so = new SWFObject("flash/player/videoplayer.swf", "flash_player", "480", "360", "8");
	
	so.addParam("wmode", "transparent");
	so.addVariable("allowScriptAccess", "sameDomain");
	so.addVariable("quality", "high");
	
	so.addVariable("MEDIA_FILENAME", pathLibrairie+pathFile);
	so.addVariable("AUTO_PLAY", autoplay);
	
	so.write(idBloc);
}

function stopFLV(idBloc) {
	document.getElementById(idBloc).innerHTML='';
}

function javascriptToFlash(idFlash,nom,valeur)
{
	//window.document[idFlash].SetVariable(nom, valeur);
	var oFlash = document.getElementById(idFlash);
	oFlash.SetVariable(nom,valeur);
}

function creerBlocFlash(){
	
	var idBloc = "emplacementFlash"+noSequence;

	document.write('<div id="'+idBloc+'">');
	document.write('<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><div style="color: #000000;"><strong>Pour visualiser ce contenu, vous devez mettre à jour votre Flash Player</strong></div><div style="color: #000000;"><a style="color: #000000;" href="http://www.macromedia.com/go/getflashplayer" target="_blank">Cliquez ici pour télécharger la version la plus récente</a>.</div><br />');
	document.write('</div>');
	
	noSequence++;
	
	return idBloc;
}

function randomString()
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function afficher(message){
	document.write(message);
}

//Fonction d'affichage d'un sous-titre
function soustitre(soustitre){
	afficher('<span class="soustitre">');
	afficher(soustitre);
	afficher('</span>');
}

//Fonction d'affichage d'un url à l'interne
function urlinterne(urlinterne,nom){
	afficher('<a href="'+urlinterne+'">');
	afficher(nom);
	afficher('</a>');
}

//Fonction d'affichage d'un url à l'externe
function urlexterne(urlexterne,nom){
	afficher('<a href="'+urlexterne+'" target="_blank">');
	afficher(nom);
	afficher('</a>');
}

//Fonction d'affichage d'une image à gauche
function imagegauche(nomimage){
	afficher('<div class="imageleft">');
	afficher('<img src="'+pathLibrairie+nomimage+'" class="imagegauche">');
	afficher('</div>');
}

//Fonction d'affichage d'une image à droite
function imagedroite(nomimage){
	afficher('<div class="imageright">');
	afficher('<img src="'+pathLibrairie+nomimage+'" class="imagedroite">');
	afficher('</div>');
}

//Fonction d'affichage d'une strophe avec marge à gauche
function strophe1(strophe, marge){
	afficher('<div class="strophe" style="margin-left:'+marge+'px;">');
	afficher(strophe);
	afficher('</div>');
}

//Fonction d'affichage d'une strophe alignée au centre
function strophe2(strophe){
	afficher('<div class="strophe" style="text-align:center;">');
	afficher(strophe);
	afficher('</div>');
}

//Création d'un bloc
function ouvrirBloc(titre){
	afficher('<div class="bloc">');
	if(!premierBloc){
		separateur();
	}
	afficher('<div class="bloc_titre">'+titre+'</div>');
	afficher('<div class="bloc_contenu">');
	premierBloc=false;
}

function fermerBloc(){
	afficher('</div>');
	
	gotoTop();
	afficher('</div>');	
}

//Création d'un bloc
function ouvrirBlocGalerie(titre){
	afficher('<div class="bloc">');
	separateur();
	afficher('<div class="bloc_titre">'+titre+'</div>');
	afficher('<div class="bloc_contenu">');
	
	afficher('<table cellpadding="5" cellspacing="0" class="galerie_media">');
	afficher('<tr>');
}

function fermerBlocGalerie(){
	afficher('</tr>');
	afficher('</table>');
		
	afficher('</div>');
	
	gotoTop();
	afficher('</div>');	
}

function separateur(){
	afficher('<div id="separateur"></div>');
}

//Fonction d'affichage d'une strophe alignée au centre
function label(texte){
	afficher('<span class="bloc_label">');
	afficher(texte);
	afficher('</span>');
}

function gotoTop(){
	afficher('<div class="gototop"><a href="'+fichierActuel+'#top"><img class="dontPrint" src="images/goto_top.gif" width="14" height="14" border="0"></a></div>');	
}

function creerNouveauDiv(){

	var id='media'+noMedia;
	
	afficher('<div id="'+id+'" name="'+id+'"></div>');
	noMedia++;
	
	return id;
}

function ajouterMedia(urlMini,urlFull,titre){
	
	if(titre == null){
		var titre = '';
		if(titrePage != null){
			titre = decode(titrePage);
		}
	}
	
	if(nbreElementsGalerie%4==0){
		//Saut de ligne
		afficher('</tr>');
		afficher('<tr>');
	}
	
	nbreElementsGalerie++;
	
	afficher('<td>');
	
	//Nouveau div
	var id =  creerNouveauDiv();
	
	var strFichier = new String(urlFull);
	var extension = strFichier.substr(strFichier.length-3, 4);
	if(extension=='jpg'){
		var typeMedia = 'image';
	}else if(extension=='flv'){
		var typeMedia = 'video';
	}
	
	//Image
	afficher('<a href="#" onclick="return false;" onmouseover="ouvrirPlayer(\''+typeMedia+'\', \''+id+'\', \''+escape(urlFull)+'\', this, \''+escape(titre)+'\');return false;" onmouseout="fermerPlayer(\''+id+'\');" class="galerie_lien">');
	afficher('<img src="'+pathLibrairie+urlMini+'" class="galerie_image" onmouseover="this.style.borderColor=\'#B6E068\';" onmouseout="this.style.borderColor=\'#797979\';">');
	afficher('</a>');
	afficher('<br>');
	
	//Icône
	afficher('<div style="float:right;padding-top:5px;padding-bottom:10px;">');
	afficher('<img src="images/icone_'+typeMedia+'.gif" border="0">');
	afficher('</div>');
	
	afficher('</td>');	
}

function ouvrirPlayer(typeMedia,div,url,obj,titre){
	showBubble(typeMedia, div, url, obj, titre);
}

function fermerPlayer(div){
	stopFLV(div);
	hideBubble(div);
}

/***********************************/

function MM_preloadImages() { 
	//v3.0
	var d=document;
	if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
	for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

function WM_imageSwap(daImage, daSrc){
	var objStr,obj;
	// Check to make sure that images are supported in the DOM.
	if(document.images){
		// Check to see whether you are using a name, number, or object
		if (typeof(daImage) == 'string') {
			// This whole objStr nonesense is here solely to gain compatability
			// with ie3 for the mac.
			objStr = 'document.' + daImage;
			obj = eval(objStr);
			obj.src = daSrc;
		} else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
			daImage.src = daSrc;
		}
	}
}

function xpreload() {
}

function xshowdate() {
	var now    = new Date();
	var hour        = now.getHours();
	var minute      = now.getMinutes();
	var second      = now.getSeconds();
	var monthnumber = now.getMonth() + 1;
	var monthday    = now.getDate();
	var year        = now.getYear();
	if(year < 2000) { year = year + 1900; }
	document.write(year + "/" + monthnumber + "/" + monthday);
}

function openimaget(ximage,xwidth,xheight,xlang)
{
	var xx="00-photot.php?ximage="+ximage+"&xlang="+xlang;
	var xwidth=xwidth + 20;
	var xheight=xheight + 55;
	xtemp = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=0,top=0,width="+xwidth+"px,height="+xheight+"px";
	window.open(xx,"",xtemp);
}

function rediriger(urlPage,nouvellePage){
	
	if(urlPage != ''){
		
		if(nouvellePage != null){
			openPopup(urlPage);
		}else{
			window.location.href = urlPage;
		}
	}
}

function decode(tChaine) {
  while (true) {
    var i = tChaine.indexOf('+');
    if (i < 0) break;
    tChaine = tChaine.substring(0,i) + '%20' + tChaine.substring(i + 1, tChaine.length);
  }
  return unescape(tChaine)
}

function showBubble(typeMedia, div, url, baliseReference, titre)
{	
	url = unescape(url);
	
	var objBubble = document.getElementById(div);
	
	var largeur = 480;
	var hauteur = 450;
	
	objBubble.style.position = 'absolute';
	objBubble.style.width = largeur+'px';
	//objBubble.style.height = hauteur+'px';
	objBubble.style.backgroundColor = 'black';
	objBubble.style.border = 'solid 1px #333333';
	objBubble.style.padding = '12px';
	objBubble.innerHTML = '<div style="float:left;font-size:16px;z-index:99;"><strong>' + unescape(titre) + '</strong></div>';
	//objBubble.innerHTML += '<div style="float:right;">[<a href="#" onclick="hideBubble(\''+div+'\');return false;">fermer</a>]</div>';
	objBubble.innerHTML += '<br><br>';	
	//objBubble.innerHTML += '<div style="padding-left:10; padding-right:5">' + desc + '</div>';
	
	if(typeMedia=='image'){
		objBubble.innerHTML += '<img src="'+pathLibrairie+url+'">';
	}else if(typeMedia=='video'){
		//var idPlayer = 'bubblePlayer'+noMedia;
		var idPlayer = 'bubblePlayer_'+div;
		objBubble.innerHTML += '<div id="'+idPlayer+'"></div>';
		loadFLV(idPlayer,url,1);
	}
	
	//On positionne le bloc
	var posXY = findPosition(baliseReference);
	objBubble.style.top = (posXY[1]-hauteur) + 'px';
	
	//On fait apparaître le bloc
	objBubble.style.display = 'inline';
}

function hideBubble(div)
{
	document.getElementById(div).style.display = 'none';
}

function findPosition(oElement) {
	
	var posX = 0;
	var poxY = 0;
	
	
	if(typeof(oElement.offsetParent) != 'undefined'){
		for( var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent ){
			posX += oElement.offsetLeft;
			posY += oElement.offsetTop;
		}
	}else{
		posX = oElement.x;
		poxY = oElement.y;
	}
	
	if(document.all){
		//alert("IE");
		posY += 10;
	}else{
		//alert("MOZILLA");
		posY -= 50;
	}
	
	return [posX,posY];
}

