/////////////////////////////////////////////////////
/////// DEFINITION DES OBJETS ///////////////////////
/////////////////////////////////////////////////////

///CATEGORIE

function categorie(nom, liste_projets) 
{	
	this.nom = nom;
	this.repertoire = nom.replace(/\W/g,'_');
	this.liste_projets = new Array(); 
	this.add_projet = add_projet;
}

function add_projet(new_projet) 
{
	this.liste_projets[this.liste_projets.length] = new_projet;
}

///PROJET

function projet(nom, galerie, videos) 
{	
	this.nom = nom;
	this.repertoire = nom.replace(/\W/g,'_');
	this.rubriques = new Array(1,galerie,videos); //galerie = nb_images , videos = BOOL
}

//ELEMENT D'UNE LISTE 
function element(indice, nom, adresse)
{
	this.indice = indice;
	this.nom = nom; // le nom avec des espaces
	this.adresse = adresse; //le nom du fichier correspondant au nom = le nom sans espaces
} 

/////////////////////////////////////////////////////
///////NAVIGATION////////////////////////////////////
/////////////////////////////////////////////////////

///FONCTIONS NAVIGATION

//retrouve l'indice de la catégorie, l'indice du projet et l'indice de la rubrqiue 
//en fonction de l'url de la page courante
function get_infos_from_url()
{ 
	var arborescence = String(window.document.location).split('/');
	
	categorie_courante.adresse = arborescence[arborescence.length-3];
	categorie_courante.nom = categorie_courante.adresse.replace(/_/g,' ');
	
	projet_courant.adresse = arborescence[arborescence.length-2];
	projet_courant.nom = projet_courant.adresse.replace(/_/g,' '); ;
	
	rubrique_courante.adresse = (arborescence[arborescence.length-1].split('.'))[0];
		
	for(i=0 ; i<liste_categories.length ; i++)
	{ 
		if(liste_categories[i].repertoire == categorie_courante.adresse)
		{ 
		  	for(j=0 ; j<liste_categories[i].liste_projets.length ; j++)
			{
				if(liste_categories[i].liste_projets[j].repertoire == projet_courant.adresse)
				{
					 categorie_courante.indice =i;
					 projet_courant.indice =j;
					 for(k=0 ; k<LISTE_RUBRIQUES.length ; k++) 
					 { 
					 	if(LISTE_RUBRIQUES[k] == rubrique_courante.adresse) 
						{ rubrique_courante.indice = k;}
					 }					 
					 return;
				}
			}
		}
	}  
}

function goto_projet(base_url,i,j,k)
{
	//base_url = chemin relative au répertoire appelé
	//i = indice de la catégorie et j= l'indice du projet
	//k = indice de la sous-rubrique du projet (ex:0=index,1=galerie,2=videos...)
	var categorie_repertoire = liste_categories[i].repertoire;
	var projet_repertoire = liste_categories[i].liste_projets[j].repertoire;
	var rubrique_page= LISTE_RUBRIQUES[k];
	window.open(base_url+categorie_repertoire+"/"+projet_repertoire+"/"+rubrique_page+".html","_self");
}

function goto_categorie(i)
{
	goto_projet(REFERENCES_RELATIVE_URL,i,0,0);
}

function index_goto_categorie(i)
{
	goto_projet('',i,0,0);
}

function goto_rubrique(k)
{
	goto_projet(REFERENCES_RELATIVE_URL,categorie_courante.indice,projet_courant.indice,k);
}

function goto_next_projet()
{
	/*var url_variables = get_url_variables();
	var i = url_variables.categorie; //i = indice de la categorie courante
	var j = url_variables.projet; //j = indice du projet courante*/
	var i = categorie_courante.indice;
	var j = projet_courant.indice;
	if(++j==liste_categories[i].liste_projets.length)
	{ 
		i = next_categorie(i);
		j = 0;
	}
	goto_projet(REFERENCES_RELATIVE_URL,i,j,0);
}

function goto_previous_projet()
{
	/*var url_variables = get_url_variables();
	var i = url_variables.categorie; //i = indice de la categorie courante
	var j = url_variables.projet; //j = indice du projet courante*/
	var i = categorie_courante.indice;
	var j = projet_courant.indice;
	if(--j==-1)
	{ 
		i= previous_categorie(i);
		j = liste_categories[i].liste_projets.length-1;
	}
	goto_projet(REFERENCES_RELATIVE_URL,i,j,0);
}

function next_categorie(i) //i = indice de la catégorie courante
{
	if(++i==liste_categories.length) i = 0;
	return i;
}

