function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function dump_props(obj, obj_name) {
    var result= "", i= "";
    for( i in obj)
        result += obj_name + "." + i + " = "
                  + obj[i] + "<br>\n";
    return result;
}

function dump_element_attributes(element)
{
var target = element;
attributes_list = new Array();
nb_attributes = target['attributes'].length;
for(i=0;i<nb_attributes;i++)
{
        attributes_list[i] = target['attributes'].item(i).nodeName +' = '+target['attributes'].item(i).nodeValue;
}
attributes = attributes_list.join('&');
return(attributes);
//return true;
}

function getStyle(el,styleProp)
{
        var x = document.getElementById(el);
        if (x.currentStyle)
                var y = x.currentStyle[styleProp];
        else if (window.getComputedStyle)
                var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
        return y;
}

function toogle_display(id_element){
        element_handler = document.getElementById(id_element);
        //alert(dump_props(element_handler.style,"document.style"));
        actual_display = getStyle(id_element,"display")
        //alert('actual_display = '+actual_display);
        element_handler.style.display = ((actual_display == "none")?"block":"none");
}

var menu_focus = null;
var menu_normal = null;
var icon = null;

function reset_menu_variables(){
  menu_focus = null;
  menu_normal = null;
  icon = null;
}





function catch_menu_layer(num){

  // Booléen reconnaissant le navigateur (vu en partie 2)
  isIE = (document.all);
  isNN6 = (!isIE) && (document.getElementById);

  // Compatibilité : l'objet menu est détecté selon le navigateur
  if (isIE){
    menu_focus = document.all['partie_focus' + num];
    menu_normal = document.all['partie_normal' + num];
    icon = document.all['ElementIcone' + num];
    return(true);
  } else if (isNN6){
    menu_focus = document.getElementById('partie_focus' + num);
    menu_normal = document.getElementById('partie_normal' + num);
    icon = document.getElementById('ElementIcone' + num);
    return(true);
  } else {      // ni l'un ni l'autre: pas compatible avec le navigateur
    return(false);
  }

}

function clicMenu(num) {
  if(menu_normal == null){
        //alert('ok');
      if(catch_menu_layer(num)== false) return(false);
  }
  // On ouvre ou ferme
  //alert(num);
  if (menu_normal.style.display == "none"){
    // Cas ou le menu est ouvert
    CloseMenu(num);
  } else {
    // On l'ouvre
    OpenMenu(num);
  }
}

