/////////////////////////////////////////////////////
///////CONSTANTES ///////////////////////////////////
/////////////////////////////////////////////////////

var RELATIVE_URL="../../";
var IMAGES_HABILLAGE_RELATIVE_URL = RELATIVE_URL+"_images/habillage/";
var IMAGES_MAIN_MENU_RELATIVE_URL = IMAGES_HABILLAGE_RELATIVE_URL+"main_menu/";
var IMAGES_TITRE_RELATIVE_URL = IMAGES_HABILLAGE_RELATIVE_URL+"titres/";

var IMAGES_MENU_RUBRIQUES_RELATIVE_URL = "../_images/rubriques/";
var IMAGES_MENU_RUBRIQUES_OFF_RELATIVE_URL = IMAGES_MENU_RUBRIQUES_RELATIVE_URL+"off/";
var IMAGES_MENU_RUBRIQUES_OVER_RELATIVE_URL = IMAGES_MENU_RUBRIQUES_RELATIVE_URL+"over/";
var IMAGES_MENU_RUBRIQUES_ON_RELATIVE_URL = IMAGES_MENU_RUBRIQUES_RELATIVE_URL+"on/";  

//GALERIE
var GALERIE_THUMBNAILS_RELATIVE_URL = "_images/galerie/thumbnails/";
var GALERIE_HABILLAGE_RELATIVE_URL = IMAGES_HABILLAGE_RELATIVE_URL+"galerie/";
var GALERIE_THUMBNAIL_NEUTRE = GALERIE_HABILLAGE_RELATIVE_URL+"_00.gif";
var GALERIE_BTN_SUITE = GALERIE_HABILLAGE_RELATIVE_URL+"btn_suite.gif";
var GALERIE_BTN_RETOUR = GALERIE_HABILLAGE_RELATIVE_URL+"btn_retour.gif";
var GALERIE_MAX_THUMBNAILS = 8; // nb de thumbnails affichés sur la page galerie
var GALERIE_THUMBNAIL_DEFAULT_NAME= "thumbnail_";

var nb_thumbnails = 0;
var indice_galerie_courante = 0; //indice de la galerie courante au cas où il y est plus de 8 images pour un projet

//VIDEOS
var VIDEOS_RELATIVE_URL = "../../../videos/selection_video.html";

var categorie_courante = new element(0,"");
var rubrique_courante = new element(0,"","");

/////////////////////////////////////////////////////
///////DEFINITIONS //////////////////////////////////
/////////////////////////////////////////////////////

///DEFINITION DE L'ARBORESCENCE DES CATEGORIES
var cat_0 = new categorie("sommaire");
cat_0.add_rubrique(new rubrique("presentation"));

var cat_1 = new categorie("recherche developpement");
cat_1.add_rubrique(new rubrique("presentation"));
cat_1.add_rubrique(new rubrique("effets speciaux"));
cat_1.add_rubrique(new rubrique("personnages virtuels"));

var cat_2 = new categorie("motion capture");
cat_2.add_rubrique(new rubrique("mocap"));
cat_2.add_rubrique(new rubrique("presentation"));
cat_2.add_rubrique(new rubrique("atouts"));
//cat_2.add_rubrique(new rubrique("studio"));
//cat_2.add_rubrique(new rubrique("cameras"));
cat_2.add_rubrique(new rubrique("controle artistique"));
cat_2.add_rubrique(new rubrique("temps reel"));
cat_2.add_rubrique(new rubrique("animation faciale"));
cat_2.add_rubrique(new rubrique("galerie",9));
cat_2.add_rubrique(new rubrique("contact"));

var cat_3 = new categorie("scanning 3d");
cat_3.add_rubrique(new rubrique("savoir faire"));
//cat_2.add_rubrique(new rubrique("exemples"));

var liste_categories = new Array(cat_0,cat_1,cat_2,cat_3);

/////////////////////////////////////////////////////
///////FONCTIONS & APPEL DE FONCTIONS ///////////////
/////////////////////////////////////////////////////

// recuperation des infos sur la categorie et de la rubrique de la page courante
get_infos_from_url(); 

//generation automatique de la balise titre de la page
/*function write_title()
{	
	document.write("<TITLE>SYNTHETIQUE [ Technologies | "+categorie_courante.nom+" | "+rubrique_courante.nom+" ]</TITLE>");

//affichage du titre de la categorie
}*/

function afficher_img_titre_categorie()
{
	var url_img_titre= IMAGES_TITRE_RELATIVE_URL+categorie_courante.adresse+".gif";
	document.write("<a href='javascript:goto_rubrique_from_menu(0);'><img src='"+url_img_titre+"' border='0' alt='"+categorie_courante.nom+"' ></a>");
}

//affichage du titre de la categorie
function afficher_img_titre_rubrique()
{
	var url_img_titre= "_images/titre_rubrique.gif";
	document.write("<img src='"+url_img_titre+"'>");
}

//generation automatique du menu_principal
function init_barre_menu()
{	
  	var new_barre_menu = new barre_menu ('barre_menu_1',liste_categories.length,'btn','gif',IMAGES_MAIN_MENU_RELATIVE_URL);
    creer_barre_menu(new_barre_menu);
	var btn_courant = new_barre_menu.liste_btn[categorie_courante.indice];
	eval("window.document."+btn_courant.nom+".src='"+btn_courant.url_over+"';");	
}

