var isFondOK = false;
var pauseLogo = 3000;
var transitionEnCours = false;
var pagePrec = "accueil";

function go() 
{	
	if ($.browser.msie && $.browser.version <= 6) alert("Attention : votre navigateur est trop ancien pour afficher ce site. Nous vous recommandons de mettre à jour Internet Explorer ou de télécharger un navigateur alternatif comme Mozilla Firefox ou Google Chrome.");
	
	$(".page").hide();
	$("#global").css('visibility', 'visible');
	$("#bandeHaut, #bandeBas").fadeTo(0,0);
	
	$("#video, #btnVideo, #btnFermerVideo, #fondBtnVideo").hide();
	$("#btnVideo").appendTo("body");
	$("#btnFermerVideo").appendTo("body");
	
	// Affichage du logo au centre de l'écran		
	l = $(window).width(); h = $(window).height();
	t = (h - 188) >> 2; l = (l - 484) >> 1;
	if (t<0) t=0; if (l<0) l=0;	
	$('#logoIntro').css('top', t+"px").css('left', l+"px").hide().css('visibility', 'visible').fadeIn(1500);
	$('#loading').css('top', (t-40)+"px").css('left', (l-50)+"px").hide().css('visibility', 'visible').fadeIn(1500);

	// Attente de la fin du chargement du fond
	setTimeout("waitFond();", pauseLogo);
	
	// Gestion du redimensionnement
	window.onresize = positionnerElements;
	
	// Gestion des liens entre les pages
	$("a.lien").click(function(){
		pageNew = $(this).attr('id');		
		pageNew = pageNew.substr(4);
		k = pageNew.lastIndexOf("_");
		pageNew = pageNew.substr(0,k);		
		transitionPages(pageNew);
		return false;
	});	
	
	// Gestion des zoom dans les diaporamas
	$("img.imgDiapo").bind("mouseenter", function(){
		src = $(this).attr('src');
		alt = $(this).attr('alt');
		iSlash = src.lastIndexOf('/');
		src = src.substring(0, iSlash);
		src = src+"/big/"+alt;		
		$(this).parent().parent(".page").append("<img src='"+src+"' id='photoBig' />");		
	})
	.bind("mouseleave", function(){
		$("#photoBig").remove();
	});
	 
	// Gestion des flèches de défilement des diaporamas
	$("img.precDiapo").click(function(){iDiapo--; majDiapo();});
	$("img.suivDiapo").click(function(){iDiapo++; majDiapo();});
	$("img.precDiapo, img.suivDiapo").bind("mouseenter", function(){$(this).fadeTo(0,0.8);}).bind("mouseleave", function(){$(this).fadeTo(0,1);})
}

function transitionPages(pageNew)
{
	if (transitionEnCours) return;
	transitionEnCours = true;
	
	exit_page();
	$("#"+page).fadeTo(0,1).fadeTo(500,0, function(){
		$(this).hide();
		if (positionsPages[page]['x'] != positionsPages[pageNew]['x'] || positionsPages[page]['y'] != positionsPages[pageNew]['y'])
		{
			pagePrec = page;
			page = pageNew;
			changementDePage(page);
		}			
		else
		{
			pagePrec = page;
			page = pageNew;
			apparitionContenu();
		}
	});
}

function changementDePage(page)
{
	xPage = getGlobalX()-positionsPages[page]['x'];
	yPage = getGlobalY()-positionsPages[page]['y'];
	getFlashObject('heral').changementDePage(xPage, yPage);
}


function positionnerElements()
{
	dimensionnerFlash();	
	$("#global").css("top", getGlobalY()+"px").css("left", getGlobalX()+"px");
	getFlashObject('heral').positionnerFond(getGlobalX()-positionsPages[page]['x'], getGlobalY()-positionsPages[page]['y']);
	positionnerElementsPage();
}

function getGlobalX() {return ($(window).width() - 850) >> 1;}
function getGlobalY() {return ($(window).height() - 550) >> 1;}


// Fonction appelée par AS3 pour dire que le chargement de la photo de fond est terminé
function photoDeFondOK() {isFondOK = true;}


// Attente que le fond soit chargé
// Puis retrait du logo et apparition du fond
function waitFond()
{
	if (!isFondOK) setTimeout("waitFond();", 100);
	else
	{
		$("#logoIntro, #loading").fadeOut(600, function(){
			$(this).remove();
			xDeb = $(window).width()>>1; yDeb = $(window).height()>>1;
			xFin = getGlobalX()-positionsPages[page]['x'];
			yFin = getGlobalY()-positionsPages[page]['y'];
			setTimeout("getFlashObject('heral').afficherFond("+xDeb+","+yDeb+","+xFin+","+yFin+"); dimensionnerFlash();", 400);			
		});					
	}
}

function apparitionContenu() 
{	
	transitionEnCours = false;
	positionnerElements(); 
	go_page();	
}

function dimensionnerFlash()
{
	l = $(window).width(); h = $(window).height();	
	$(getFlashObject('heral')).css("height", h+"px").css("width", l+"px");
}

function creerObjetFlash()
{
	AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', '100%',
		'height', '400px',
		'src', 'heral.swf',
		'quality', 'high',
		'pluginspage', 'http://www.adobe.com/go/getflashplayer_fr',
		'align', 'middle',
		'play', 'true',
		'loop', 'false',
		'scale', 'noscale',
		'wmode', 'transparent',
		'devicefont', 'false',
		'id', 'heral',
		'bgcolor', '#ffffff',
		'name', 'heral',
		'menu', 'false',
		'allowFullScreen', 'true',
		'allowScriptAccess','sameDomain',
		'movie', 'heral',
		'salign', 'lt'
	);
}


