// JavaScript Document

var zoneBig = 0;

// on récupère la valeur de la hauteur de la fenêtre
function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
			return windowHeight;
		}

function agrandirZone() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	if (!document.getElementById("content")) return false;
	if (!document.getElementById("fondContentTop")) return false;
	if (!document.getElementById("bordureContent")) return false;
	if (!document.getElementById("fondContentBottom")) return false;
	var contentHeight = document.getElementById('content');
	var fondContentTopHeight = document.getElementById('fondContentTop');
	var bordureContentHeight = document.getElementById('bordureContent');
	var fondContentBottomHeight = document.getElementById('fondContentBottom');
	
	var windowHeight = getWindowHeight();
	
	contentHeight.style.height = (windowHeight - 54) + 'px';
	bordureContentHeight.style.height = (windowHeight - 86) + 'px';
	fondContentBottomHeight.style.height = (windowHeight - 46) + 'px';
	
	contentHeight.style.top = 34 + 'px';
	fondContentTopHeight.style.top = 4 + 'px';
	bordureContentHeight.style.top = 44 + 'px';
	fondContentBottomHeight.style.top = 44 + 'px';

	zoneBig = 1;
	
	// set the cookie
	SetCookie("tailleZone",zoneBig,"December,31,2029");
	
	// désaffiche le div video
	document.getElementById('video').style.visibility="hidden";
	
	// cache/affiche les boutons
	document.images["ImgAgrandirReduireZone"].src="/img/picto-zoom/picto-zoom-reduire.gif";
	document.images["ImgAgrandirReduireZone"].alt="Réduire la zone";
	document.images["ImgAgrandirReduireZone"].title="Réduire la zone";
}

function reduireZone() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	if (!document.getElementById("header")) return false;
	if (!document.getElementById("content")) return false;
	if (!document.getElementById("fondContentTop")) return false;
	if (!document.getElementById("bordureContent")) return false;
	if (!document.getElementById("fondContentBottom")) return false;
	if (!document.getElementById("fondMenu")) return false;
	if (!document.getElementById("theme")) return false;
	var headerHeight = document.getElementById('header').offsetHeight;
	var contentHeight = document.getElementById('content');
	var fondContentTopHeight = document.getElementById('fondContentTop');
	var bordureContentHeight = document.getElementById('bordureContent');
	var fondContentBottomHeight = document.getElementById('fondContentBottom');
	var fondMenuHeight = document.getElementById('fondMenu');
	var themeHeight = document.getElementById('theme').offsetHeight;
	
	var windowHeight = getWindowHeight();
	
	contentHeight.style.height = (windowHeight - headerHeight - 55) + 'px';
	fondContentBottomHeight.style.height = (windowHeight - headerHeight - 40) + 'px';
	bordureContentHeight.style.height = (windowHeight - headerHeight - 86) + 'px';
	fondMenuHeight.style.height = themeHeight + 'px';
	
	contentHeight.style.top = 420 + 'px';
	fondContentTopHeight.style.top = 389 + 'px';
	bordureContentHeight.style.top = 429 + 'px';
	fondContentBottomHeight.style.top = 423 + 'px';
	
	zoneBig = 0;
	
	// set the cookie
	SetCookie("tailleZone",zoneBig,"December,31,2029");
	
	// réaffiche le div video
	document.getElementById('video').style.visibility="visible";
	
	// cache/affiche les boutons
	document.images["ImgAgrandirReduireZone"].src="/img/picto-zoom/picto-zoom-agrandir.gif";
	document.images["ImgAgrandirReduireZone"].alt="Agrandir la zone";
	document.images["ImgAgrandirReduireZone"].title="Agrandir la zone";
}

function SetCookie(name,value,expires)
{
	var exp = new Date(expires);
	document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); + ";path=";
}



