Event.observe(window, 'load', function() {
new Effect.Appear('div_main', 1);
new Effect.Appear('footer',1);
new PeriodicalExecuter(function() {changeEntete('left')}, 4);
new PeriodicalExecuter(function() {changeEntete('center')}, 5);
new PeriodicalExecuter(function() {changeEntete('right')}, 6);
sous_menu();
if ((document.forms['testform2'].elements['formul2'].value == 'formulaire') && (document.forms['testform2'].elements['val2'].value != 'val2'))
{
	maj_container('livre_dor');	
}
else
{
	if ((document.forms['testform'].elements['formul'].value == 'formulaire') && (document.forms['testform'].elements['val'].value != 'val'))
	{
		maj_container('contact');
	}
	else
	{
		maj_container('accueil');
	}
}
});

function getXhr()
	{
     	var xhr = null; 
		if(window.XMLHttpRequest) // Firefox et autres
			xhr = new XMLHttpRequest(); 
		else if(window.ActiveXObject) // Internet Explorer
			{  
				try 
					{
			     		xhr = new ActiveXObject("Msxml2.XMLHTTP");
			    	} 
				catch (e) 
					{
			        	xhr = new ActiveXObject("Microsoft.XMLHTTP");
			    	}
			}
		else // XMLHttpRequest non supporté par le navigateur 
			{ 
				alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
				xhr = false; 
			} 
        return xhr;
	}

function preview()
	{
				var xhr = getXhr();
				// On défini ce qu'on va faire quand on aura la réponse
				xhr.onreadystatechange = function(){
					// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
					if(xhr.readyState == 4 && xhr.status == 200){
						leselect = xhr.responseText;
						// On se sert de innerHTML pour rajouter les options a la liste
						document.getElementById('lect').innerHTML = leselect;
										}
				}

				// Ici on va voir comment faire du post
				xhr.open("POST","livre.php",true);
				// ne pas oublier ça pour le post
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				// ne pas oublier de poster les arguments
				// ici, l'id de l'auteur
				var div=document.getElementById('num');
				if(div){ 
					idmessage = document.getElementById('num').value; 
					} 
				else{ 
				idmessage = -1;
					}
				 
				xhr.send("idmessage="+idmessage);
				
			}

function suivant(){
				var xhr = getXhr();
				// On défini ce qu'on va faire quand on aura la réponse
				xhr.onreadystatechange = function(){
					// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
					if(xhr.readyState == 4 && xhr.status == 200){
						leselect = xhr.responseText;
						// On se sert de innerHTML pour rajouter les options a la liste
						document.getElementById('lect').innerHTML = leselect;
						
					}
				}

				// Ici on va voir comment faire du post
				xhr.open("POST","livre.php",true);
				// ne pas oublier ça pour le post
				xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				// ne pas oublier de poster les arguments
				// ici, l'id de l'auteur
				var div=document.getElementById('num_pre');
				if(div){ 
					idmessage_pre =document.getElementById('num_pre').value; 
				} 
				else{ 
				idmessage_pre = 1;
					}
				 
				
				xhr.send("idmessage_pre="+idmessage_pre);
			}

function smiley(smile) {
	smile = " "+smile+" ";

	var compgen = navigator.userAgent.toLowerCase();
	var navsafari = ((compgen.indexOf('safari') != -1) || (navigator.vfinor == "Apple"));
	var navie = ((compgen.indexOf('msie') != -1) && (!navopera) && (!navsafari) && (!navwebtv));
	var navopera = (compgen.indexOf('opera') != -1);
	var navwebtv = (compgen.indexOf('webtv') != -1);
	var oswin =  ((compgen.indexOf("win") != -1) || (compgen.indexOf("16bit") != -1));
	var navers = parseInt(navigator.appVersion);
	var chem = document.getElementById('message');
	var fermer = false;

	if ((navers >= 4) && navie && oswin) {
		if (chem.isTextEdit) {
			chem.focus();
			var dselect = document.selection;
			var cr = dselect.createRange(); cr.colapse;
			if ((dselect.type == "Text" || dselect.type == "None") && cr != null) {
				fermer = true;
				cr.text = smile;
			}
		}
		else { fermer = true; chem.value += smile; }
	}
	else {
		if (chem.selectionEnd) {
			var selectdebut = chem.selectionStart;
			var selecthaut = chem.scrollTop;
			var selectfin = chem.selectionEnd;
			if (selectfin <= 2) { selectfin = chem.textLength; }
			var debut  = (chem.value).substring(0, selectdebut);
			var milieu = (chem.value).substring(selectdebut, selectfin);
			var fin    = (chem.value).substring(selectfin, chem.textLength);
			if (chem.selectionEnd - chem.selectionStart > 0){ milieu = smile + milieu; } else { milieu = smile + milieu; fermer = true; }
			chem.value = debut + milieu + fin;
			var cpos = selectdebut + (milieu.length);
			chem.selectionStart = cpos;
			chem.selectionEnd = cpos;
			chem.scrollTop = selecthaut;
		}
		else {
			fermer = true;
			chem.value += smile;
		}

		chem.focus(); return fermer;
	}
}
			
