﻿// NAVIGATION
var tempoNavigation					= 2000;					// ms
var pageEnCours						= '';
var fadeEnCours						= 'none';
var pageG							= new Array();
var pageD							= new Array();
var pageAvecGalerie					= new Array();
pageG['accueil']					= 'contentAccueil';
pageD['accueil']					= 'viewerAccueil';
pageAvecGalerie['accueil']			= 'yes';
pageG['histoire']					= 'contentHistoire';
pageD['histoire']					= 'viewerHistoire';
pageAvecGalerie['histoire']			= 'yes';
pageG['agenda']						= 'contentAgenda';
pageD['agenda']						= 'illustrationAgenda';
pageAvecGalerie['agenda']			= 'none';
pageG['spectacle']					= 'contentSpectacle';
pageD['spectacle']					= 'illustrationSpectacle';
pageAvecGalerie['spectacle']		= 'none';
pageG['media']						= 'contentMedia';
pageD['media']						= 'illustrationMedia';
pageAvecGalerie['media']			= 'none';
pageG['contact']					= 'contentContact';
pageD['contact']					= 'formulaireContact';
pageAvecGalerie['contact']			= 'none';
pageG['lien']						= 'contentLien';
pageD['lien']						= 'illustrationLien';
pageAvecGalerie['lien']				= 'none';
pageG['news']						= 'contentNews';
pageD['news']						= 'illustrationNews';
pageAvecGalerie['news']				= 'none';

window.onload = function(){
	$('#siteLoader').fadeOut(1500);
}

function showPage(target) {
	// on execute que si la page target est differente de celle en cours, et si un changement de page n'est pas en cours
	if ((target != pageEnCours) && (fadeEnCours == 'none')) {
		fadeEnCours					= 'run';					// marque qu'un changement de page est en cours
		if (pageEnCours == '')		{ pageEnCours = 'accueil'; }
		// fade des pages
		$('#'+pageG[pageEnCours]).fadeOut(tempoNavigation, function() {
			$('#'+pageG[target]).fadeIn(tempoNavigation);
		});
		$('#'+pageD[pageEnCours]).fadeOut(tempoNavigation, function() {
			$('#'+pageD[target]).fadeIn(tempoNavigation, function() {
				fadeEnCours			= 'none';
			});
		});
		// traitement post fade
		if (pageAvecGalerie[pageEnCours] == 'yes') {
			stopViewerColonne(pageD[pageEnCours]);				// arret galerie photos en cours
		}
		if (pageAvecGalerie[target] == 'yes') {
			runViewerColonne(pageD[target], vc_tempo);			// lancement de la galerie photos target
		}
		// init var
		pageEnCours					= target;
	}
}

// gestion de l'affichage de la boite de message
function showMessage(action) {
	if (action == 'show') {
		$('#messageBox').fadeIn(4000, function() {
				messageBox_timer	= setTimeout("showMessage('hide')", 5000);
		});
	} else {
		$('#messageBox').fadeOut(4000);
	}
}

// MENU GENERAL
function showMenu() {
	var content			= '';
	content				+= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="445" width="200">';
	content				+= '<param name="movie" value="../images/menu.swf">';
	content				+= '<param name="quality" value="best">';
	content				+= '<param name="play" value="true">';
	content				+= '<param name="wmode" value="transparent">';
	content				+= '<embed wmode="transparent" height="445" pluginspage="http://www.macromedia.com/go/getflashplayer" src="../images/menu.swf" type="application/x-shockwave-flash" width="200" quality="best" play="true">';
	content				+= '</object>';
	$('#menu').html(content);
}

