// ************************************************
// gestion onload et onunload
// ************************************************
function SectionInit() {
  sCookieValue = ReadCookie("menu");
  if(sCookieValue != null) {
    if(sCookieValue.search("menu:false") != -1) { bGblMenuvisible = true; MenuVisible(); }
    if(sCookieValue.search("menu:true") != -1) { bGblMenuvisible = false; MenuVisible(); } // on le fait tout de même apparaître, bug ie
  }
  bGblPageLoaded = true;
}

function SectionQuit() {
  CreateCookie("menu", "menu:" + bGblMenuvisible, 15);
}

// ************************************************
// gestion de la popup sur les sections
// ************************************************
var bGblSectionPopupVisible = false;
var bGblSectionPopupId      = "";
function SectionPopupShow(sId, sChapter, sSection, sGallery, iQuantity) {
  if(bGblSectionPopupVisible == false) {
    arrayBody = findPos("body");
    arrayMenu = findPos("menudetail");
    if(arrayMenu[3] > arrayBody[3]) { iDocumentHeight = arrayMenu[3];  }
    else { iDocumentHeight = arrayBody[3]; }
    arrayPos = findPos(sId);
    document.getElementById("section_popup").style.left      = arrayPos[0] + arrayPos[2] + 2 + "px";
    if(iQuantity > 5) { iQuantity = 5; }
    if(iDocumentHeight < (arrayPos[1] + (iQuantity * 75))) { iTop = iDocumentHeight - (iQuantity * 75); }
    else { iTop = arrayPos[1]; }
    document.getElementById("section_popup").style.top       = iTop + "px";
    document.getElementById("section_popup").style.display   = "block";
    document.getElementById(sId).style.backgroundColor = "#222222";
    AjaxLoadSectionPopupImg(sChapter, sSection, sGallery);
    bGblSectionPopupVisible = true;
    bGblSectionPopupId      = sId;
  }
}
function SectionPopupHide(sId, iPosX, iPosY) {
  if(bGblSectionPopupVisible = true) {
    if((ObjInside("section_popup", iPosX, iPosY) == false) || (sId != bGblSectionPopupId))  {
      document.getElementById("section_popup").style.display  = "none";
      document.getElementById(sId).style.backgroundColor = "#000000";
      bGblSectionPopupId      = "";
      bGblSectionPopupVisible = false;
    }
  }
}
function SectionPopupOver() {
  document.getElementById(bGblSectionPopupId).style.backgroundColor = "#222222";
}
function SectionPopupOut(iPosX, iPosY) {
  if(bGblSectionPopupVisible == true) {
    if(sGblNavigator == "ie") {
      iPosX = iPosX - 2; // bug de microsoft sûrement dû aux marges
      iPosY = iPosY - 2; // bug de microsoft
    }
    if((ObjInside("section_popup", iPosX, iPosY) == false) && (ObjInside(bGblSectionPopupId, iPosX, iPosY) == false)) {
      arrayPopup = findPos("section_popup");
      document.getElementById("section_popup").style.display  = "none";
      document.getElementById(bGblSectionPopupId).style.backgroundColor = "#000000";
      bGblSectionPopupId      = "";
      bGblSectionPopupVisible = false;
    }
  }
}

// ************************************************
// gestion du chargement des imagettes par XMLHttpRequest
// ************************************************
function stateSectionPopupImgLoaded() {
  if (xmlHttp.readyState == 4) {
    document.getElementById("section_popup_img").innerHTML = xmlHttp.responseText;
  }
}
function AjaxLoadSectionPopupImg(sChapter, sSection, sGallery) {
  document.getElementById("section_popup_img").innerHTML = "<div class=\"ajax_loader\" ><img class=\"ajax_loader_img\" src=\"image/ajax-loader.gif\" alt=\"loading\" /></div>";

  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null) {
    alert("Your browser does not support AJAX!");
    return;
  }
  var url = "common/ajax.php";
  url = url + "?fn=LoadSectionPopupImg";
  url = url + "&c=" + sChapter;
  url = url + "&s=" + sSection;
  url = url + "&g=" + sGallery;
  url = url + "&id=" + Math.random();
  xmlHttp.onreadystatechange = stateSectionPopupImgLoaded;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
}