function previous_categorie(i) //i = indice de la catégorie courante
{
	if(--i==-1) i = liste_categories.length-1;
	return i;
}

//////////////////////////////////////////////////
/////SOUS MENUS///////////////////////////////////
//////////////////////////////////////////////////

// fonction qui verifie l'existence d'un drop-down menu avant de l'afficher

function afficher_menu(i,image)
{
	if(eval("window.document.mm_menu_"+i))
	{
		MM_showMenu(eval("window.document.mm_menu_"+i),5,26,null,image);  //menu, x, y, child, imgname
	}
}

//genération des sous menus de la page references
function mmLoadMenus() 
{
	if (window.menus) return;
	var label_menu = new String("");
	for(i=0; i<liste_categories.length ;i++)
	{	
		if(liste_categories[i].liste_projets.length>1)
		{
			var categorie_repertoire = liste_categories[i].repertoire;
			label_menu = "window.document.mm_menu_"+i;
			eval(label_menu+" = new Menu('root',130,22,'Verdana, Arial, Helvetica, sans-serif',11,'#FFFFFF','#C8DEFF','#041E62','#1F41AA','left','middle',4,1,1000,-5,7,true,false,true,5,true,false);");
			for(j=0 ; j<liste_categories[i].liste_projets.length; j++)
			{
				var projet_repertoire = liste_categories[i].liste_projets[j].repertoire;
				var projet_nom  = liste_categories[i].liste_projets[j].nom;
				var projet_url = REFERENCES_RELATIVE_URL+categorie_repertoire+"/"+projet_repertoire+"/index.html?";
				eval(label_menu+".addMenuItem('"+projet_nom+"',\"location='"+projet_url+"'\");"); // second argument :"window.open('url', '_blank');" ou "location='url'"				
			}		
			eval(label_menu+".hideOnMouseOut=true;");
			eval(label_menu+".bgColor='#FFFFFF';");
			eval(label_menu+".menuBorder=0;");
			eval(label_menu+".menuLiteBgColor='#FFFFFF';");
			eval(label_menu+".menuBorderBgColor='#000000';");
			label_menu = "window.document.mm_menu_"+i;
		}
	}
	eval(label_menu+".writeMenus();");
}

//////////////////////////////////////////////////
/////MENUS////////////////////////////////////////
//////////////////////////////////////////////////

//OBJETS//

function barre_menu(nom,nb_btn,nom_btn,format_img,url_img)
{
	this.nom = nom;
	this.nb_btn = nb_btn;
	this.nom_btn = nom_btn;
	this.format_img = format_img;
	this.url_img = url_img;
	this.liste_btn = new Array();
	for(i=0; i<this.nb_btn ; i++)
	{ 
		this.liste_btn[i] = new btn_barre_menu();		
		this.liste_btn[i].nom = this.nom+"_"+this.nom_btn+"_"+i; //ex : 'barre_menu_1'+'_'+'btn'+'_'+'1' = barre_menu_1_btn_1
		this.liste_btn[i].nom_img = this.nom_btn+"_"+i+"."+this.format_img;
		this.liste_btn[i].url_off = this.url_img+"off/"+this.liste_btn[i].nom_img; 
		this.liste_btn[i].url_over = this.url_img+"over/"+this.liste_btn[i].nom_img; 
	}	
}

function btn_barre_menu()
{
	this.nom ='';
	this.nom_img ='';
	this.url_off = '';
	this.url_over = '';	
}

// fonction charger barre de menu principale
function creer_barre_menu(new_barre_menu)
{
	for(i=0 ; i<new_barre_menu.nb_btn ; i++)
	{ 
		var btn = new_barre_menu.liste_btn[i];
		document.write("<a href=\"javascript:goto_categorie("+i+");\" target='_self' ");
		document.write(" onClick=\"MM_nbGroup('down','"+new_barre_menu.nom+"','"+btn.nom+"','"+btn.url_over+"',1)\""); 
		document.write(" onMouseOver=\"MM_nbGroup('over','"+btn.nom+"','"+btn.url_over+"','',1);afficher_menu("+i+",'"+btn.nom+"');\"");
		document.write(" onMouseOut=\"MM_nbGroup('out');MM_startTimeout();\"");
		document.write(" onLoad=\"MM_preloadImages('+btn.url_over+')\">");
		document.write("<img name='"+btn.nom+"' src='"+btn.url_off+"' border='0' align='top' alt='"+liste_categories[i].nom+"'>");
		document.write("</a>");
	}
}



