var clicPanneau = false;
var clicPhotos = false;
var clicRequete = false;
var clicRecherche = false;

chargeAccueil = function(type) {
	$('bandeau').appear({duration:1}); 
	$('portailsig').appear({duration:3}); 
	$('contenu').appear({duration:3}); 
	if (type == "accueil") new Effect.Move($('contenuCentral'), { x:0, y:-100, duration:3});
	else if (type != "recherche") new Effect.Move($('contenuCentralVide'), { x:0, y:-100, duration:3});
	return false;

}

recherche = function(texte) {
	window.location = "recherche.php?id="+texte;
}

photo = function(texte) {
	$('photo_ajax').hide();
	new Ajax.Updater('photo_ajax',	'photocontenu.ajax.php', { onSuccess: function() { new Effect.Appear('photo_ajax', {duration:4}); }, method: 'get', parameters: {id: texte} });
	
}

archive = function(texte) {
	$('archive_ajax').hide();
	new Ajax.Updater('archive_ajax',	'archivecontenu.ajax.php', { onSuccess: function() { new Effect.Appear('archive_ajax', {duration:4}); }, method: 'get', parameters: {id: texte} });
	
}

function prechargimg() {
	var doc=document;
	if(doc.images){ 
		if(!doc.precharg) doc.precharg=new Array();
		var i,j=doc.precharg.length,x=prechargimg.arguments; for(i=0; i<x.length; i++)
		if (x[i].indexOf("#")!=0){ 
			doc.precharg[j]=new Image; 
			doc.precharg[j++].src=x[i];
		}
	}
}

var effect = 1;
var time = 3000;

var current_image = 0;
var next_image = 1;
var image = new Array();

function init() {
	if(document.getElementsByClassName("image")) {
		image = document.getElementsByClassName("image");
		for(i=1; i < image.length; i++) {
			image[i].style.display = "none";
		}
	}
	
	if(image.length > 1) galerie();
}

function galerie() {
	self.setTimeout("nextimage()",time);	
}

function nextimage() {
	if(effect == 1) { new Effect.Fade(image[current_image], {duration:2}); new Effect.Appear(image[next_image], {duration:2}); }
	if(effect == 2) { new Effect.BlindUp(image[current_image]); new Effect.BlindDown(image[next_image]); }
	
	if(next_image == (image.length-1)) {
		current_image = next_image;
		next_image = 0;
	} else {
		current_image = next_image;
		next_image++;
	}
	galerie();
}

gerePanneau = function() {
	if (!clicPanneau) reduitPanneau();
	else granditPanneau();
}

reduitPanneau = function() {
	$('panneau').fade({duration:0.6});
	$('panneau').morph('width:144px;height:46px;',{duration:1.5});
	$('photopanneau').morph('width:144px;height:46px;',{duration:1.5});
	$('photopanneau').style.background = 'url(img/src/fondpanneau.png) no-repeat left center';
	$('reduitgranditpanneau').fade();
	//$('fermePanneau').fade();
	$('granditpanneau').show();
	new Effect.Move($('photopanneau'), { x: 10, y: 240, mode:'absolute' })
	clicPanneau = true;
}

granditPanneau = function() {
	if (clicRequete) new Effect.Move($('requete'), { x:10, y:540, mode:'absolute' })
	if (clicPhotos) new Effect.Move($('galerie'), { x:10, y:640, mode:'absolute' })
	$('photopanneau').morph('width:320px;height:245px;',{duration:1.5});
	$('photopanneau').style.background = 'url(img/src/fondpanneau2.png) no-repeat center';
	$('panneau').appear({duration:1});
	$('panneau').morph('width:300px;height:225px;',{duration:1.5});
	$('reduitgranditpanneau').appear();
	//$('fermePanneau').appear();
	$('granditpanneau').hide();
	clicPanneau = false;
}

fermePanneau = function() {
	$('photopanneau').fade({duration:1});
}

gerePhotos = function() {
	if (!clicPhotos) reduitPhotos();
	else granditPhotos();
}

