// JavaScript Document
function preloading(){
	if (document.images) 
	{		
		for(var b=1; b<=nombre_photos; b++){
			this["img"+b] = new Image();
			this["img"+b].src = url_photos + "bg" + b + ".jpg";
		}		
	}
}
// Variable à changer pour le nombre de photos de background
var nombre_photos = 6;
// Variable à changer pour le nombre de secondes entre les changements de background
var nombre_secondes = 4000;

var temps_normal = nombre_secondes;
var temps_thumb = 9000;
var premiere_photo = 0;
// Ajouter le nombre de photos dans le tableau
var tPhotos = [1,2,3,4,5,6];
var compteur_photos = 1;
var photo_cliquer = "laphoto1";
var numero_cliquer = photo_cliquer.substring((photo_cliquer.length-1));
var background_prensent = "bg1";
var timerback = 0;
var pret_fermer = true;
var boite_fermer = true;
// Fade la background arriere pour commencer
fadeout_background(2);

//CGI-NOTE : TEMPORAIREMENT, utiliser les paths d'images indiqué ci-dessous, mais une amélioration du 
//code pour être faite pour utiliser seulement le image-gallery sous la home page
var url_photos = "/~/media/jobs/Recruitment/images/bg/";
var url_thumbnails = "/~/media/jobs/Recruitment/images/bg/thumbs/";

preloading();
// Preload les images




// Jquery feed

function toyposi()
{ 									
	 var position;
 	 position = jQuery("#menu").offset();
	 var objtoy = document.getElementById("toy");
	 var objtoyopaque = document.getElementById("toyopaque");
	 var objmenu = document.getElementById("menu");	
	 // position = document.menu.offsetLeft;
	 //objtoy.style.left=position.left+624;
	 jQuery("#toy").css({left:position.left+624 });
	 jQuery("#toyopaque").css({left:position.left+624 });
 }



function fadeout_background(background_actif)
{
	jQuery("#bg"+background_actif).fadeTo( 500 , 0 );
}
function fadein_background(image,background_inactif)
{
	document.getElementById("bg"+background_inactif).innerHTML =" <img src=" + url_photos + "bg" + image + ".jpg />";
	jQuery("#bg"+background_inactif).fadeTo( 500 , 1 );

}
/*
  $(document).ready(function(){
toyposi();
// Fade background rollover menu --  enlever

	$("#sup").hover(
			function () 
				{	 	   
				 $("#bg1").fadeTo( 100 , 0.6 ); 
			    }
				,
				function () 
				{	 $("#bg1").fadeTo( 100 ,1 ); 

			    }
	 );


  });
  */

// Cette fonction augmente le temps entre le changement de photo quand l'usager click sur un thumbnail
function thumb(thumb,laphoto){
	nombre_secondes = temps_thumb;
	changerbackground(thumb,laphoto);
}

// Change le brackground par le numero passé en paramêtre
function changerbackground(objet,numero_photo){
	
	var background_actif = 1;
	var background_inactif = 2;
	if(background_prensent == "bg1"){
		background_actif = 1;
		background_inactif = 2;
	}else{
		background_actif = 2;
		background_inactif = 1;
	}
	numero_cliquer = photo_cliquer.substring((photo_cliquer.length-1));
	fadeout_background(background_actif);
	if(numero_cliquer<=4){
		document.getElementById(photo_cliquer).src= url_thumbnails + "tbg" + compteur_photos + ".gif";
	}
	document.getElementById(objet.id).src= url_thumbnails + "tbg" + numero_photo + "over.gif";
	fadein_background(numero_photo,background_inactif);
	compteur_photos = numero_photo;
	photo_cliquer = objet.id;
	
	clearTimeout();
	if(background_prensent == "bg1"){
		background_prensent = "bg2";
	}else{
		background_prensent = "bg1";
	}
	clearTimeout(timerback);
	timerback = setTimeout("bg_auto_change()", nombre_secondes);
	nombre_secondes = temps_normal;
}

// Change les images de position dans la zone selon la flèche appoyée
function derniereimage(position,la_direction){
	if(la_direction == "precedante"){
		if(tPhotos[position] == 1){
			tPhotos[position] = nombre_photos;
		}else{
			tPhotos[position]= tPhotos[position] -1;
		}
	}else{
		if(tPhotos[position] == nombre_photos){
			tPhotos[position] = 1;
		}else{
			tPhotos[position] = tPhotos[position]+1;
		}
	}
}

