var td_onglet_last=null;
var num_last_sous_menu="";
var last_titre ="";
var recrutement='true';
var myJSONObject;
 
function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i=0; i<changeImages.arguments.length; i+=2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
        }
    }
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {
        avisto_navigation0_over = newImage("img/avisto-navigation0-over.gif");
        avisto_navigation1_over = newImage("img/avisto-navigation1-over.gif");
        avisto_navigation2_over = newImage("img/avisto-navigation2-over.gif");
        avisto_navigation3_over = newImage("img/avisto-navigation3-over.gif");
        avisto_navigation4_over = newImage("img/avisto-navigation4-over.gif");
        bottom2_over = newImage("img/bottom2-over.gif");
        bottom4_over = newImage("img/bottom4-over.gif");
        bottom6_over = newImage("img/bottom6-over.gif");
        pict0 = newImage("img/pict0.jpg");
        pict1 = newImage("img/pict1.jpg");
        pict2 = newImage("img/pict2.jpg");
        pict3 = newImage("img/pict3.jpg");
        pict4 = newImage("img/pict4.jpg");
        pict5 = newImage("img/pict5.jpg");
        pict6 = newImage("img/pict6.jpg");
        pict7 = newImage("img/pict7.jpg");
        pict8 = newImage("img/pict8.jpg");
        pict9 = newImage("img/pict9.jpg");
        pict10 = newImage("img/pict10.jpg");
        pict11 = newImage("img/pict11.jpg");
        pict12 = newImage("img/pict12.jpg");
        preloadFlag = true;
    }
}

function images() {
    document.pict.src = 'img/pict'+ (Math.round(Math.random()*11)+1) +'.jpg'
}
function getYear(){ //recupere l'ann�e courante'
    var d = new Date()
    y=d.getFullYear();
    return y;
}

function changeImage(numPage){
    
    //changer image bandeau
                            
    if(numPage=='5_0'){
        document.getElementById("td_image").innerHTML="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='793' height='158'>"+
            "<param name='movie' value='video/intro.swf'><param name=quality value=high><embed src='video/intro.swf' width='793' height='158' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash'></embed></object>";
    }else{
         document.getElementById("td_image").innerHTML="<a href=\"#\"><img src=\"img/pict0.jpg\" name=\"pict\" width=\"793\" height=\"158\" border=\"0\" id=\"pict\" onclick=\"changeContenu(5,0,'');\"></a>";
    images(); 
    }
     
}
function supp_rec(){ // suppression de la partie recrutement 
    // document.getElementById("td_rec").width='0';
      
    document.getElementById("td_rec").innerHTML="";
     
    document.getElementById("td_contenu").width=798;
      
    document.getElementById("tab_contenu").width=798;
       
    document.getElementById("td_onglet").style.backgroundImage = "url(img/onglet-carriere.gif)";
    // document.getElementById("td_onglet").innerHTML="Legal notice";

    document.getElementById("td_contenu2").style.backgroundImage = "url(img/back-table3.gif)";
    document.getElementById("img_bottom").width=798;
    document.getElementById("img_bottom").style.backgroundImage = "url(img/bottom-table3.gif)";
    
 

                  

}
 
