var backcolor = "#32508D";
var contentcolor = "#2B426B";
var w = screen.availWidth;
var h = screen.availHeight;
var current;
var curxpos;
var curypos;
var height;
var width;
var exists;
var allStretch;
var i=0;
var j=0;
var tmp=0;
var sup=0;
var tmparray = new Array();
var lefttmparray = new Array();
var righttmparray = new Array();
var txtlength;
var leftlength;
var rightlength;
var suplength;
var interval;
var leftinterval;
var rightinterval;
var supinterval
var strdiv;
var strleftdiv;
var strrightdiv;
var strsupdiv;

window.onload=function() {
	if (self != top)
		top.location.href = self.location.href;
	var menuw = Element.getDimensions('menucontainer').width;
	var leftspace1 = menuw + (((w - menuw - 10) - 500) / 2);
	var leftspace2 = menuw + (((w - menuw - 10) - 740) / 2);
	document.getElementById("d2i").style.left = leftspace1 + "px";
	document.getElementById("container").style.left = leftspace2 + "px";
	new Effect.Appear('d2i', {duration: 2.0});
	//new Effect.Appear('news', {duration: 2.0});
	if(!NiftyCheck())
		return;
	Rounded("div#menucontainer","all",backcolor,"transparent", "smooth");
	//Rounded("div#news","all",backcolor,"transparent", "smooth");
	Rounded("div#d2i","all",backcolor,"transparent","smooth");
	Rounded("div#welcome","tl tr",backcolor,"transparent","border #FFFFFF");

	if (document.images) {
		image1 = new Image();
		image1.src = "images/bouton-off.gif";
		image2 = new Image();
		image2.src = "images/bouton-on.gif";
		image3 = new Image();
		image3.src = "images/bouton-small-off.gif";
		image4 = new Image();
		image4.src = "images/bouton-small-on.gif";
	}
}

window.onscroll=function(){
	document.getElementById('footer').style.display = 'none';
}

window.onresize=function(){
	if (document.body.scrollHeight > 600)
		document.getElementById('footer').style.display = 'block';
}

function validate() {
	var nom=contactform.nom.value;
	var prenom=contactform.prenom.value;
	var email=contactform.email.value;
	var message=contactform.message.value;
	if (nom == '') {
		alert('Veuillez renseigner votre nom.');
		contactform.nom.focus();
		return false;
	}
	if (prenom == '') {
		alert('Veuillez renseigner votre prénom.');
		contactform.prenom.focus();
		return false;
	}
	if (email == '') {
		alert('Veuillez renseigner votre email.');
		contactform.email.focus();
		return false;
	}
	else {
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email) != 1) {
			alert('Votre email est incorrect.');
			contactform.email.focus();
			return false;
		}
	}
	if (message == '') {
		alert('Veuillez renseigner votre message.');
		contactform.message.focus();
		return false;
	}
	else {
		//alert('Merci, envoi en cours ...');
		//contactform.nom.value = '';
		//contactform.prenom.value = '';
		//contactform.email.value = '';
		//contactform.societe.value = '';
		//contactform.message.value = '';
		return true;
	}
}

function display(left,top) {
	clearallintervals();
	Rounded("div#content","all",backcolor,"transparent","smooth");
	Rounded("div#intro","all",contentcolor,"transparent", "smooth");
	Rounded("div#icon","all",contentcolor,"transparent","smooth");
	Rounded("div#submenu","all",contentcolor,"transparent","small border");
	Rounded("div#div1","all",contentcolor,"transparent","smooth");
	Rounded("div#div2","all",contentcolor,"transparent","smooth");
	Rounded("div#div3","all",contentcolor,"transparent","smooth");
	Rounded("div#div4","all",contentcolor,"transparent","smooth");
	Effect.Combo('intro', 'icon', {scaleX: true}, left, top);
	document.getElementById("content").style.display = "block";
	new Effect.BlindDown('submenu', {});
}

Effect.OpenUp = function(element) {
	element = $(element);
	new Effect.BlindDown(element, arguments[1] || {});
}

Effect.CloseDown = function(element) {
	element = $(element);
	new Effect.Fade(element, arguments[1] || {});
}

Effect.Combo = function(element, icon, argv, xpos, ypos) {
	element = $(element);
	icon = $(icon);
	if(element.style.display == 'none') {
		//new Effect.OpenUp(element, arguments[1] || {});
		new Effect.Move(element, {x:$(xpos), y:$(ypos), mode: 'absolute', duration:1.5});
		new Effect.Appear(element, {});
		new Effect.Grow(icon, {duration:1.5, direction: 'center', opacityTransition:Effect.Transitions.linear});
		//new Effect.Grow(icon, {});
	}
	else { 
		new Effect.CloseDown(element, arguments[1] || {}); 
		new Effect.Move(current, {x:findPosX(link), y:findPosY(link), mode: 'absolute'});
		new Effect.DropOut(icon, {});
	}
}