function imageprecedante(){
	premiere_photo = 0;
	derniereimage(premiere_photo,"precedante");
	var photos_toy = "<a><img src='" + url_thumbnails + "tbg" + tPhotos[premiere_photo] + ".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto1' /></a> ";
	premiere_photo++;
	derniereimage(premiere_photo,"precedante");
	photos_toy += "<a><img src='" + url_thumbnails + "tbg" + tPhotos[premiere_photo] + ".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto2' /></a> ";
	premiere_photo++;
	derniereimage(premiere_photo,"precedante");
	photos_toy += "<a><img src='" + url_thumbnails + "tbg" + tPhotos[premiere_photo]+".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto3' /></a> ";
	premiere_photo++;
	derniereimage(premiere_photo,"precedante");
	photos_toy += "<a><img src='" + url_thumbnails + "tbg" + tPhotos[premiere_photo]+".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto4' /></a> ";
	premiere_photo++;
	document.getElementById('photosbackground').innerHTML = photos_toy;
	numero_cliquer = photo_cliquer.substring((photo_cliquer.length-1));
	if(numero_cliquer == nombre_photos){
		numero_cliquer = 1;
		photo_cliquer = "laphoto"+(numero_cliquer);
	}else{
		numero_cliquer++;
		photo_cliquer = "laphoto"+(numero_cliquer);
	}
	if(numero_cliquer <=4){
		document.getElementById(photo_cliquer).src= url_thumbnails + "tbg" + compteur_photos + "over.gif";
	}
}

function imagesuivante(){
	premiere_photo = 0;
	derniereimage(premiere_photo,"suivante");
	var photos_toy = "<a><img src='" + url_thumbnails + "tbg"+tPhotos[premiere_photo]+".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto1' /></a> ";
	premiere_photo++;
	derniereimage(premiere_photo,"suivante");
	photos_toy += "<a><img src='" + url_thumbnails + "tbg"+tPhotos[premiere_photo]+".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto2' /></a> ";
	premiere_photo++;
	derniereimage(premiere_photo,"suivante");
	photos_toy += "<a><img src='" + url_thumbnails + "tbg"+tPhotos[premiere_photo]+".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto3' /></a> ";
	premiere_photo++;
	derniereimage(premiere_photo,"suivante");
	photos_toy += "<a><img src='" + url_thumbnails + "tbg"+tPhotos[premiere_photo]+".gif' width='41' height='29' border='0' onmouseover='imagerollover(this,"+tPhotos[premiere_photo]+");' onmouseout='imagerollout(this,"+tPhotos[premiere_photo]+");' onclick='changerbackground(this,"+tPhotos[premiere_photo]+");' id='laphoto4' /></a> ";
	premiere_photo++;
	document.getElementById('photosbackground').innerHTML = photos_toy;
	numero_cliquer = photo_cliquer.substring((photo_cliquer.length-1));
	if(numero_cliquer == 1){
		numero_cliquer = nombre_photos;
		photo_cliquer = "laphoto"+(numero_cliquer);
	}else{
		numero_cliquer--;
		photo_cliquer = "laphoto"+(numero_cliquer);
	}
	if(numero_cliquer >=0 && numero_cliquer <=4){
		document.getElementById(photo_cliquer).src= url_thumbnails + "tbg" + compteur_photos+"over.gif";
	}
}

timerback = setTimeout("bg_auto_change()", nombre_secondes);
function bg_auto_change(){
	var background_actif = 1;
	var background_inactif = 2;
	// Roll out la derniere photo
	if(photo_cliquer != "" && numero_cliquer <=4){
		document.getElementById(photo_cliquer).src= url_thumbnails + "tbg" + compteur_photos+".gif";
	}
	// Change pour une nouvelle photo thumbnail
	if(compteur_photos == nombre_photos){
		compteur_photos = 1;
	}else{
		compteur_photos++;
	}
	numero_cliquer = photo_cliquer.substring((photo_cliquer.length-1));
	// incrémente les photos thumbnails a changer
	numero_cliquer++;
	photo_cliquer = "laphoto"+(numero_cliquer);
	// RollOver les nouvelles photos thumbnail
	if(numero_cliquer <= 4){
		document.getElementById(photo_cliquer).src= url_thumbnails + "tbg"+compteur_photos+"over.gif";
	}else{
		if(numero_cliquer > nombre_photos){
			numero_cliquer = 1;
			photo_cliquer = "laphoto1"
			document.getElementById(photo_cliquer).src= url_thumbnails + "tbg"+compteur_photos+"over.gif";
		}
	}
	// Switch les backgrounds
	if(background_prensent == "bg1"){
		background_actif = 1;
		background_inactif = 2;
	}else{
		background_actif = 2;
		background_inactif = 1;
	}
	fadeout_background(background_actif);
	fadein_background(compteur_photos,background_inactif);
	timerback = setTimeout("bg_auto_change()", nombre_secondes);
	if(background_prensent == "bg1"){
		background_prensent = "bg2";
	}else{
		background_prensent = "bg1";
	}
}

// RollOver d'images
function imagerollover(objet,numero_photo){
	document.getElementById(objet.id).src= url_thumbnails + "tbg"+numero_photo+"over.gif";
}
function imagerollout(objet,numero_photo){
	if(objet.id != photo_cliquer){
		document.getElementById(objet.id).src= url_thumbnails + "tbg"+numero_photo+".gif";
	}
}

/*
function drop_black(){
	//if(){

	jQuery("#inside_black").slideToggle("100");	
	
	//}
}

*/