//generation automatique du menu rubriques : descriptif, galerie, videos
function afficher_menu_rubriques()
{
	var menu_rubriques = liste_categories[categorie_courante.indice].liste_rubriques ;
	for(i=0; i<menu_rubriques.length; i++)
	{
		var img_nom = menu_rubriques[i].repertoire;
		var rubrique_nom = menu_rubriques[i].nom;
		var rubrique_off = IMAGES_MENU_RUBRIQUES_OFF_RELATIVE_URL+img_nom+".gif";
		var rubrique_over = IMAGES_MENU_RUBRIQUES_OVER_RELATIVE_URL+img_nom+".gif";
		var rubrique_on = IMAGES_MENU_RUBRIQUES_ON_RELATIVE_URL+img_nom+".gif";
		
		document.write("<br>");
		
		if(rubrique_courante.indice==i)
		{
			//ON
			document.write("<img src='"+rubrique_on+"' border=0 name='"+img_nom+"' id='"+img_nom+"' alt='"+rubrique_nom+"' >");
		}		
		else
		{
		  	//OFF
			document.write("<a href='javascript:goto_rubrique_from_menu("+i+");' onMouseOver=\"MM_swapImage('"+img_nom+"','','"+rubrique_over+"',1)\" onMouseOut='MM_swapImgRestore()'");
			document.write(" onLoad=\"MM_preloadImages('"+rubrique_over+"')\">");			
		  	document.write("<img src='"+rubrique_off+"' border=0 name='"+img_nom+"' id="+img_nom+" alt='"+rubrique_nom+"'>");
			document.write("</a>");
		}
	}
}

/////////////////////////////////////////////////////
///////FONCTIONS de la GALERIE //////////////////////
/////////////////////////////////////////////////////

//fonction open popup_galerie
function open_popup_galerie(img_courante, nb_img)
{
	var popup_url = "popup_galerie.html?img_courante="+img_courante+"&nb_img="+nb_img;
	MM_openBrWindow(popup_url,'','width=650,height=525');
}

//afficher un thumbnail
function write_thumbnail(thumbnail_src)
{
	var nom_thumbnail = GALERIE_THUMBNAIL_DEFAULT_NAME+i;
	document.write("<img src='"+thumbnail_src+"' border=0 width='99' height='70'>");
}

// fonction afficher le tableau de thumbnails
function afficher_thumbnails()
{
    nb_thumbnails = liste_categories[categorie_courante.indice].liste_rubriques[rubrique_courante.indice].galerie;	
	var variables_url = get_url_variables();
	
	if(variables_url.indice_galerie)
	{ indice_galerie_courante = Number(variables_url.indice_galerie);}
	
	var increment = indice_galerie_courante*(GALERIE_MAX_THUMBNAILS-2);
	
	for(i = 1 ; i <= GALERIE_MAX_THUMBNAILS ;i++)
	{
		var ii = i+increment;
	
		if(i%4==1)
		{document.write("<tr align='center' valign='middle'>");}
		
		document.write("<td nowrap>");
		
		if(ii>nb_thumbnails)
		{
			write_thumbnail(GALERIE_THUMBNAIL_NEUTRE);
		}
		else
		{
			if(i==GALERIE_MAX_THUMBNAILS && ii < nb_thumbnails)
			{
				document.write("<a href='javascript:goto_galerie_suivante();'>")
				write_thumbnail(GALERIE_BTN_SUITE);
				document.write("</a>");
			}
			else if(i==1 && indice_galerie_courante >0)
			{
				document.write("<a href='javascript:goto_galerie_precedente();'>")
				write_thumbnail(GALERIE_BTN_RETOUR);
				document.write("</a>");
			}
			else
			{
				document.write("<a href='javascript:open_popup_galerie("+ii+", "+nb_thumbnails+");'>")
				var src_thumbnail;
				if((ii) > 9)
				{ src_thumbnail = GALERIE_THUMBNAILS_RELATIVE_URL+'_'+ii+'.jpg'; }
				else 
				{ src_thumbnail = GALERIE_THUMBNAILS_RELATIVE_URL+'_0'+ii+'.jpg'; }
				write_thumbnail(src_thumbnail);
				document.write("</a>");
			}
		}

		document.write("</td>");
		
		if(i%4==0)
		{document.write("</tr>");}
	}
}

function goto_galerie_suivante()
{
	var galerie_url = new String(window.location); //récupération de l'adresse de la page actuelle
	var end_index = galerie_url.indexOf('?'); // tronquer la partie de l'adresse comprenant des variables (après le '?')
	if(end_index>0) {galerie_url = galerie_url.substring(0,end_index);}
	window.document.location = galerie_url+"?indice_galerie="+(indice_galerie_courante+1);
}

function goto_galerie_precedente()
{
	var galerie_url = new String(window.location); //récupération de l'adresse de la page actuelle
	var end_index = galerie_url.indexOf('?'); // tronquer la partie de l'adresse comprenant des variables (après le '?')
	if(end_index>0) {galerie_url = galerie_url.substring(0,end_index);}
	window.document.location = galerie_url+"?indice_galerie="+(indice_galerie_courante-1);
}

/////////////////////////////////////////////////////
///////FONCTIONS VIDEOS /////////////////////////////
/////////////////////////////////////////////////////

//fonction open popup_video
//fonction open popup_video
function open_popup_video(nom_video)
{
	var popup_url = VIDEOS_RELATIVE_URL+"?nom_video="+nom_video;
	MM_openBrWindow(popup_url,'','width=600,height=540');
}