reduitPhotos = function() {
	$('photosgalerie').fade({duration:0.1});
	$('galerie').morph("width:144px;height:46px;border:0px;",{duration:1.5});
	$('galerie').style.background = 'url(img/src/fondphotos.png) no-repeat left center';
	$('reduitgranditphotos').fade();
	//$('fermePhotos').fade();
	$('granditphotos').show();
	new Effect.Move($('galerie'), { x: 10, y: 440, mode:'absolute' })
	clicPhotos = true;
}

granditPhotos = function() {
	$('photosgalerie').appear({duration:5});
	$('galerie').morph("width:244px;height:85px;border:1px solid black;",{duration:1.5});
	$('galerie').style.background = 'url(img/src/fondphotos2.png) no-repeat center';
	$('reduitgranditphotos').appear();
	//$('fermePhotos').appear();
	$('granditphotos').hide();
	clicPhotos = false;
}

fermePhotos = function() {
	$('galerie').fade({duration:1});
}

gereRequete = function() {
	if (!clicRequete) reduitRequete();
	else granditRequete();
}

reduitRequete = function() {
	$('tableauCommune').fade({duration:0.6});
	//$('tableauCommune').morph('width:144px;height:46px;',{duration:1.5});
	$('requete').morph('width:144px;height:46px;padding:0px',{duration:1.5});
	$('requete').style.background = 'url(img/src/fondrequete.png) no-repeat left center';
	$('reduitgranditrequete').fade();
	//$('fermeRequete').fade();
	$('granditrequete').show();
	var w = window.innerWidth  ? window.innerWidth  : document.body.clientWidth; 
	var h = window.innerHeight ? window.innerHeight : document.body.clientHeight; 
	new Effect.Move($('requete'), { x:10, y:340, mode:'absolute' })
	clicRequete = true;
}

granditRequete = function() {
	$('requete').morph('width:310px;height:274px;padding:10px',{duration:1.5});
	$('requete').style.background = 'url(img/src/fondrequete2.png) no-repeat center';
	$('tableauCommune').appear({duration:2.5});
	$('granditrequete').hide();
	$('reduitgranditrequete').appear();
	//$('fermeRequete').appear();
	clicRequete = false;
}

fermeRequete = function() {
	$('requete').fade({duration:1});
}

gereRecherche = function() {
	if (!clicRecherche) reduitRecherche();
	else granditRecherche();
}

reduitRecherche = function() {
	$('rechinput').fade({duration:0.1});
	$('cartorecherche').morph("width:144px;height:46px;border:0px;",{duration:1.5});
	$('cartorecherche').style.background = 'url(img/src/fondrecherche.png) no-repeat left center';
	$('reduitgranditrecherche').fade();
	//$('fermeRecherche').fade();
	$('granditrecherche').show();
	new Effect.Move($('cartorecherche'), { x: 10, y: 140, mode:'absolute' })
	clicRecherche = true;
}

granditRecherche = function() {
	$('rechinput').appear({duration:5});
	$('cartorecherche').morph("width:244px;height:85px;border:1px solid black;",{duration:1.5});
	$('cartorecherche').style.background = 'url(img/src/fondphotos2.png) no-repeat center';
	$('reduitgranditrecherche').appear();
	//$('fermeRecherche').appear();
	$('granditrecherche').hide();
	clicRecherche = false;
}

fermeRecherche = function() {
	$('cartorecherche').fade({duration:1});
}

//-------------------------Fonction d'apparition Département---------------------
var clicidentite = true;
var cliccuriosite = true;
var clicclimat = true;
var clichistoire = true;
var clicgeo = true;


listeRealisations = function(monElement, monclic) {
	if (!monclic) {
		monElement.appear();
		return true;
	}
	else {
		monElement.fade();
		return false;
	}
}

//-------------------------Fonction d'apparition des flêches dérouler/enrouler les blocs ---------------------
affichereduitbloc = function(monclic) {	
	if (!monclic) overlib("<img src='img/src/deroule.png' />", WIDTH, 32, HEIGHT, 32, BACKGROUND,'none');
	else overlib("<img src='img/src/enroule.png' />", WIDTH, 32, HEIGHT, 32, BACKGROUND,'none');
}
