function addImageForm() {
    hideReplaceImageForm();
    document.getElementById('addForm').style.display = "block";
}

function hideAddImageForm() {
    document.getElementById('addForm').style.display = "none";
}

var doc = null;
function replaceImageForm(id) {
    hideAddImageForm();
    var idInput = document.getElementById('replaceImageIdInput');
    if (idInput.value == "") {
        idInput.value = id;
        document.getElementById('replaceForm').style.display = "block";
        document.getElementById('divImage'+id).style.borderColor = "red";
    } else if (idInput.value == id) {
        idInput.value = "";
        hideReplaceImageForm();
        document.getElementById('divImage'+id).style.borderColor = "black";
    } else {
        hideReplaceImageForm();
        var temp = document.getElementById('divImage'+id).innerHTML;
        document.getElementById('divImage'+ id).innerHTML = document.getElementById('divImage'+ idInput.value).innerHTML;
        document.getElementById('divImage'+ idInput.value).innerHTML = temp;
        document.getElementById('divImage'+id).style.borderColor = "black";
        document.getElementById('divImage'+idInput.value).style.borderColor = "black";
        doc = new XML(); 
        doc._method = "POST";
        doc.setAttribute("sourceImageId", idInput.value);
        doc.setAttribute("targetImageId", id);
        doc.setAttribute("uniqId", Math.round(Math.random()*10000));
        doc.sendAndLoad("actions-vauvertSwapImage.do");
        idInput.value = "";
    }
}

function hideReplaceImageForm() {
    document.getElementById('replaceForm').style.display = "none";
}

function showImage(id) {
    document.getElementById('bigpic').src="uploaded/Gallery/" + id + "-Large.jpg";
}

function deleteImage() {
    if (confirm("Voulez-vous vraiment effacer cette image?")) {
        var id = document.getElementById('replaceImageIdInput').value;
        var page = document.getElementById('replaceImagePageInput').value;
        window.location='actions-vauvertDeleteImage.do?imageId='+id+'&page='+page;
    }
}

/**
 * Comment
 */
var height = 0;
var timer;
var height2 = 520;
var margiin = 0;
var largeurImage = 102;



// Bouton Bas
function scrollHoldDown(id) {
  scrollDown(id,false);
  timer=setTimeout("scrollHoldDown('"+id+"')",25);
}
// Bouton Haut
function scrollHoldUp(id, parentId) {
  scrollUp(id, parentId,false);
  timer=setTimeout("scrollHoldUp('"+id+"', '"+parentId+"')",25);
}
// Bouton Bas
function scrollHoldDownMENU(id) {
  scrollDown(id,true);
  timer=setTimeout("scrollHoldDownMENU('"+id+"')",25);
}
// Bouton Haut
function scrollHoldUpMENU(id, parentId) {
  scrollUp(id, parentId,true);
  timer=setTimeout("scrollHoldUpMENU('"+id+"', '"+parentId+"')",25);
}
// Bouton Next
function scrollHoldRight(id, parentId, nb) {    
    longueur = (nb * largeurImage) * -1;
    if ((margiin-408) > longueur) {
    scrollRight(id);
    timer=setTimeout("scrollHoldRight('"+id+"', '"+parentId+"', '"+nb+"')",25);
  }
}
// Bouton Prev
function scrollHoldLeft(id) {
    if (margiin < 0) {
      scrollLeft(id);
      timer=setTimeout("scrollHoldLeft('"+id+"')",25);
    }
}

/**
 * Comment
 */
function scrollStop() {
    clearTimeout(timer);
}

function scrollDown(id,menu) {
    var marginTop;
    var Top;
    if(document.defaultView) {
      marginTop = document.defaultView.getComputedStyle(document.getElementById(id),null).getPropertyValue('margin-top');
    }
    else if(document.getElementById(id).currentStyle) {
        marginTop = document.getElementById(id).currentStyle['marginTop'];
    }
    if (marginTop.substr(0,marginTop.length-2) < 0) {
      height+=5;
      document.getElementById(id).style.marginTop=height+"px";
      if(menu)document.getElementById(id+'2').style.marginTop=height+"px";
    }
}

function scrollUp(id, parentId, menu) {
    var marginTop;
    var Top;
    if(document.defaultView) {
      marginTop = document.defaultView.getComputedStyle(document.getElementById(id),null).getPropertyValue('margin-top');
    }
    else if(document.getElementById(id).currentStyle) {
        marginTop = document.getElementById(id).currentStyle['marginTop'];
    }
    if (((marginTop.substr(0,marginTop.length-2))*-1)-20 < document.getElementById(id).offsetHeight-document.getElementById(parentId).offsetHeight) {
      height-=5;
      document.getElementById(id).style.marginTop=height+"px";
      if(menu)document.getElementById(id+'2').style.marginTop=height+"px";
    }
}
function scrollLeft(id) {
      height2-=8;
      margiin+=8;
      document.getElementById(id).style.marginLeft=margiin+"px";
      document.getElementById(id).style.width=height2+"px";
}