var id_lanterne = 'menu_accueil';
var z=0;
var zz=0;

function sous_menu (){
	$('menu_accueil').setOpacity(0.0);
	$('menu_notre_hotel').setOpacity(0.0);
	$('menu_tarif').setOpacity(0.0);
	$('menu_situation').setOpacity(0.0);
	$('menu_contact').setOpacity(0.0);
	$('menu_alentour').setOpacity(0.0);
	$('menu_livre_dor').setOpacity(0.0);
}

function menu(id){
$(id_lanterne).setOpacity(0.0);
$('menu_' + id).setStyle({zIndex:(++z)});
id_lanterne = 'menu_'+id;
$(id_lanterne).setOpacity(1.0);
$('menu_' + id).setStyle({zIndex:(++z)});
}

function maj_container(id){
if (id=='legal'){sous_menu();}
else {menu(id);}
document.getElementById('info').style.display="none";
var oldHTML = document.getElementById(id).innerHTML;
var newHTML = oldHTML;
document.getElementById('info').innerHTML = newHTML;
new Effect.Appear('info');
if (id=='livre_dor'){preview();}
}

function big_img(id) {
	$(id).setStyle({zIndex:(++zz)});
	switch (id)
	{	
		case 'morph1' :
			new Effect.Morph(id, {style:'position absolute; margin-left:150px; margin-top:-150px; width:360px; height:540px;', duration: 0.8} )
			break
		case 'morph2' :
			new Effect.Morph(id, {style:'position absolute; margin-left:150px; margin-top:-350px; width:360px; height:540px;', duration: 0.8} )
			break
		case 'morph3' :
			new Effect.Morph(id, {style:'position absolute; margin-left:0px; margin-top:0px; width:370px; height:246px;', duration: 0.8} )
			break
		case 'morph4' :
			new Effect.Morph(id, {style:'position absolute; margin-left:70px; margin-top:0px; width:370px; height:246px;', duration: 0.8} )
			break
		case 'morph5' :
			new Effect.Morph(id, {style:'position absolute; margin-left:140px; margin-top:0px; width:370px; height:246px;', duration: 0.8} )
			break
		case 'morph6' :
			new Effect.Morph(id, {style:'position absolute; margin-left:310px; margin-top:0px; width:200px; height:300px;', duration: 0.8} )
			break
		case 'morph7' :
			new Effect.Morph(id, {style:'position absolute; margin-left:0px; margin-top:0px; width:370px; height:246px;', duration: 0.8} )
			break
		case 'morph8' :
			new Effect.Morph(id, {style:'position absolute; margin-left:70px; margin-top:0px; width:370px; height:246px;', duration: 0.8} )
			break
		case 'morph9' :
			new Effect.Morph(id, {style:'position absolute; margin-left:140px; margin-top:0px; width:370px; height:246px;', duration: 0.8} )
			break
		case 'morph10' :
			new Effect.Morph(id, {style:'position absolute; margin-left:310px; margin-top:0px; width:200px; height:300px;', duration: 0.8} )
			break
		case 'morph11' :
			new Effect.Morph(id, {style:'position absolute; margin-left:0px; margin-top:0px; width:502px; height:330px;', duration: 0.8} )
			break
		case 'morph12' :
			new Effect.Morph(id, {style:'position absolute; margin-left:-195px; margin-top:-70px; width:401px; height:264px;', duration: 0.8} )
			break
	}
}