function show(page) {
	new Ajax.Updater('container',page,{asynchronous:true, evalScripts:true});
	document.getElementById("d2i").style.display = "none";
}

function init() {
	var divs = document.getElementsByClassName("stretcher");
	allStretch = new fx.MultiFadeSize(divs, {duration: 400});
	items = document.getElementsByClassName("display");
	for (i = 0; i < items.length; i++){
		var h3 = items[i];
		div = h3.nextSibling;
		h3.title = h3.className.replace("display ", "");
		if (window.location.href.indexOf(h3.title) < 0) {
			allStretch.hide(div, 'height');
			if (exists != true) exists = false;
		}
		else exists = true;
		h3.onclick = function(){
			allStretch.showThisHideOpen(this.nextSibling, 100, 'height');
		}
	}
	if (exists == false) $('menu').childNodes[1].fs.toggle('height');
	//Si handle en place : if (exists == false) $('menu').childNodes[2].fs.toggle('height');
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function updateDiv(previous,next) {
	previous = $(previous);
	next = $(next);
	previous.innerHTML = next.innerHTML;
}

function hideDiv(element) {
	element = $(element);
	document.getElementById("+element+").style.display = "none";
}

function clearallintervals() {
	clearInterval(interval);
	clearInterval(leftinterval);
	clearInterval(rightinterval);
	clearInterval(supinterval);
}

function animate(txtarray, leftarray, rightarray) {
	i=j=tmp=0;
	tmparray = txtarray;
	lefttmparray = leftarray;
	righttmparray = rightarray;
	strdiv=document.getElementById("txtscroller")
	strleftdiv=document.getElementById("leftimg")
	strrightdiv=document.getElementById("rightimg")
	strdiv.innerHTML = tmparray[0];
	strleftdiv.innerHTML='<img border="0" src="images/'+lefttmparray[0]+'" alt="">';
	strrightdiv.innerHTML='<img border="0" src="images/'+righttmparray[0]+'" alt="">';
	tmp++;
	j++;
	txtlength = txtarray.length;
	leftlength = leftarray.length;
	rightlength = rightarray.length;
	interval = setInterval("showMsg()", 3500);
	leftinterval = setInterval("switchimgleft()", 6000);
	rightinterval = setInterval("switchimgright()", 6000);
	new Effect.Appear('txtscroller', {});
}

function showMsg() {
	if (strdiv.innerHTML != '') {
		if (i >= txtlength)
			i=0;
		strdiv.innerHTML = tmparray[i];
		Effect.Scroll('txtscroller', 0, 15);
		i++;
	}
}

Effect.Scroll = function(element, xpos, ypos) {
	element = $(element);
	element.style.top = "0px";
	new Effect.Appear(element, {duration:2.0,
		afterFinish:function(){
			new Effect.Move(element, {x:$(xpos), y:$(ypos), mode: 'absolute', duration:1.0});
			new Effect.Fade(element, {});
		}
	});
}

function switchimgleft() {
	if (j >= leftlength)
		j=0;
	new Effect.Fade('leftimg', {duration:2.0,
		afterFinish:function(){
			updateleftimg();
		}
	});
}

function updateleftimg() {
	if (strleftdiv.innerHTML != '') {
		var leftimgstr = "images/"+lefttmparray[j];
		strleftdiv.innerHTML = '<img border="0" src='+leftimgstr+' alt="">';
		new Effect.Appear('leftimg', {});
		j++;
	}
}

function switchimgright() {
	if (tmp >= rightlength)
		tmp=0;
	new Effect.Fade('rightimg', {duration:2.0,
		afterFinish:function(){
			updaterightimg();
		}
	});
}

function updaterightimg() {
	if (strrightdiv.innerHTML != '') {
		var rightimgstr = "images/"+righttmparray[tmp];
		strrightdiv.innerHTML = '<img border="0" src='+rightimgstr+' alt="">';
		new Effect.Appear('rightimg', {});
		tmp++;
	}
}

function showsupervision() {
	strsupdiv=document.getElementById("supervision")
	strsupdiv.innerHTML = '<img border="0" src='+"images/"+supervisionarray[0]+' alt="">';
	new Effect.Appear('supervision', {});
	sup=1;
	clearInterval(supinterval);
	suplength = supervisionarray.length;
	supinterval = setInterval("switchsupervision()", 7000);
}

function switchsupervision() {
	if (sup >= suplength)
		sup=0;
	new Effect.Fade('supervision', {duration:2.0,
		afterFinish:function(){
			updatesupervision();
		}
	});
}

function updatesupervision() {
	if (strsupdiv.innerHTML != '') {
		var supimgstr = "images/"+supervisionarray[sup];
		strsupdiv.innerHTML = '<img border="0" src='+supimgstr+' alt="">';
		new Effect.Appear('supervision', {});
		sup++;
	}
}