function scrollRight(id) { 
      height2+=8;
      margiin-=8;
      document.getElementById(id).style.marginLeft=margiin+"px";
      document.getElementById(id).style.width=height2+"px";
   
}



function toCamelCase( sInput ) {
    var oStringList = sInput.split('-');
    if(oStringList.length == 1)   
        return oStringList[0];
    var ret = sInput.indexOf("-") == 0 ?
       oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1) : oStringList[0];
    for(var i = 1, len = oStringList.length; i < len; i++){
        var s = oStringList[i];
        ret += s.charAt(0).toUpperCase() + s.substring(1)
    }
    return ret;
}



// gallery: affichage

var lockedGalleryMedia = -1;
var galleryAdmin = false;

function setAdminGallery() {
    galleryAdmin = true;
}

function chgBigImgInGallery(mediaId, ext) {    
    if(lockedGalleryMedia == -1) {
        document.getElementById('bigLeftGal').src = 'uploaded/cms_gallery/' + mediaId + '-Large.' + ext;   
        document.getElementById('lnkZoom').href = 'uploaded/cms_gallery/' + mediaId + '-Default.' + ext; 
    }
}

function lockImgInGallery(mediaId, ext) {
    if(mediaId == lockedGalleryMedia) {        
        document.getElementById('boxGallery-' + lockedGalleryMedia).style.border = 'none';
        lockedGalleryMedia = -1;        
        
        if(galleryAdmin) {
            document.getElementById('galleryAddDiv').style.display = 'block';
            document.getElementById('galleryEditDiv').style.display = 'none';
        }         
        
        return;
    }

    if(lockedGalleryMedia != -1) {
        document.getElementById('boxGallery-' + lockedGalleryMedia).style.border = 'none';
        lockedGalleryMedia = -1;
        
        chgBigImgInGallery(mediaId, ext);
        
        lockedGalleryMedia = mediaId;
        document.getElementById('boxGallery-' + mediaId).style.border = '1px solid black';
        
        if(galleryAdmin) {
            document.getElementById('galleryAddDiv').style.display = 'none';
            document.getElementById('galleryEditDiv').style.display = 'block';
            
            document.getElementById('mediaIdModify').value = mediaId;
            document.getElementById('mediaIdDelete').value = mediaId;
        }  
    }
    else {
        lockedGalleryMedia = mediaId;
        document.getElementById('boxGallery-' + mediaId).style.border = '1px solid black';
        
        if(galleryAdmin) {
            document.getElementById('galleryAddDiv').style.display = 'none';
            document.getElementById('galleryEditDiv').style.display = 'block';
            
            document.getElementById('mediaIdModify').value = mediaId;
            document.getElementById('mediaIdDelete').value = mediaId;
        }    
    } 
}

function imgOver(no,ext){
    document.getElementById('i_'+no).src= "images/homepage/icone_"+no+ext+".jpg";
}
//**************************************************************************************************
//**************************************************************************************************
//// DIAPORMA
//**************************************************************************************************
//**************************************************************************************************
var timer2;
var timer3;
var id = 0;
var len;
var diapo_array;
var alpha = 0;

function start_diaporama(diapo_array){
   len = diapo_array.length;
   if(len!=1){
    alpha = 0;
    fadeInOut('IN');
   }else{
      // FIREFOX
     document.getElementById('img_diapo').style.opacity=100;
     // IE
     if (document.body.filters != undefined){
          document.getElementById('img_diapo').style.filter = 'alpha(opacity:100)';
      }
   }
}

function fadeInOut(TF){
   if(TF=='IN'){  
       if(alpha==100){
           clearTimeout(timer2);
           timer2=setTimeout("attendre('OUT')",3000);
       }else{
           alpha+=5;
           // FIREFOX
           document.getElementById('img_diapo').style.opacity=(alpha/100);
           // IE
           if (document.body.filters != undefined){
                document.getElementById('img_diapo').style.filter = 'alpha(opacity:' + alpha + ')';
            }
           timer2=setTimeout("fadeInOut('IN')",100);
       }
   }else{
      if(alpha==0){ 
           clearTimeout(timer2);
           changeBgDiapo()
       }else{
           alpha-=5;
           // FIREFOX
           document.getElementById('img_diapo').style.opacity=(alpha/100);
           // IE
           if (document.body.filters != undefined){
                document.getElementById('img_diapo').style.filter = 'alpha(opacity:' + alpha + ')';
            }
           timer2=setTimeout("fadeInOut('OUT')",100);
       } 
   }   
}

function attendre(TF){
    if(TF=='IN'){
        fadeInOut('IN');
    }else{
        fadeInOut('OUT'); 
    }
}

function changeBgDiapo(){
   id++; 
   if(id==len){
       id=0; 
    }
    document.getElementById('img_diapo').src='uploaded/Diaporama/'+diapo_array[id]; 
    timer2=setTimeout("attendre('IN')",1000);
}