function small_img(id) {
	switch (id)
	{	
		case 'morph1' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:410px; margin-top:0px; width:100px; height:150px;', duration: 0.8} )
			break
		case 'morph2' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:410px; margin-top:0px; width:100px; height:150px;', duration: 0.8} )
			break
		case 'morph3' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:0px; margin-top:0px; width:165px; height:110px;', duration: 0.8} )
			break
		case 'morph4' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:172px; margin-top:0px; width:165px; height:110px;', duration: 0.8} )
			break
		case 'morph5' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:344px; margin-top:0px; width:165px; height:110px;', duration: 0.8} )
			break
		case 'morph6' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:410px; margin-top:119px; width:100px; height:150px;', duration: 0.8} )
			break
		case 'morph7' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:0px; margin-top:0px; width:165px; height:110px;', duration: 0.8} )
			break
		case 'morph8' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:172px; margin-top:0px; width:165px; height:110px;', duration: 0.8} )
			break
		case 'morph9' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:344px; margin-top:0px; width:165px; height:110px;', duration: 0.8} )
			break
		case 'morph10' :
			new Effect.Morph(id, {style:'position:absolute; margin-left:410px; margin-top:119px; width:100px; height:150px;', duration: 0.8} )
			break
		case 'morph11' :
			new Effect.Morph(id, {style:'position absolute; margin-left:228px; margin-top:134px; width:255px; height:166px;', duration: 0.8} )
			break
		case 'morph12' :
			new Effect.Morph(id, {style:'position absolute; margin-left:0px; margin-top:0px; width:255px; height:166px;', duration: 0.8} )
			break
	}	
}

var zidx = 0;
var left = 1;
var center = 1;
var right = 1;


function changeEntete(div)
{
	if('left' == div)
	{
		switch (left) 
		{
			case 1 :
		 		left = 2
		 		break
			case 2 :
		 		left = 3
		 		break
			case 3 :
		 		left = 1
		 		break
		}
			$('banniere_left_' + left).setOpacity(0.0)
			$('banniere_left_' + left).setStyle({zIndex:(++zidx)})
			new Effect.Opacity('banniere_left_' + left,{duration:2.0,from:0.0,to:1.0})
	}
	else if('center' == div)
	{
		switch (center) 
		{
			case 1 :
		 		center = 2
		 		break
			case 2 :
		 		center = 3
		 		break
			case 3 :
		 		center = 1
		 		break
		}
			$('banniere_center_' + center).setOpacity(0.0)
			$('banniere_center_' + center).setStyle({zIndex:(++zidx)})
			new Effect.Opacity('banniere_center_' + center,{duration:3.0,from:0.0,to:1.0})
	}
	else if('right' == div)
	{
		switch (right) 
		{
			case 1 :
		 		right = 2
		 		break
			case 2 :
		 		right = 3
		 		break
			case 3 :
		 		right = 1
		 		break
		}
			$('banniere_right_' + right).setOpacity(0.0)
			$('banniere_right_' + right).setStyle({zIndex:(++zidx)})
			new Effect.Opacity('banniere_right_' + right,{duration:4.0,from:0.0,to:1.0})
	}
};



function verif_mail(adresse){
	if (adresse.match(/^([a-z0-9_-]+(?:[.][a-z0-9_-]+)*)@((?:[a-z0-9_-]+[.])*[a-z0-9_-]{0,66})[.]([a-z]{2,6}(?:[.][a-z]{2})?)$/i))
		return true;
	else
		return false;
}



	
// Function to show alentours images

var currentAlentoursDiv;
var zalen = 0;
function showAlentours(div) {

 if(div == currentAlentoursDiv) return
 currentAlentoursDiv = div

 $('alentours_' + div).setOpacity(0.0)
 $('alentours_' + div).setStyle({zIndex:(++zalen)})
 new Effect.Opacity('alentours_' + div,{duration:0.0,from:0.0,to:1.0})
};

function maj_lect(id){
document.getElementById('lecture').style.display="none";
var oldHTML = document.getElementById(id).innerHTML;
var newHTML = oldHTML;
document.getElementById('lecture').innerHTML = newHTML;
new Effect.Appear('lecture');
}