// Liste des elements qui seront masques lors de l'effet Lightbox (et reaffiches par la suite)
var gts_LBElementsId = new Array();
//var goEvent = null;

function LLB_addElementToHide(psId) {
	gts_LBElementsId[gts_LBElementsId.length] = psId;
}

function LLB_showElements(pbShow) {
	var eElement = null;
	var sDisplay = "";
	var iIdx = 0;
	
	if (pbShow)
		sDisplay = "block";
	else
		sDisplay = "none";
		
	for(iIdx = 0; iIdx < gts_LBElementsId.length; iIdx++) {
		eElement = $(gts_LBElementsId[iIdx]);
		if (eElement != null)
			eElement.style.display = sDisplay;
	}	
}


function showBox() {
	var bod = document.getElementsByTagName("body")[0];
		if (bod != null) {
		var htm = document.getElementsByTagName("html")[0];
			
		var clt_size = LLB_getClientSize();
		var eOverlay = $("overlay");
	
		if (eOverlay == null) {	
			eOverlay = document.createElement("div");
			eOverlay.id	= "overlay";
			bod.appendChild(eOverlay);
		}
			
		eOverlay.style.width = clt_size.maxWidth + "px";
		if (_isUInt(document.body.scrollHeight));
			eOverlay.style.height = document.body.scrollHeight + "px"; 
		eOverlay.style.display = "block";
		LLB_centerElement("box");
		LLB_showElements(false);
	}
    return false;
}

function hideBox(){
    $("box").style.display = "none";
    $("overlay").style.display = "none";
    LLB_showElements(true);
    return false;
}

function refreshBox() {
	var eOverlay = document.getElementById("overlay");
	if (eOverlay != null) {
		if (eOverlay.style.display != "none")
			showBox();
		else
			if (_isUInt(document.body.scrollHeight));
				eOverlay.style.height = document.body.scrollHeight + "px"; 
	}
}

function LLB_centerElement(psId){
	var eElement = $(psId);
	if (eElement == null) return false;
    
	var stClientSize = LLB_getClientSize();
	var stScroll = LLB_getScrollXY();
    eElement.style.position = "absolute";
    eElement.style.zIndex   = 1099;

	var stDimensions = LLB_getDimensions(eElement);

	var iLeft = LLB_getValue((stClientSize.width - stDimensions.width) / 2 + stScroll.x);
	var iTop = LLB_getValue((stClientSize.height - stDimensions.height) / 2 + stScroll.y);

    eElement.style.left = iLeft + "px";
    eElement.style.top  = iTop + "px";
    eElement.style.display  = "block";
}

function LLB_getValue(piValue) {
	var iValue = parseInt(piValue);
	if (isNaN(iValue))
		return 0;
	else if (iValue < 0)
		return 0;
	else return iValue;
}

function LLB_obtenirElementPosition(peElement) {
	var eElement = peElement;
	var iTop = 0;
	var iLeft = 0;
	while(eElement != null) {
		iTop += eElement.offsetTop;
		iLeft += eElement.offsetLeft;
		eElement = eElement.offsetParent;
	}
	return {top: iTop, left: iLeft};
}

function LLB_getDimensions(element) {
    if (element.style.display != "none")
      return {width: element.offsetWidth, height: element.offsetHeight};

    // All *Width and *Height properties give 0 on elements with display none,
    // so enable the element temporarily
    var els = element.style;
    var originalVisibility = els.visibility;
    var originalPosition = els.position;
    els.visibility = 'hidden';
    els.position = 'absolute';
    els.display = '';
    var originalWidth = element.clientWidth;
    var originalHeight = element.clientHeight;
    els.display = 'none';
    els.position = originalPosition;
    els.visibility = originalVisibility;
    return {width: originalWidth, height: originalHeight};
}

function LLB_getClientSize() {
    var iWidth  = 0;
    var iHeight = 0;
    var iMaxWidth  = 0;
    var iMaxHeight = 0;
	var bOverflowX = false;
	var bOverflowY = false;

    if ( typeof(window.innerWidth) == 'number' ){
        iWidth  = window.innerWidth;
        iHeight = window.innerHeight;
    }else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
        iWidth  = document.documentElement.clientWidth;
        iHeight = document.documentElement.clientHeight;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight) ){
        iWidth  = document.body.clientWidth;
        iHeight = document.body.clientHeight;
    }

	var eTopContainer = $("topContainer");
	if (eTopContainer == null) {
		iMaxWidth = iWidth;
		iMaxHeight = iHeight;
	}
	else {
		iMaxWidth = eTopContainer.offsetWidth;
		iMaxHeight = eTopContainer.offsetHeight;

		if (iMaxHeight > iHeight)
			bOverflowX = true;
		else
			iMaxHeight = iHeight;

		if (iMaxWidth > iWidth)
			bOverflowX = true;
		else
			iMaxWidth = iWidth;
	}

    return {width: iWidth, height: iHeight, maxWidth: iMaxWidth, maxheight: iMaxHeight, overflowY: bOverflowX, overflowX: bOverflowY};
}

function LLB_getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return {x: scrOfX, y: scrOfY};
}		
