// -------------------------------------------
//  TOOLTIP
// -------------------------------------------
function toolTip(elmt){
	$(elmt).tooltip({
		track: true, 
		delay: 0, 
		showURL: false
	});
}
// -------------------------------------------
//  REDIRECTION
// -------------------------------------------
var currentURL = document.location.href;
var urlFr =  "http://"+window.location.host+"/fr/";
var urlEn =  "http://"+window.location.host+"/en/";
var urlIt =  "http://"+window.location.host+"/it/";

function redirectionLangue () 
{ 
		var language = "fr"; 
       
        if (navigator.browserLanguage) {
                language = navigator.browserLanguage; 
        }else{
               var language = navigator.language; 
        }
		
		if (language.indexOf('fr') > -1 && currentURL != urlFr && currentURL != urlFr+"index.html"){
                document.location.href = urlFr;
   		}else if (language.indexOf('en') > -1 && currentURL != urlEn && currentURL != urlEn+"index.html") {
                document.location.href = urlEn;
 	    }else if (language.indexOf('it') > -1 && currentURL != urlIt && currentURL != urlIt+"index.html") {
                document.location.href = urlIt;
       	}
} 
// -------------------------------------------
//  HISTORY
// -------------------------------------------
// au demarrage aucune scene n'est chargée
// on regarde si nécessaire d'unloader une scene avant d'en charger une autre.

var firstScene=true;

function sceneCalled(hash,firstScene){
	alert("sceneCalled // "+hash+" "+firstScene);
}

// ___________________________________________________________________ apres le chargement du flash...
function flashReady(flashLoaded){
	// on attend que le flash soit chargé
	if(flashLoaded){
		//alert("ready");
		$.historyInit(initPage);
	}
}
// ___________________________________________________________________ init History

var calledFromFlash = false;

function initPage(hash) {
	//alert("initPage // "+hash);
	// si l'appel ne vient pas de flash, on fait suivre le lien, sinon non car double l'appel de flash...
	if(!calledFromFlash){
		if(hash) {
			
			if(firstScene){
				setTimeout("document.getElementById('arthur').passIntro();",200);
			}
			// goto la scene hash
			gotoScene(hash);
		}else {
			//si pas de hash  goto home
			//gotoScene("home");
			//alert("home");
			firstScene=false;
		}
	}
   return false; 
}
// ___________________________________________________________________ affiche et enregistre le hash
function loadHash(hash){
		//alert("loadHash // "+hash);
		hash = hash.replace(/.swf/,'');
		//h = hash.replace(/^.*/, '');
		//location.href="#"+hash;
		calledFromFlash =true;
		$.historyLoad(hash);
		calledFromFlash =false;
}
// ___________________________________________________________________ Load Scene dans flash
function gotoScene(hash){
	//alert("gotoScene // "+hash+" "+firstScene);
	setTimeout("document.getElementById('arthur').goScene('"+hash+"',"+firstScene+")",300);
	firstScene=false;
	//alert(document.getElementById("arthur"));
}




// -------------------------------------------
//  LIGHTBOX
// -------------------------------------------
var lightBoxOpen = false;
var lbHeight=$('#lb_content').height();
// ------------------------------------------- init lightbox
function savoirPlus(){
	$('#savoirplus a').click(function(){
		var hash = $(this).attr('class');
		//loadHash(hash);
		initPage(hash);
		closeB();
		return false;
	});
}
function lightBox(object,type){

		//alert(type);
		$('#savoirplus a').slideUp("normal");
	
		if(type=="video"){
			$('#menuGames').hide();
			$('#menuImages').hide();
			$('#menuVideo').show("normal");
		}else if(type=="games"){
			$('#menuVideo').hide();
			$('#menuImages').hide();
			$('#menuGames').show("normal");
		}else if(type=="images"){
			$('#menuVideo').hide();
			$('#menuGames').hide();
			$('#menuImages').hide();
			//$('#menuImages').show("normal");
		}
		
		var page = $('#'+object).attr('href');
		var titre = $('#'+object).attr('alt');
		var partie = $('#'+object+" img").attr('class');
				
		if(!lightBoxOpen)
		{
			$('#lightbox').fadeIn("normal", function(){
				setObject(object,page,titre,partie,type);
			});
			
			lightBoxOpen=true;
			
		}else{
			setObject(object,page,titre,partie,type);
		}
}
// ------------------------------------------- load la page contenant l'object à afficher ds lightbox
function setObject(object,page,titre,partie,type){
	
	$('#lightbox h2').html(titre);
	$('#lb_content').load(page,function(){
	
		
	
		if(type == "games" ||  type == "video")
		{
			objectHeight_emb= $('#lb_content embed').height();
			objectHeight_obj= $('#lb_content object').height();
					
			if(objectHeight_emb!=null && objectHeight_emb!=0){
				objectHeight = objectHeight_emb;
			}else{
				objectHeight = objectHeight_obj;
			}
			
			objectWidth = $('#lb_content object').width();
		}
		else if(type == "images")
		{
			objectHeight  =$('#lb_content img').height();
			objectWidth  = $('#lb_content img').width();
		}
		
		$('#lb_content > *').hide();
		
		setTimeout("animate("+objectHeight+","+objectWidth+",'"+partie+"')",500);
		
	});
	
	 $('.menuLB a').removeClass("actif");
	 $('.menuLB a#'+object+'').addClass("actif");
}

function animate(objectHeight,objectWidth,partie)
{
	$('#lb_content').animate({height:lbHeight+objectHeight},600,function(){
		$('#lb_content > *').fadeIn("normal");
		$('#savoirplus a.'+partie).width(objectWidth).slideDown('normal');
		
	});
}

// ------------------------------------------- ferme lightbox et relance la scene
function closeBox(){
	$("a.close").click(function(){
		closeB();
		return false;
	});
}
function closeB(){
	$('#lightbox').hide();
	 $('#lightbox h2').empty();
	 $('#lb_content').empty();
	 $('#savoirplus a').hide();
	 $('.menuLB a').removeClass("actif");
	document.getElementById("arthur").loopScene();
	lightBoxOpen=false;
}

// ------------------------------------------- click sur les vignettes  lightbox
function menuLB(){
	$(".menuLB a").click(function(){
		var idVid=$(this).attr("id");
		var type=$(this).attr("class");
		lightBox(idVid,type);
		return false;
	});
}