//-------------------------------------------------------------------------
// PRELOAD DES IMAGES SI COOKIE PAS DEJA EN PLACE
//-------------------------------------------------------------------------
var nImgToLoad = 0;
function PreloadImg(icArgs){
	diffHeight = avblPosHeight - (92/2);
	diffWidth = avblPosWidth - (171/2)
	document.getElementById("img_loader").style.top = diffHeight + "px";
	document.getElementById("img_loader").style.left = diffWidth + "px";
	document.getElementById("img_loader").style.display = "block";
    //--------------------------------------------------------------------
    document.getElementById("divPercent").innerHTML = "Loading: 0%"
	var Pic = icArgs.split("|");
	var imagesTag = "";
	nImgToLoad = Pic.length;
	for (i = 0; i < Pic.length; i++){
	   imagesTag += "<img onload='WaitforImgLoad()' id='img"+ Number(i+1) +"' src='"+ StylePath + Pic[i] +"'/>"
	   document.getElementById("preload_images").innerHTML = imagesTag;
	}
	
}
var nImgLoaded = 0;
function WaitforImgLoad(){
    nImgLoaded++;
    var percent = Math.round((nImgLoaded/nImgToLoad)*100);
    document.getElementById("divPercent").innerHTML = "Loading: "+percent+"%"
    if(nImgLoaded == nImgToLoad){
        document.getElementById("img_loader").style.display = "none";
        //alert("ALL LOAD DONE");
	    var pathname=location.pathname;
	    var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	    SetCookie("ImgLoader","Loaded",null,myDomain);        
        centerContent();
    }
}

//-------------------------------------------------------------------------
//  GESTION DU POSITIONNEMENT
//-------------------------------------------------------------------------
function adjustDivGallery(){
    if(document.getElementById("TitleHeader")){
        document.getElementById("divGallery").style.height = (360-document.getElementById("TitleHeader").offsetHeight)+"px";
    }else{
        document.getElementById("divGallery").style.height = "360px";
    }
}

function centerContent(){
    marginHeightBrowser = (IE)?(0):(0);
    marginWidthBrowser = (IE)?(0):(0);

    siteHeight = 550;//document.getElementById("divAll").offsetHeight;
    //-------------------------------------------------------------------------
    avaibleHeight = 0;
    if (self.innerHeight) // all except Explorer
    {
	    avaibleHeight = self.innerHeight;
	    avaibleWidth = self.innerWidth;
    }
    else if (IE6)
    {
	    avaibleHeight = document.documentElement.clientHeight;
	    avaibleWidth = document.documentElement.clientWidth;
    }
    else if (IE7) // other Explorers
    {
	    avaibleHeight = document.documentElement.clientHeight;
	    avaibleWidth = document.documentElement.clientWidth;
    }
    //-------------------------------------------------------------------------
    avblPosHeight = Math.floor(avaibleHeight/2);
    avblPosWidth = Math.floor(avaibleWidth/2);
	//alert("Hauteur disponible: " + avaibleHeight)

	diffHeight = avblPosHeight - (siteHeight/2);
	document.getElementById("divAll").style.top = diffHeight + "px";

	diffBgHeight = avblPosHeight - (1200/2) + marginHeightBrowser;
	diffBgWidth = avblPosWidth - (1600/2);
	document.body.style.backgroundPosition = diffBgWidth + "px  " + diffBgHeight + "px";

	//alert(diffHeight + " / " + diffBgHeight);
	//-------------------------------------------------------------------------
	document.getElementById("divContent").style.width = "810px";
	document.getElementById("divContent").style.height = "380px";

	document.getElementById("divAll").style.display = "block";
	if (IE6)document.getElementById("divContent").style.backgroundAttachment = "fixed";
	
	    
    if(document.getElementById("IFramePage")){
        document.getElementById("IFramePage").height = diffHeight-30;
    }   

}

//-------------------------------------------------------------------------
// INITIALISATIONS
//-------------------------------------------------------------------------

var marginHeightBrowser = (IE)?(0):(0);
var marginWidthBrowser = (IE)?(0):(0);
var siteHeight = 550;//document.getElementById("divAll").offsetHeight;
var avaibleHeight = 0;
var avaibleWidth = 0;
if (self.innerHeight) // all except Explorer
{
	avaibleHeight = self.innerHeight;
	avaibleWidth = self.innerWidth;
}
else if (IE6)
{
	avaibleHeight = document.documentElement.clientHeight;
	avaibleWidth = document.documentElement.clientWidth;
}
else if (IE7) // other Explorers
{
	avaibleHeight = document.documentElement.offsetHeight;
	avaibleWidth = document.documentElement.offsetWidth;
}
var avblPosHeight = Math.floor(avaibleHeight/2);
var avblPosWidth = Math.floor(avaibleWidth/2);

//-------------------------------------------------------------------------

var NavMenu;
var StylePath = "/Ext/Layouts/Common.Layout3/SITUP/images/";
function DoLayout(){
    NavMenu = document.getElementById("NavMenu");
    var imgLoader = GetCookie("ImgLoader");
    if(imgLoader == null){
	    PreloadImg("bg3/bg_body1.jpg|bg3/bg_body2.jpg|bg3/bg_body3.jpg|bg2/bg_body1.jpg|bg2/bg_body2.jpg|bg2/bg_body3.jpg|bg1/bg_body1.jpg|bg1/bg_body2.jpg|bg1/bg_body3.jpg");
	 }else{
	    centerContent();
	    if(document.getElementById("divGallery")){
	        adjustDivGallery();
	    }
	 }   
}

window.onresize=centerContent;
window.onchange=centerContent;