// SCROLLER PAGE
var scrollerHeight					= 600;
var textestyle;
var scrollEnCours					= 'none';
var positionTexte;
var hauteurTexte;
function pageUp() {
	if  (scrollEnCours == 'none') {
		scrollEnCours				= 'run';
		hauteurTexte				= document.getElementById(pageG[pageEnCours]+'Texte').offsetHeight - 500;
		positionTexte				= document.getElementById(pageG[pageEnCours]+'Texte').offsetTop * (-1);
		if (positionTexte < hauteurTexte) {
			$('#'+pageG[pageEnCours]+'Texte').animate({'top': '-=' + scrollerHeight / 2 + 'px'}, 500, function() {
				scrollEnCours		= 'none';
			});
		} else {
			scrollEnCours			= 'none';
		}
	}
}
function pageDown() {
	if  (scrollEnCours == 'none') {
		scrollEnCours				= 'run';
		positionTexte				= document.getElementById(pageG[pageEnCours]+'Texte').offsetTop * (-1);
		if (positionTexte > 0) {
			$('#'+pageG[pageEnCours]+'Texte').animate({'top': '+=' + scrollerHeight / 2 + 'px'}, 500, function() {
				scrollEnCours		= 'none';
			});
		} else {
			scrollEnCours			= 'none';
		}
	}
}
function handle(delta) {
	if (document.getElementById(pageG[pageEnCours]+'Texte')) {
        if (delta < 0)
			pageUp();
        else
			pageDown();
	}
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;

// VIEWER COLONNE
var vc_tempo						= 12000;					// ms
var vc_timer						= new Array();
var vc_media						= new Array();
var vc_mediaTxt						= new Array();
var vc_mediaIndex					= new Array();

function createViewerColonne(target) {
	var content;
	// calques conteners images
	content							= '<div id="'+target+'1" class="viewerColonneElement" ';
	content							+= 'onmouseover="javascript:this.style.cursor = \'pointer\';" ';
	content							+= 'onclick="javascript:openGalerie(\''+target+'\')">';
	content							+= '</div>';
	content							+= '<div id="'+target+'2" class="viewerColonneElement" ';
	content							+= 'onmouseover="javascript:this.style.cursor = \'pointer\';" ';
	content							+= 'onclick="javascript:openGalerie(\''+target+'\')">';
	content							+= '</div>';
	// boutons de navigation
	content							+= '<div id="openGalerie'+target+'" ';
	content							+= 'style="background-image: url(../images/ouvrirGal.gif); background-repeat: no-repeat; position: absolute; top: 622; left: 3; width: 20px; height: 20px; z-index: 3" ';
	content							+= 'onmouseover="javascript:this.style.cursor = \'pointer\';" ';
	content							+= 'onclick="javascript:openGalerie(\''+target+'\')">';
	content							+= '</div>';
	content							+= '<div id="runGalerie'+target+'" ';
	content							+= 'style="background-image: url(../images/runGal.gif); background-repeat: no-repeat; position: absolute; top: 622; left: 26; width: 20px; height: 20px; z-index: 3; display: none" ';
	content							+= 'onmouseover="javascript:this.style.cursor = \'pointer\';" ';
	content							+= 'onclick="javascript:runViewerColonne(\''+target+'\', \''+vc_tempo+'\')">';
	content							+= '</div>';
	content							+= '<div id="stopGalerie'+target+'" ';
	content							+= 'style="background-image: url(../images/stopGal.gif); background-repeat: no-repeat; position: absolute; top: 622; left: 26; width: 20px; height: 20px; z-index: 3" ';
	content							+= 'onmouseover="javascript:this.style.cursor = \'pointer\';" ';
	content							+= 'onclick="javascript:stopViewerColonne(\''+target+'\')">';
	content							+= '</div>';
	$('#'+target).html(content);
}

function runViewerColonne(target, tempo) {
	$(document).ready(function () {
		$('#stopGalerie'+target).css("display", "block");
		$('#runGalerie'+target).css("display", "none");
		if (!vc_timer[target]) {
			$('#'+target+'1').css("display", "none");
			$('#'+target+'1').css("z-index", 1);
			$('#'+target+'1').html("<img src=\"../../../upLoad/full/"+vc_media[target][1]+"\" border=0>");
			$('#'+target+'2').css("z-index", 2);
			$('#'+target+'2').html("<img src=\"../../../upLoad/full/"+vc_media[target][0]+"\" border=0>");
			vc_mediaIndex[target]		= 1;
		} else {
			var fadeTempo				= tempo / 5;
			var temp1					= 1;
			var temp2					= 2;
			if (Math.abs($('#'+target+'1').css("z-index")) == 1) {
				temp1					= 2;
				temp2					= 1;
			}
			$('#'+target+'1').css("z-index", temp1);
			$('#'+target+'2').css("z-index", temp2);
			$('#'+target+temp1).fadeOut(fadeTempo*2);
			$('#'+target+temp2).fadeIn(fadeTempo, function() {
				$('#'+target+temp1).css("display", "none");
				$('#'+target+temp1).html("<img src=\"../../../upLoad/full/"+vc_media[target][vc_mediaIndex[target]]+"\" border=0>");
			});
			vc_mediaIndex[target]++;
			if (vc_mediaIndex[target] == vc_media[target].length) {
				vc_mediaIndex[target]	= 0;
			}
		}
		vc_timer[target]				= setTimeout("runViewerColonne('"+target+"', "+tempo+")", tempo);
	});
}

function stopViewerColonne(target) {
	$('#stopGalerie'+target).css("display", "none");
	$('#runGalerie'+target).css("display", "block");
	if (vc_timer[target]) {
		window.clearTimeout(vc_timer[target]);
	}
}

// VIEWER GALERIE
var indexImgGal				= '';
var fadeGalEnCours			= 'none';

function openGalerie(target) {
	indexImgGal				= '';
	stopViewerColonne(pageD[pageEnCours]);
	var content				= '<center>';
	content 				+= '<table border="0" cellspacing="0" cellpadding="0"><tr><td valign="bottom">';
	content					+= '<img src="../images/footerViewerGalerie.gif" />';
	content					+= '</td><td valign="top">';
	content 				+= '<table class="viewerCadre" width="875px"><tr><td valign="top" width="310">';
	content					+= '<div id="viewerThumbGalerie">';
	var i					= 0;
	var j					= 0;
	while (vc_media[target][i]) {
		content				+= '<a href="javascript:showImgGal(\'imgGal'+i+'\');"><img width="60px" src="../../../upLoad/thumb/'+vc_media[target][i]+'" class="imgLink" /></a>';
		if (j == 4) {
			content			+= '<br>';
			j 				= -1;
		}
		i++;
		j++;
	}
	content					+= '</div>';
	content 				+= '</td><td valign="top" width="354">';
	var i					= 0;
	while (vc_media[target][i]) {
		content				+= '<div id="imgGal'+i+'" class="viewerGalerie">';
		content				+= '<img src="../../../upLoad/full/'+vc_media[target][i]+'" />';
		content				+= '</div>';
		i++;
	}
	content					+= '</td><td valign="top">';
	var i					= 0;
	while (vc_mediaTxt[target][i]) {
		content				+= '<div id="imgGal'+i+'txt" class="viewerGalerieTxt">';
		content				+= vc_mediaTxt[target][i];
		content				+= '</div>';
		i++;
	}
	content					+= '</td></tr></table>';
	content					+= '</td><td valign="top">';
	content					+= '<img src="../images/titreViewerGalerie.gif" />';
	content					+= '</td></tr></table>';
	content					+= '<br><a href=\'javascript:closeGalerie();\'>:: fermer ::</a>';
	content					+= '</center>';

	$('#viewerGaleriesFullScreen').fadeIn(3000, function() {
		$('#viewerGaleriesFullScreen').html(content);
		showImgGal('imgGal0');
	});
}

function closeGalerie() {
	$('#viewerGaleriesFullScreen').html('&nbsp;');
	$('#viewerGaleriesFullScreen').fadeOut(3000, function() {
		runViewerColonne(pageD[pageEnCours], vc_tempo);
	});
}

function showImgGal(target) {
	if ((fadeGalEnCours == 'none') && (target != indexImgGal)) {
		if (indexImgGal != '') {
			$('#'+indexImgGal).css("display", "none");
			$('#'+indexImgGal+'txt').css("display", "none");
		}
		fadeGalEnCours		= 'yes';
		$('#'+target).fadeIn(2000, function() {
			$('#'+target+'txt').fadeIn(2000);
			fadeGalEnCours	= 'none';
		});
		indexImgGal			= target;
	}
}

// MEDIA
function openMedia(media, typemedia) {
	var content				= '<center><br><br>';
	content					+= '<img src="../images/titreViewer.gif" border="0" alt="">';
	content 				+= '<table class="viewerCadre"><tr><td>';
	// on stop la galerie eventuellement en cours
	if (pageAvecGalerie[pageEnCours] == 'yes') {
		stopViewerColonne(pageD[pageEnCours]);				// arret galerie photos en cours
	}
	if (typemedia == 1) {				// video FLV 16:9 - 480x272 px
		content 			+= '<object id="playerMedia" data="playerVideo169.swf" type="application/x-shockwave-flash" height="272" width="480">';
		content 			+= '<param name="movie" value="playerVideo169.swf"/>';
		content 			+= '<param name="quality" value="best"/>';
		content 			+= '<param name="play" value="true"/>';
		content 			+= '<param name="FlashVars" value="flv='+media+'">';
		content 			+= '</object>';
	} else if (typemedia == 2) {		// video FLV 4:3 - 384x288 px
		content 			+= '<object id="playerMedia" data="playerVideo43.swf" type="application/x-shockwave-flash" height="288" width="384">';
		content 			+= '<param name="movie" value="playerVideo43.swf"/>';
		content 			+= '<param name="quality" value="best"/>';
		content 			+= '<param name="play" value="true"/>';
		content 			+= '<param name="FlashVars" value="flv='+media+'">';
		content 			+= '</object>';
	} else if (typemedia == 3) {		// son mp3
		content 			+= '<object id="playerMedia" data="playermedia.swf" type="application/x-shockwave-flash" height="150" width="400">';
		content 			+= '<param name="movie" value="playermedia.swf"/>';
		content 			+= '<param name="quality" value="best"/>';
		content 			+= '<param name="play" value="true"/>';
		content 			+= '<param name="FlashVars" value="media='+media+'">';
		content 			+= '</object>';
	} else if (typemedia == 4) {		// fichier flash
		content				+= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="300" width="350">';
		content				+= '<param name="movie" value="../../../upLoad/media/'+media+'">';
		content				+= '<param name="quality" value="best">';
		content				+= '<param name="play" value="true">';
		content				+= '<embed height="300" pluginspage="http://www.macromedia.com/go/getflashplayer" src="../../../upLoad/media/'+media+'" type="application/x-shockwave-flash" width="350" quality="best" play="true">';
		content				+= '</object>';
	} else if (typemedia == 5) {				// video FLV 16:9 - 560x304 px
		content 			+= '<object id="playerMedia" data="playerVideo169-560x304.swf" type="application/x-shockwave-flash" height="304" width="560">';
		content 			+= '<param name="movie" value="playerVideo169-560x304.swf"/>';
		content 			+= '<param name="quality" value="best"/>';
		content 			+= '<param name="play" value="true"/>';
		content 			+= '<param name="FlashVars" value="flv='+media+'">';
		content 			+= '</object>';
	} else {
		// pas de type reconnu
	}
	content					+= '</td></tr></table>';
	content					+= '<img src="../images/footerViewer.gif" border="0" alt="">';
	// lien de fermeture du viewer pour la video et le son
	if ((typemedia == 1) || (typemedia == 2) || (typemedia == 3)) {
		content				+= '<br><br><a href=\'javascript:stopMedia();\'>:: fermer ::</a>';
	// pour les autres media
	} else {
		content				+= '<br><br><a href=\'javascript:closeMedia();\'>:: fermer ::</a>';
	}
	$('#viewerFullScreen').fadeIn(3000, function () {
		$('#viewerFullScreen').html(content);
	});
	content					+= '</center>';
}

// function d'arret de player video ou son
function stopMedia() {
	document.getElementById('playerMedia').SetVariable('instruction', 'stop');
}

// function de fermeture du viewer
function closeMedia() {
	var content				= '&nbsp;';
	$('#viewerFullScreen').html(content);
	$('#viewerFullScreen').fadeOut(1500, function() {
		if (pageAvecGalerie[pageEnCours] == 'yes') {
			runViewerColonne(pageD[pageEnCours], vc_tempo);			// lancement de la galerie photos eventuellement en cours
		}
	});
}

