function ajusteInterface(){
   var opt=null;
   if (top.document==document){
     if(opener) opener.document.getElementById("page").src = location;
	 return; //page plein ecran
	 }
   //recherche du liens dans la page principale
   var liens = top.document.getElementsByTagName("a");
   var i = liens.length-1;
   while( i >=0 && (liens[i].id.indexOf("option")==-1 || location.toString().indexOf(liens[i].href)==-1)) i--;
   if(i >=0) opt = liens[i];
   else{
     if(top.document.sousOptionActive) styleOption(top.document.sousOptionActive,":link"); //page d'acceuil sans bouton
     if(top.document.optionActive) styleOption(top.document.optionActive,":link"); //page d'acceuil sans bouton
     return; //page plein écran.
     }
   //si pas la peine de changer pour éviter un clignotement
   if((opt == top.document.sousOptionActive)||(opt == top.document.optionActive && top.document.sousOptionActive == null)) return;

   //option
   if(opt.id.indexOf("_")==-1) {
     styleOption(top.document.sousOptionActive,":link");
     top.document.sousOptionActive = null;
	 if (top.document.optionActive) 
	   top.document.getElementById(top.document.optionActive.id.replace("lienoption","sousmenu")).style.visibility="hidden";
	 styleOption(top.document.optionActive,":link");
	 top.document.optionActive = opt;
	 top.document.getElementById(opt.id.replace("lienoption","sousmenu")).style.visibility="visible";
	 styleOption(top.document.optionActive,":hover");
	 }
   //sous option
   else {
     styleOption(top.document.sousOptionActive,":link");
	 if (top.document.optionActive && top.document.optionActive!=top.document.getElementById(opt.id.substr(0,11))) 
	   top.document.getElementById(top.document.optionActive.id.replace("lienoption","sousmenu")).style.visibility="hidden";
     top.document.sousOptionActive = opt;
     styleOption(top.document.sousOptionActive,":hover");
	 styleOption(top.document.optionActive,":link");
	 top.document.optionActive = top.document.getElementById(opt.id.substr(0,11));
	 styleOption(top.document.optionActive,":hover");
	 top.document.getElementById(top.document.optionActive.id.replace("lienoption","sousmenu")).style.visibility="visible";
	 } 
	 afficheVignette();
}
function afficheVignette(){
   var ex = new RegExp("/[a-zA-Z0-9_]*\.[a-zA-Z0-9_]{3,4}$","g");
   top.document.getElementById("vignette").src = window.location.href.replace(ex,"/images/exemple.jpg");
}
function styleOption(option,style){
  if(option){
    if(style==":hover"){
       option.style.color = "#003300";
       option.style.fontWeight = "bold";
       option.style.marginLeft = "3px";
       option.style.marginRight = "0px";
	 }
	 else{
       option.style.color = "#006600";
       option.style.fontWeight = "normal";
       option.style.marginLeft = "0px";
       option.style.marginRight = "0px";

	   }
    }
}

function overOption(){
   var liensTopDoc = top.document.getElementsByTagName("a");
   var i = liensTopDoc.length - 1;
   while(i >=0 && (liensTopDoc[i].id.indexOf("option")==-1 || this.href.indexOf(liensTopDoc[i].href)==-1)) i--;
   styleOption(liensTopDoc[i],":hover");
   if (top.document.optionActive) cacheSousMenu(top.document.optionActive);
   afficheSousMenu(liensTopDoc[i]);
   afficheVign(liensTopDoc[i]);
}
function cacheSousMenu(option){
    id=(option.id.indexOf("_")!=-1)?option.id.substr(0,option.id.length-2):option.id; 
    top.document.getElementById(id.replace("lienoption","sousmenu")).style.visibility="hidden";
	}
function afficheSousMenu(option){
  id=(option.id.indexOf("_")!=-1)?option.id.substr(0,option.id.length-2):option.id; 
  top.document.getElementById(id.replace("lienoption","sousmenu")).style.visibility="visible";
  }
function afficheVign(option){
   var ex = new RegExp("/[a-zA-Z0-9_]*\.[a-zA-Z0-9_]{3,4}$","g");
   top.document.getElementById("vignette").src = option.href.replace(ex,"/images/exemple.jpg");
}

function outOption(){
   var liensTopDoc = top.document.getElementsByTagName("a");
   var j = liensTopDoc.length - 1;
   while(j >=0 && (liensTopDoc[j].id.indexOf("option")==-1 || this.href.indexOf(liensTopDoc[j].href)==-1)) j--;
   if(top.document.optionActive && top.document.optionActive == liensTopDoc[j]) return;
   restaureVignette();
   cacheSousMenu(liensTopDoc[j]);
   if (top.document.optionActive) afficheSousMenu(top.document.optionActive);
   styleOption(liensTopDoc[j],":link");
}
function restaureVignette(){
  var option = top.document.sousOptionActive ? top.document.sousOptionActive : top.document.optionActive ? top.document.optionActive : null;
  if(option!=null) afficheVign(option);
  else top.document.getElementById("vignette").src = "images/exemple.jpg";
}


function lienInterface(){
   if (top.document==document){return;}
   var liensTopDoc = top.document.getElementsByTagName("a");
   var liensDoc = document.getElementsByTagName("a");
   var i = 0;
   while( i < liensDoc.length ){
     var j = liensTopDoc.length - 1;
     while(j >=0 && (liensTopDoc[j].id.indexOf("option")==-1 || liensDoc[i].href.indexOf(liensTopDoc[j].href)==-1)) j--;
	 if (j>=0) {
	   liensDoc[i].onmouseover = overOption;
	   liensDoc[i].onmouseout = outOption;
	   }
	 i++;
	 }
}

function addLoadEvent(func){
 var oldonload = window.onload;
 if(typeof window.onload != 'function'){window.onload = func;}
 else{window.onload = function(){oldonload();func();}}
}

addLoadEvent(function () {
//MM_reloadPage(true);
ajusteInterface();
lienInterface();
});