function changeImageOnglet(num){ //changement de l'image des onglets
    
    if(td_onglet_last!=null){

      
        document.getElementById("td_onglet"+td_onglet_last).innerHTML="<a href='#'  onmouseover=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+"-over.gif'); return true;\" onmouseout=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+".gif'); return true;\"  onmousedown=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+"-over.gif'); return true;\"    onmouseup=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+"-over.gif'); return true;\"    onclick=\"changeImageOnglet("+td_onglet_last+");changeTheme("+td_onglet_last+");\">  <img  name='avisto_navigation"+td_onglet_last+"' src='img/avisto-navigation"+td_onglet_last+".gif' width='159' height='34' border='0'></a> ";
    
    }
    
    document.getElementById("td_onglet"+num).innerHTML="<img  name='avisto_navigation"+num+"' src='img/avisto-navigation"+num+"-over.gif' width='158' height='34' border='0' >";
         
    td_onglet_last=num;
 
    
}
function changeContenu_suite(intitule,contenu){ //suite du changement de contenu
    document.getElementById("td_onglet").innerHTML=intitule;
    document.getElementById("td_contenu2").innerHTML=contenu;
}
function changeTheme_suite(td_width,titre,td_suite,intitule,contenu,numTheme){ // suite du changgement de theme
    td1="<table  width='800' height='26' border='0' cellpadding='0' cellspacing='0' background='img/avisto-navigation6.gif'><tr>";
                                                
    td1+="<td id='"+numTheme+"_0' width='"+td_width+"' style='background-image: url(img/avisto-navigation8.gif);'><div class='linkwhite' align='center'>"+titre+"</div></td>"; 
            
    td1 =td1+ td_suite; 
    td1+="</tr></table>";
       
    document.getElementById('sous_menu').innerHTML=td1; 
    
    changeContenu_suite(intitule,contenu);
                
    changeImage('');
    last_titre=titre;
}
function change_couleur_sous_menu(numTheme,numPage,titre){ //change le sous menu
    if(numTheme<=4){
        td_id =numTheme+"_"+numPage;
        td_id_last =numTheme+"_"+num_last_sous_menu;
  
        document.getElementById(td_id).style.backgroundImage = "url(img/avisto-navigation8.gif)";
      
        document.getElementById(td_id_last).style.backgroundImage = "";
       
        document.getElementById(td_id).innerHTML="<div align='center' class='linkwhite'>"+titre+"</div>";
         
        
        document.getElementById(td_id_last).innerHTML="<div align='center'><a onclick='changeContenu("+numTheme+","+num_last_sous_menu+", \" "+last_titre+"\");' href='#' class='linkwhite'>"+last_titre+"</a></div>";
         
        
        num_last_sous_menu= numPage;
        last_titre=titre;
        
    }
}
function  modifierRecrutement(rec){
               // fonction qui decide s'il faut ajouter ou supprimer la partie recrutement'
    if(rec!=recrutement){ // il faut faire un changement
             
        if(rec=='true'){
            //rajouter le recrutement
           
            add_rec();
        }else{
                   
            // supprimmer le recrutement
            supp_rec();
        }
    }
    recrutement=rec;
}
function add_rec(){ //rajoute la partie sur le recrutement
    document.getElementById("td_rec").width=242;
    document.getElementById("td_rec").innerHTML="<table width='242' height='100%' border='0' cellpadding='0' cellspacing='0'>\n\
              <tr><td height='37' background='img/onglet-bleu.gif'><span class='titreonglet'>"+rec_intitule+"</span></td></tr>\n\
              <tr><td height='100%' valign='top' background='img/back-table2.gif' class='texte'>"+rec_contenu+"</td></tr>\n\
              <tr><td height='4' valign='top'><img src='img/bottom-table2.gif' width='242' height='8'></td></tr></table>";
    
      
 
    document.getElementById("td_contenu").width= 558;
      
    document.getElementById("tab_contenu").width=558;
       
    document.getElementById("td_onglet").style.backgroundImage = "url(img/onglet-gris.gif)";
    // document.getElementById("td_onglet").innerHTML="Legal notice";

    document.getElementById("td_contenu2").style.backgroundImage = "url(img/back-table1.gif)";
    document.getElementById("img_bottom").width= 558;
    document.getElementById("img_bottom").style.backgroundImage = "url(img/bottom-table1.gif)";
}
function vide_menus(numpage){ //vidage du sous menu pour la page d'accueil , contact et legal'
            
    document.getElementById('sous_menu').innerHTML="<table width='800' height='26' border='0' cellpadding='0' cellspacing='0' background='img/avisto-navigation6.gif'><tr><td> </td></tr></table>" 
    if(td_onglet_last!=null){

      
        document.getElementById("td_onglet"+td_onglet_last).innerHTML="<a href='#'  onmouseover=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+"-over.gif'); return true;\" onmouseout=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+".gif'); return true;\"  onmousedown=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+"-over.gif'); return true;\"    onmouseup=\"changeImages('avisto_navigation"+td_onglet_last+"', 'img/avisto-navigation"+td_onglet_last+"-over.gif'); return true;\"    onclick=\"changeImageOnglet("+td_onglet_last+");changeTheme("+td_onglet_last+");\">  <img  name='avisto_navigation"+td_onglet_last+"' src='img/avisto-navigation"+td_onglet_last+".gif' width='159' height='34' border='0'></a> ";
    
    }
    changeImage(numpage);
}
function changeTheme(numTheme){ //changement du theme
            
    td_suite='';nbPage=''; titre=''; td_width='';intitule ='';contenu='';
    num_last_sous_menu=0; recrutement_temp='';
                                              
                                                   
    nbPage = myJSONObject[numTheme].length;
    titre=myJSONObject[numTheme][0].titre;
    td_width=795/nbPage;
    recrutement_temp=myJSONObject[numTheme][0].recrutement;
                   
            for(i=1; i<nbPage; i++){
   
              td_suite+="<td id='"+numTheme+"_"+i+"' width='"+td_width+"'><div align='center'><a class='linkwhite' href='#' onclick=\"changeContenu("+numTheme+", "+i+",'"+myJSONObject[numTheme][i].titre+"')\">"+myJSONObject[numTheme][i].titre+"</a></div></td>";            
                     }                                 
     
        intitule=myJSONObject[numTheme][0].intitule;
    contenu=myJSONObject[numTheme][0].contenu;
                                            
    modifierRecrutement(recrutement_temp.toString());
    changeTheme_suite(td_width,titre,td_suite,intitule,contenu,numTheme);
      
}
 function changeContenu(numTheme,numPage,titre){ // changement du contenu de la page
   				closeAllAnnonceWindows();
              if(numTheme==5){ // le theme contenant les pages sans sous menu
                    vide_menus(numPage);
              }
                intitule='';contenu='';recrutement_temp='';
                        
                          
                                   intitule=myJSONObject[numTheme][numPage].intitule;
                                    contenu=myJSONObject[numTheme][numPage].contenu; 
                                recrutement_temp=myJSONObject[numTheme][numPage].recrutement;
                                                                  
                                                              
                                           
     modifierRecrutement(recrutement_temp.toString());  
 
changeImage(numTheme+'_'+numPage);
if(numTheme==4 && numPage==2){ // cas des offre d'emplois on affiche le top panel qui contient
	// le filtre et la grid de resultats
     document.getElementById("td_onglet").innerHTML=intitule;
     document.getElementById("td_contenu2").innerHTML="";
     showTopPanel();

}else{
   changeContenu_suite(intitule,contenu); 
}
                                                 
                                                change_couleur_sous_menu(numTheme,numPage,titre);  
                                            }
                                          
function video(){
   var   winVideo = new Ext.Window({
            constrainHeader :true,
                layout      : 'fit',
                width       : 419,
                height      : 310,
                 closable  :false,
                plain       : true,
              modal:true,
               title :'Pr�sentation d\'avisto',
              html     : '<embed src="video/PresentationVideoAvisto.wmv" autostart="true" width="400" height="350" quality=high>' ,
               cls:'winVideo'
              


                ,buttons: [{
                    text     : 'Close',
                    handler  : function(){
                        winVideo.close();
                    }
                }]
            });
        
        winVideo.show();
                }

function getUrl(){
  	
	var currentLocation =  document.location.href;
	
	
	ref_index=currentLocation.indexOf('ref');
	if(ref_index!=-1){
	
	ref=currentLocation.substring(currentLocation.lastIndexOf('=')+1);
	
	changeImageOnglet(4);changeTheme(4);changeContenu(4,2,'Offres');
	Ext.get('reference').set({value: ref});	
		Ext.getCmp("btnRech").handler.call(Ext.getCmp("btnRech").scope); 
	}
	
 
	
}
 