function agrandirreduireZone()
{
	// si pas de cookie
	valeurCookietailleZone=LireCookie("tailleZone");
	if (valeurCookietailleZone==null)
	{
		if (zoneBig==1)
		{
			reduireZone();
		}
		else
		{
			agrandirZone();
		}
	}
	else
	// si cookie
	{
		valeurCookietailleZone=LireCookie("tailleZone");
		if (valeurCookietailleZone=="1")
		{
			reduireZone();
		}
		if (valeurCookietailleZone=="0")
		{
			agrandirZone();
		}
	}
}



// 2 fonctions servant à lire le cookie
function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}




// cette fonction sert à ajuster la hauteur de la zone
// on ne défini pas ici le 'top'
function setHeight() {
	
	// alert(zoneBig);
		
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	if (!document.getElementById("header")) return false;
	if (!document.getElementById("colLeft")) return false;
	if (!document.getElementById("content")) return false;
	if (!document.getElementById("fondContentBottom")) return false;
	if (!document.getElementById("bordureContent")) return false;
	if (!document.getElementById("fondMenu")) return false;
	if (!document.getElementById("theme")) return false;
		
	var windowHeight = getWindowHeight();
	
	var headerHeight = document.getElementById('header').offsetHeight;
	var colLeftHeight = document.getElementById('colLeft').offsetHeight;
	var contentHeight = document.getElementById('content');
	var fondContentBottomHeight = document.getElementById('fondContentBottom');
	var bordureContentHeight = document.getElementById('bordureContent');
	var fondMenuHeight = document.getElementById('fondMenu');
	var themeHeight = document.getElementById('theme').offsetHeight;
			
	contentHeight.style.height = (windowHeight - headerHeight - 55) + 'px';
	fondContentBottomHeight.style.height = (windowHeight - headerHeight - 40) + 'px';
	bordureContentHeight.style.height = (windowHeight - headerHeight - 86) + 'px';
	fondMenuHeight.style.height = themeHeight + 'px';
	
	contentHeight.style.overflow = "auto";
	document.getElementById('content').style.height="100%";

	if (zoneBig == 1) {
		agrandirZone();
	} else {
		reduireZone();
	}

}

//function ajusterZone() {
//	if (!document.getElementById) return false;
//	if (!document.getElementsByTagName) return false;
//	
//	if (!document.getElementById("content")) return false;
//	if (!document.getElementById("fondContentTop")) return false;
//	if (!document.getElementById("bordureContent")) return false;
//	if (!document.getElementById("fondContentBottom")) return false;
//	var contentHeight = document.getElementById('content');
//	var fondContentTopTop = document.getElementById('fondContentTop').offsetTop;
//	// on a besoin de connaître la valeur 'top' de 'fondContentTop'
//	var bordureContentHeight = document.getElementById('bordureContent');
//	var fondContentBottomHeight = document.getElementById('fondContentBottom');
//	
//	var windowHeight = getWindowHeight();
//	
//	alert('hello'+fondContentTopTop);
//	
//	fondContentBottomHeight.style.height = (windowHeight - fondContentTopTop - 300) + 'px';
//	contentHeight.style.height = (windowHeight - fondContentTopTop - 55) + 'px';
//	fondContentBottomHeight.style.height = (windowHeight - fondContentTopTop - 36) + 'px';
//	bordureContentHeight.style.height = (windowHeight - fondContentTopTop - 100) + 'px';
//}

function ajusterZone2() {
	if (!document.getElementById) return false;
	if (!document.getElementsByTagName) return false;
	
	if (!document.getElementById("fondContentTop")) return false;
	var fondContentTopTop = document.getElementById('fondContentTop').offsetTop;
	
	if (fondContentTopTop >= 389) {
		reduireZone();
	} else {
		agrandirZone();
	}
}

//window.onload = function() {
//	setHeight();
//	alert('oksetHeight');
//}
//
//window.onresize = function() {
//	setHeight();
//	alert('okonresize');
//}