function OpenMenu(num){
  if(menu_normal == null){
      if(catch_menu_layer(num)== false) return(false);
  }
  // On ouvre quelque soit son état
  menu_normal.style.display = "none"
  menu_focus.style.display = ""
  icon.src = "images/icone_croix.gif";
  reset_menu_variables();  // on remet tout à zéro
}
function CloseMenu(num){
  if(menu_normal == null){
      if(catch_menu_layer(num)== false) return(false);
  }
  menu_normal.style.display = ""
  menu_focus.style.display = "none"
  icon.src = "images/icone_fleche.gif";
  reset_menu_variables();  // on remet tout à zéro
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**********/
var dom = (document.getElementById)? true:false;
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;

/*****************************/
/* gestion des images */
/* structure du tableau */
/* [string nom_fichier,bool visible,int num_fichier, string titre_fichier]   */
/*****************************/

function set_event(new_img,num_image){

        if (ie4) {
                new_img.onclick = function (e){select_image(num_image);OpenMenu('3');};
        }else if (dom) {
                new_img.addEventListener('click',function (e){select_image(num_image);OpenMenu('3');}, false);
        }else if (ns4) {
                new_img.captureEvents(Event.CLICK);
                new_img.onclick = function (e){select_image(num_image);OpenMenu('3');};
        }
}


function select_image(num_image){
        if(photo_array.length == 0) return(false);
        document.getElementById('image_big').src = document_path+photo_array[num_image][0];
        document.getElementById('image_big').style.height = "550px";
        selected_image = num_image;
}

function remove_image(){
        if(nb_photo != 0){
                if(confirm('Voulez-vous vraiment retirer cette image du diaporama')){
                        var images_div = document.getElementById('div_vignette');
                        num_pic_to_remove = (photo_array[selected_image][2]-1);
                        //alert(num_pic_to_remove);
                        images_div.removeChild(images_div.getElementsByTagName('img')[num_pic_to_remove]);

                        photo_array[selected_image][1] = '0';
                        photo_array_length = photo_array.length;
                        for(i=selected_image;i<photo_array_length;i++){
                                if(photo_array[i][2] != '0'){
                                        photo_array[i][2]--;
                                }
                        }
                        nb_photo--;
                        is_selected = 0;
                        if(nb_photo != 0){
                                for(i=0;i<photo_array_length;i++){
                                        if(photo_array[i][1] == '1'){
                                                select_image(i);
                                                is_selected = 1;
                                                i = photo_array_length;
                                        }
                                }

                        }
                        if(is_selected == 0){
                                var new_div = document.createElement('div');
                                var new_img = document.createElement('img');
                                new_img.src = 'images/JPG.gif';
                                new_img.classId = 'document_icon';
                                new_div.appendChild(new_img);
                                new_div.id = 'photo_icon_div';
                                images_div.appendChild(new_div);
                                document.getElementById('image_big').src = "images/espaceur.gif";
                                document.getElementById('image_big').style.height = "10px";
                        }

                }
        }else{
                alert('Votre diaporama est vide');
        }

}

function add_image_to_diap(img_name){
  var document_div = document.getElementById('div_vignette');
  var dummy_icon_div = document.getElementById('photo_icon_div');
  if(dummy_icon_div) document_div.removeChild(dummy_icon_div);

  var new_img = document.createElement('img');
  new_img.src = document_path+'mini/'+img_name+'?'+Math.floor(Math.random()*10000);
  new_img.className = 'loaded';
  set_event(new_img,photo_array.length);
  document_div.appendChild(new_img);
  nb_photo++;
  photo_array[photo_array.length] = [img_name,'1',nb_photo];

}

/*************************************/

/* gestion de la miniature */

/*****************************/

function add_image_mini(img_name){

  var document_div = document.getElementById('div_mini');

  var new_img = document.createElement('img');

  new_img.src = document_path+'mini/'+img_name+'?'+Math.floor(Math.random()*10000);

  new_img.className = 'loaded';

  set_event(new_img,photo_array.length);

  document_div.appendChild(new_img);

  projets_mini_name = img_name;
}

/*************************************/
/* gestion des autres objets */
/*****************************/


function set_event_remove_doc(objet,num_objet,type_objet){

        //alert(nb_video);
        if (ie4) {
                objet.onclick = function (e){remove_objet(num_objet,type_objet);};
        }else if (dom) {
                objet.addEventListener('click',function (e){remove_objet(num_objet,type_objet);}, false);
        }else if (ns4) {
                objet.captureEvents(Event.CLICK);
                objet.onclick = function (e){remove_objet(num_objet,type_objet);};
        }
}

function set_event_onmouseout_over(objet,image_onmouseover,image_onmouseout){

        if (ie4) {
                objet.onmouseover = function (e){objet.src = image_onmouseover;};
                objet.onmouseout = function (e){objet.src = image_onmouseout;};
        }else if (dom) {
                objet.addEventListener('mouseover',function (e){objet.src = image_onmouseover;}, false);
                objet.addEventListener('mouseout',function (e){objet.src = image_onmouseout;}, false);
        }else if (ns4) {
                objet.captureEvents(Event.MOUSEOVER);
                objet.onmouseover = function (e){objet.src = image_onmouseover;};
                objet.captureEvents(Event.MOUSEOUT);
                objet.onmouseout = function (e){objet.src = image_onmouseout;};
        }
}

function remove_objet(num_document,type_document){
//      alert('nb_video: '+this.document.nb_video);
//        return false;

/*
for (prop in this)
    {
    if(prop == "ownerDocument") alert(this[prop]);
    }
*/
/*
ATTENTION:

LE SWITCH SUIVANT PEUT SEMBLER ÊTRE IDENTIQUE MAIS IL NE L'EST PAS
CELA LAISSE LA POSSIBILITE DE PERSONNALISER LES ACTIONS EN FONCTION DU TYPE D'OBJET SUR LEQUEL IL EST APPLIQUE
*/
        switch (type_document) {
                case 3:
                        dummy_icon_div_name = 'video_icon_div';
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        nb_document = nb_video;
                        var document_div = document.getElementById('div_video');
                        var documents_array = videos_array;
                        image_icone_dummy = 'iconevideo1.gif';
                        image_icone_normale = 'iconevideo1.gif';
                        image_icone_survol = 'iconevideosurvol.gif';
                        intitule_alt = 'vidéo';
                        break;
                case 4:
                        dummy_icon_div_name = 'pdf_icon_div';
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        nb_document = nb_pdf;
                        var document_div = document.getElementById('div_pdf');
                        documents_array = pdfs_array;
                        image_icone_dummy = 'iconepdf1.gif';
                        image_icone_normale = 'iconepdf1.gif';
                        image_icone_survol = 'iconepdf1survol.gif';
                        intitule_alt = 'PDF';
                        break;
                case 5:
                        dummy_icon_div_name = 'son_icon_div';
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        nb_document = nb_son;
                        var document_div = document.getElementById('div_son');
                        documents_array = sons_array;
                        image_icone_dummy = 'iconeson.gif';
                        image_icone_normale = 'iconeson.gif';
                        image_icone_survol = 'iconesonsurvol.gif';
                        intitule_alt = 'son';
                        break;
                case 6:
                        dummy_icon_div_name = 'plan_icon_div';
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        nb_document = nb_plan;
                        var document_div = document.getElementById('div_plan');
                        documents_array = plans_array;
                        image_icone_dummy = 'iconecarto1.gif';
                        image_icone_normale = 'iconecarto1.gif';
                        image_icone_survol = 'iconecartosurvol.gif';
                        intitule_alt = 'plan';
                        break;
                case 7:
                        dummy_icon_div_name = 'quick_time_icon_div';
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        nb_document = nb_quick_time;
                        var document_div = document.getElementById('div_quick_time');
                        documents_array = quick_times_array;
                        image_icone_dummy = 'iconeQT1.gif';
                        image_icone_normale = 'iconeQT1.gif';
                        image_icone_survol = 'iconeQTsurvol.gif';
                        intitule_alt = 'quicktime';
                        break;
                case 8:
                        dummy_icon_div_name = 'lien_icon_div';
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        nb_document = nb_lien;
                        var document_div = document.getElementById('div_lien');
                        documents_array = liens_array;
                        image_icone_dummy = '';
                        image_icone_normale = '';
                        image_icone_survol = '';
                        break;
                default:
                        alert('pas de bol :'+type_document);
                        return(false);
        }

        if(nb_document != 0){
                if(confirm('Voulez-vous vraiment retirer ce document?')){
                        num_doc_to_remove = (documents_array[num_document][2]-1);
                        document_div.removeChild(document_div.getElementsByTagName('div')[num_doc_to_remove]);
                        documents_array[num_document][1] = '0';
                        documents_array_length = documents_array.length;
                        //alert('document_array_length: '+documents_array_length);
                        for(i=num_document;i<documents_array_length;i++){
                                if(documents_array[i][2] != '0'){
                                        documents_array[i][2]--;
                                }
                        }
                        nb_document--;
                        if(nb_document == 0){
                                var new_div = document.createElement('div');
                                var new_img = document.createElement('img');
                                new_img.src = 'images/'+image_icone_dummy;
                                new_img.classId = 'document_icon';
                                new_div.id = dummy_icon_div_name;
                                new_div.appendChild(new_img);
                                document_div.appendChild(new_div);
                        }
                }
                // je suis obligé de mettre ce genre de code moche et hideux car javascript ne gère pas l'addressage par référence!?!?!?
                switch (type_document) {
                        case 3:
                                nb_video = nb_document;
                                videos_array = documents_array;
                                break;
                        case 4:
                                nb_pdf = nb_document;
                                pdfs_array = documents_array;
                                break;
                        case 5:
                                nb_son = nb_document;
                                sons_array = documents_array;
                                break;
                        case 6:
                                nb_plan = nb_document;
                                plans_array = documents_array;
                                break;
                        case 7:
                                nb_quick_time = nb_document;
                                quick_times_array = documents_array;
                                break;
                        case 8:
                                nb_lien = nb_document;
                                liens_array = documents_array;
                                break;
                }
        }else{
                alert('Votre diaporama est vide');
        }
}

function add_document_to_diap(document_name,document_titre,type_document){
        switch (type_document) {
                case 3:
                        dummy_icon_div_name = 'video_icon_div';
                        nb_document = nb_video;
                        var document_div = document.getElementById('div_video');
                        documents_array = videos_array;
                        image_icone_normale = 'images/iconevideo1.gif';
                        image_icone_survol = 'images/iconevideosurvol.gif';
                        intitule_alt = 'vidéo';
                        //alert(nb_video);
                        break;
                case 4:
                        dummy_icon_div_name = 'pdf_icon_div';
                        nb_document = nb_pdf;
                        var document_div = document.getElementById('div_pdf');
                        documents_array = pdfs_array;
                        image_icone_normale = 'images/iconepdf1.gif';
                        image_icone_survol = 'images/iconepdf1survol.gif';
                        intitule_alt = 'PDF';
                        break;
                case 5:
                        dummy_icon_div_name = 'son_icon_div';
                        nb_document = nb_son;
                        var document_div = document.getElementById('div_son');
                        documents_array = sons_array;
                        image_icone_normale = 'images/iconeson.gif';
                        image_icone_survol = 'images/iconesonsurvol.gif';
                        intitule_alt = 'son';
                        break;
                case 6:
                        dummy_icon_div_name = 'plan_icon_div';
                        nb_document = nb_plan;
                        var document_div = document.getElementById('div_plan');
                        documents_array = plans_array;
                        image_icone_normale = 'images/iconecarto1.gif';
                        image_icone_survol = 'images/iconecartosurvol.gif';
                        intitule_alt = 'plan';
                        break;
                case 7:
                        dummy_icon_div_name = 'quick_time_icon_div';
                        nb_document = nb_quick_time;
                        var document_div = document.getElementById('div_quick_time');
                        documents_array = quick_times_array;
                        image_icone_normale = 'images/iconeQT1.gif';
                        image_icone_survol = 'images/iconeQTsurvol.gif';
                        intitule_alt = 'quicktime';
                        break;
                case 8:
                        dummy_icon_div_name = 'lien_icon_div';
                        nb_document = nb_lien;
                        var document_div = document.getElementById('div_lien');
                        documents_array = liens_array;
                        image_icone_normale = '';
                        image_icone_survol = '';
                        break;
                default:
                        alert('pas de bol :'+type_document);
                        return(false);
        }

        switch (type_document) {
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                        var dummy_icon_div = document.getElementById(dummy_icon_div_name);
                        if(dummy_icon_div) document_div.removeChild(dummy_icon_div);

                        var new_div_container = document.createElement('div');
                        new_div_container.className = 'ElementAsuivre';

                        var new_link = document.createElement('a');
                        new_link.setAttribute('href',document_path+document_name);
                        new_link.setAttribute('target','_blank');

                        var new_link_span = document.createElement('span');
                        new_link_span.className = 'ElementLegende';
                        var new_link_span_text = document.createTextNode(document_titre);
                        new_link_span.style.cursor = 'pointer';
                        set_event_remove_doc(new_link_span,documents_array.length,type_document);
                        new_link_span.appendChild(new_link_span_text);

                        var new_link_img = document.createElement('img');
                        new_link_img.src = image_icone_normale;
                        new_link_img.setAttribute('alt',intitule_alt);
                        new_link_img.setAttribute('border','0');
                        set_event_onmouseout_over(new_link_img,image_icone_survol,image_icone_normale);

                        var new_link_br = document.createElement('br');


                        new_link.appendChild(new_link_img);
                        new_link.appendChild(new_link_br);
                        new_div_container.appendChild(new_link);
                        new_div_container.appendChild(new_link_span);
                        document_div.appendChild(new_div_container);
                        break;
                case 8:
                        var new_link = document.createElement('a');
                        new_link.setAttribute('href',document_titre);
                        new_link.setAttribute('target','_blank');

                        var new_link_text = document.createTextNode(document_titre);

                        var new_link_img = document.createElement('img');
                        new_link_img.src = 'images/supprimer.gif';
                        new_link_img.style.cursor = 'pointer';
                        set_event_remove_doc(new_link_img,documents_array.length,type_document);

                        new_link.appendChild(new_link_text);
                        var new_div = document.createElement('div');
                        new_div.appendChild(new_link);
                        new_div.appendChild(new_link_img);

                        document_div.appendChild(new_div);
                        break;
                default:
                        alert('pas de bol :'+type_document);
                        return(false);
        }

        nb_document++;
        documents_array[documents_array.length] = [document_name,'1',nb_document,document_titre];

        switch (type_document) {
                case 3:
                        nb_video = nb_document;
                        documents_array = videos_array;
                        break;
                case 4:
                        nb_pdf = nb_document;
                        pdfs_array = documents_array;
                        break;
                case 5:
                        nb_son = nb_document;
                        sons_array = documents_array;
                        break;
                case 6:
                        nb_plan = nb_document;
                        plans_array = documents_array;
                        break;
                case 7:
                        nb_quick_time = nb_document;
                        quick_times_array = documents_array;
                        break;
                case 8:
                        nb_lien = nb_document;
                        liens_array = documents_array;
                        break;
        }
}

