$(document).ready(function() {
	// Masque la div de sélection des langues
	$("#selectLang").css("display","none");
	$("#showreel").css("display","inline");
	
	// Ajout du roll sur le skip>
	$("#showreel div.skip").mouseenter(function() {
		$(this).addClass("hover");
		add_over($("#showreel div.skip img"));
	});
	$("#showreel div.skip").mouseleave(function() {
		$(this).removeClass("hover");
		remove_over($("#showreel div.skip img"));
	});
	// Preload du over
	preloadImg($("#showreel div.skip img").attr("src").split(".").join("_over."));
	
	// Mettre les images dans le selectLang
	$("#selectLang ul li a").each(function() {
		var title = $(this).attr("title");
		$(this).html("<div id=\""+title+"_text3d\" class=\"contenerImg3d\">"+insertPng(title,"_r")+insertPng(title,"_b")+insertPng(title,"_w")+"</div>");
	});
	function insertPng(title,color) {
		return "<div class=\"img3d img3d"+color+"\"><img src=\"img/index/"+title+color+".png\"/></div>";
	}
	
	var positionLeft = [10,10];
	var positionTop = [0,0];
	var ii;
	
	// Décalage en y
	ii = 0;
	$("#selectLang .contenerImg3d").each(function() {
		$(this).css("top",positionTop[ii]);
		ii++;
	});
	
	// Décalage des couleurs
	// blanc
	ii = 0;
	$("#selectLang ul li div.img3d_w").each(function() {
		$(this).css("top","-1px");
		$(this).css("left",positionLeft[ii]);
		ii++;
	});
	// rouge
	ii = 0;
	$("#selectLang ul li div.img3d_r").each(function() {
		$(this).css("top","-1px");
		$(this).css("left",(positionLeft[ii]+2));
		ii++;
	});
	// bleu
	ii = 0;
	$("#selectLang ul li div.img3d_b").each(function() {
		$(this).css("top", "1px");
		$(this).css("left", (positionLeft[ii]-2));
		ii++;
	});
	
	// Programmation du survol
	$("#selectLang .contenerImg3d").mouseenter(function() {
		ii = $("#selectLang .contenerImg3d").index($(this));
		$(this).children(".img3d").each(function() {
			if($(this).hasClass("img3d_r")) $(this).animate({left: (positionLeft[ii]+4),top: '-2px'}, 100);
			if($(this).hasClass("img3d_b")) $(this).animate({left: (positionLeft[ii]-4),top: '2px'}, 100);
		});
	});
	$("#selectLang .contenerImg3d").mouseleave(function() {
		ii = $("#selectLang .contenerImg3d").index($(this));
		$(this).children(".img3d").each(function() {
			if($(this).hasClass("img3d_r")) $(this).animate({left: (positionLeft[ii]+2),top: '-1px'}, 100);
			if($(this).hasClass("img3d_b")) $(this).animate({left: (positionLeft[ii]-2),top: '1px'}, 100);
		});
	});
	$("#selectLang .contenerImg3d").click(function() {
		$("#selectLang").fadeOut(500);
	});
	
	// Action Skip
	$("#showreel .skip").click(function() {
		closeShowreel();
	});
	
	// Insertion de la vidéo du showreel (flash vimeo)
	insertFlashVimeo("showreel_video","26313911",720,405,1);
	
	if(isIphone||isIpad) closeShowreel();
});

// Interactions avec le player vimeo
var vimeo_flash = false;
function vimeo_player_loaded() {
	$("#showreel img.loader").remove();
	vimeo_flash = document.getElementById("vimeo_flash");
	vimeo_flash.api_addEventListener("onFinish", "vimeo_on_finish");
}
function vimeo_on_finish() {
	closeShowreel();
}
function closeShowreel() {
	if(vimeo_flash) vimeo_flash.api_pause();
	$("#showreel").fadeOut(200, function() {
		$("#showreel").remove();
		$("#selectLang").fadeIn(500);
	});
}
