//**********
//script de la page d'accueil
//Date de création : 07/11/2005
//Modifié le : 07/11/2005
//Auteur : Grégory MICHAU
//Copyright I.D.M.S. (c) 2005
//**********

var ie = /MSIE/.test(navigator.userAgent);
var timer1;
var delay = 100;
var pMiniH;
var pMiniW;
var orgTop;
var orgLeft;

var oldTop;
var oldLeft;

var indexFrame = 2;


function Init()
{
	document.getElementById("contentMaire").style.display = "block";
	var pNews = document.getElementById("PanelNews");
	var pMini = document.getElementById("PanelMiniatures");
	var pMaire = document.getElementById("PanelMaire");
	var b = document.body;

	if(!ie)
	{
		b.style.overflow = "hidden";
		document.addEventListener("DOMMouseScroll",function(e){e.preventDefault();},false);
		pNews.addEventListener("mouseover",affScroll,true);
		pNews.addEventListener("mouseout",stopScroll,true);
	}else{
		pNews.attachEvent("onmouseover",affScroll);
		pNews.attachEvent("onmouseout",stopScroll);
	}
	var mTop = 5;
	var mBottom = 3;
	var mLeft = 5;
	var mRight = 3;
	b.style.marginTop = mTop;
	b.style.marginBottom = mBottom;
	b.style.marginRight = mRight;
	b.style.marginLeft = mLeft;
	//---
	var cHeight;
	var cWidth;
	//---
	cHeight = (ie)?b.offsetHeight:innerHeight;
	cWidth = (ie)?b.offsetWidth:innerWidth;
	
	pMini.style.height = cHeight - mTop - mBottom;
	pMini.style.top = mTop;
	pMini.style.left = pMaire.offsetWidth + mLeft + 2;
	pMini.style.width = (cWidth - pMaire.offsetWidth - mLeft - mRight)-2;
	
	var d1 = document.getElementById("m1");
	var d2 = document.getElementById("m2");
	var d3 = document.getElementById("m3");
	var d4 = document.getElementById("m4");
	d1.style.display = d2.style.display = d3.style.display = d4.style.display = "block";
	
	if(pMini.offsetHeight - pMaire.offsetHeight > 0)
	{	
		pNews.style.height = pMini.offsetHeight - pMaire.offsetHeight;
		//---------
		//initialisation des quatres sous conteneur d'actualités
		//calcul de la taille du conteneur pMini
		
		pMiniH = pMini.offsetHeight / 2;
		pMiniW = pMini.offsetWidth / 2;
		
		d1.style.width = pMiniW;
		d1.style.height = pMiniH;
		orgTop = d1.offsetTop;
		orgLeft = d1.offsetLeft;
		if(d1.scrollHeight > d1.offsetHeight)
			d1.firstChild.style.visibility = "visible";
		else
			d1.firstChild.style.visibility = "hidden";
		d2.style.width = pMiniW;
		d2.style.left = pMiniW;
		d2.style.height = pMiniH;
		d2.style.top = d1.offsetTop;
		if(d2.scrollHeight > d2.offsetHeight)
			d2.firstChild.style.visibility = "visible";
		else
			d2.firstChild.style.visibility = "hidden";
		d3.style.width = pMiniW;
		d3.style.height = pMiniH;
		d3.style.top = d1.offsetHeight;
		if(d3.scrollHeight > d3.offsetHeight)
			d3.firstChild.style.visibility = "visible";
		else
			d3.firstChild.style.visibility = "hidden";
		d4.style.width = pMiniW;
		d4.style.left = pMiniW;
		d4.style.height = pMiniH;
		d4.style.top = d3.offsetHeight;
		if(d4.scrollHeight > d4.offsetHeight)
			d4.firstChild.style.visibility = "visible";
		else
			d4.firstChild.style.visibility = "hidden";
	}else{
	//la fenetre devient trop petite pour afficher les informations de façon convenable
	//affiche l'image Nothing a la place des calques d'informations
		d1.style.display = d2.style.display = d3.style.display = d4.style.display = "none";
	}
}

function affScroll(e)
{
	
	var mX = (ie)?event.clientY:e.clientY;
	var pn = document.getElementById("PanelNews");
	var seuilH = pn.offsetTop + (pn.offsetHeight / 3);
	var seuilL = pn.offsetTop + (2*(pn.offsetHeight / 3));
	if(mX < seuilH)
	{
		if(timer1)
			clearInterval(timer1);
		timer1 = setInterval("scrollDivUp()",delay);
	}else if(mX>seuilL)
	{
		if(timer1)
			clearInterval(timer1);
		timer1 = setInterval("scrollDivDown()",delay);
	}else{
		if(timer1)
			clearInterval(timer1);
	}
	(ie)?event.cancelBubble=true:e.stopPropagation();
}


function scrollDivDown()
{
	var pn = document.getElementById("PanelNews");
	pn.scrollTop += 10;
	
}

function scrollDivUp()
{
	var pn = document.getElementById("PanelNews");
	pn.scrollTop -= 10;
	
}

function stopScroll(e)
{
	if(timer1)
		clearInterval(timer1);
}

function MaxDiv(IdObj)
{
	var fen = document.getElementById(IdObj);
	if(parseInt(fen.style.height) > pMiniH)
	{
		fen.style.height = pMiniH;
		fen.style.width = pMiniW;
		fen.style.top = oldTop;
		fen.style.left = oldLeft;
		fen.style.zIndex = 1;
	}else{	
		oldTop = fen.style.top;
		oldLeft = fen.style.left;
		fen.style.top = orgTop;
		fen.style.left = orgLeft;
		fen.style.width = pMiniW*2;
		fen.style.height = pMiniH*2;
		fen.style.zIndex = 2;
	}
}

function maskPanel()
{
	var cImg = document.getElementById("ctrlPanel");
	var content = document.getElementById("contentMaire");
	if(content.style.display == "block")
	{
		cImg.src = "../images/picto/ico_plus.gif"
		content.style.display = "none";
	}else{
		cImg.src = "../images/picto/ico_moins.gif"
		content.style.display = "block";
	}
	var pMaire = document.getElementById("PanelMaire");
	var pNews = document.getElementById("PanelNews");
	var pmini = document.getElementById("PanelMiniatures").offsetHeight;
	pNews.style.height = pmini - pMaire.offsetHeight;
}

function ResizeParent(obj)
{
	var oParent = obj.parentNode;
	var hText = oParent.childNodes[1].offsetHeight + oParent.childNodes[2].offsetHeight;
	oParent.style.height = (obj.height<hText)?hText:obj.height;	
}

//envoie les informations a afficher dans le fil d'ariane
function TextForFilAriane(myText)
{
	top.frames[indexFrame].document.getElementById("filSousMenu").value = myText;
}