window.addEvent('domready', function (){
		
		/////// PROFILS PAGE D'ACCUEIL
		
		var url = window.location.href;
		//1
		if (url == "http://www.ville-romans.fr/"){
			$('profils').addEvent('change',function(){ 
				var affiche = $('profils').value;
				if (affiche!=""){
					//Get Some COOKIE !
					EcrireCookie('profil',affiche);
					//On masque tous les blocs
					$$('.perso').setStyle('display','none');
					//On affiche le bon bloc
					eval("$('"+affiche+"').setStyle('display','block');");
				}
			});
		
			if (LireCookie('profil')!=null){
				var profil = LireCookie('profil');
				$$('.perso').setStyle('display','none');
				eval("$('"+profil+"').setStyle('display','block');");
				eval("$('"+profil+"list').set('selected','selected');");
			}
		}
		//2
		if (url == "http://www.ville-romans.com/"){
			$('profils').addEvent('change',function(){ 
				var affiche = $('profils').value;
				if (affiche!=""){
					//Get Some COOKIE !
					EcrireCookie('profil',affiche);
					//On masque tous les blocs
					$$('.perso').setStyle('display','none');
					//On affiche le bon bloc
					eval("$('"+affiche+"').setStyle('display','block');");
				}
			});
		
			if (LireCookie('profil')!=null){
				var profil = LireCookie('profil');
				$$('.perso').setStyle('display','none');
				eval("$('"+profil+"').setStyle('display','block');");
				eval("$('"+profil+"list').set('selected','selected');");
			}
		}
		//3
		if (url == "http://www.ville-romans.com/index.php"){
			$('profils').addEvent('change',function(){ 
				var affiche = $('profils').value;
				if (affiche!=""){
					//Get Some COOKIE !
					EcrireCookie('profil',affiche);
					//On masque tous les blocs
					$$('.perso').setStyle('display','none');
					//On affiche le bon bloc
					eval("$('"+affiche+"').setStyle('display','block');");
				}
			});
		
			if (LireCookie('profil')!=null){
				var profil = LireCookie('profil');
				$$('.perso').setStyle('display','none');
				eval("$('"+profil+"').setStyle('display','block');");
				eval("$('"+profil+"list').set('selected','selected');");
			}
		}
		//4
		if (url == "http://www.ville-romans.fr/index.php"){
			$('profils').addEvent('change',function(){ 
				var affiche = $('profils').value;
				if (affiche!=""){
					//Get Some COOKIE !
					EcrireCookie('profil',affiche);
					//On masque tous les blocs
					$$('.perso').setStyle('display','none');
					//On affiche le bon bloc
					eval("$('"+affiche+"').setStyle('display','block');");
				}
			});
		
			if (LireCookie('profil')!=null){
				var profil = LireCookie('profil');
				$$('.perso').setStyle('display','none');
				eval("$('"+profil+"').setStyle('display','block');");
				eval("$('"+profil+"list').set('selected','selected');");
			}
		}
		//5
		if (url == "http://ville-romans.fr/"){
			$('profils').addEvent('change',function(){ 
				var affiche = $('profils').value;
				if (affiche!=""){
					//Get Some COOKIE !
					EcrireCookie('profil',affiche);
					//On masque tous les blocs
					$$('.perso').setStyle('display','none');
					//On affiche le bon bloc
					eval("$('"+affiche+"').setStyle('display','block');");
				}
			});
		
			if (LireCookie('profil')!=null){
				var profil = LireCookie('profil');
				$$('.perso').setStyle('display','none');
				eval("$('"+profil+"').setStyle('display','block');");
				eval("$('"+profil+"list').set('selected','selected');");
			}
		}
		//6
		if (url == "http://ville-romans.com/"){
			$('profils').addEvent('change',function(){ 
				var affiche = $('profils').value;
				if (affiche!=""){
					//Get Some COOKIE !
					EcrireCookie('profil',affiche);
					//On masque tous les blocs
					$$('.perso').setStyle('display','none');
					//On affiche le bon bloc
					eval("$('"+affiche+"').setStyle('display','block');");
				}
			});
		
			if (LireCookie('profil')!=null){
				var profil = LireCookie('profil');
				$$('.perso').setStyle('display','none');
				eval("$('"+profil+"').setStyle('display','block');");
				eval("$('"+profil+"list').set('selected','selected');");
			}
		}
		$('fondgfx').set('tween', {duration: '300'});
		
		/////////// MOUVEAU MENU
		$$('.lidemarches').addEvent('mouseenter',function(){ 
			this.set('class','mesdemarcheshover');
		});
		
		$$('.lidemarches').addEvent('mouseleave',function(){ 
			this.set('class','lidemarches');
		});
		
		$$('.liquotidien').addEvent('mouseenter',function(){ 
			this.set('class','monquotidienhover');
		});
		
		$$('.liquotidien').addEvent('mouseleave',function(){ 
			this.set('class','liquotidien');
		});
		
		$$('.liparticipe').addEvent('mouseenter',function(){ 
			this.set('class','jeparticipehover');
		});
		
		$$('.liparticipe').addEvent('mouseleave',function(){ 
			this.set('class','liparticipe');
		});
		
		$$('.liminforme').addEvent('mouseenter',function(){ 
			this.set('class','jeminformehover');
		});
		
		$$('.liminforme').addEvent('mouseleave',function(){ 
			this.set('class','liminforme');
		});
		
		$('menu').addEvent('mouseenter',function(){
			if (Browser.Engine.trident && (Browser.Engine.version==4)){
			}else{
				var opaciteFx = $('fondgfx').getStyle('opacity');
				if (opaciteFx>0){
					$('fondgfx').set('tween',{duration: 200});
					$('fondgfx').tween('opacity', '0.4');
				}
				
			}
		});
		
		
		$('menu').addEvent('mouseleave',function(){
			if (Browser.Engine.trident && (Browser.Engine.version==4)){
			}else{
				$('fondgfx').set('tween',{duration: 200});
				$('fondgfx').tween('opacity', '1');
			}
		});
		
		$$('.menuhaut li').addEvent('mouseenter',function(){
			var nextSibling = this.getChildren('ul');
			if (nextSibling!=""){
				nextSibling.setStyle('display','block');
			}
		});
		
		
		$$('.menuhaut li').addEvent('mouseleave',function(){
			var nextSibling = this.getChildren('ul');
			if (nextSibling!=""){
				nextSibling.setStyle('display','none');
			}
		});
		
		
		
		/*
		$$('#mesdemarches').addEvent('mouseenter',function(){
			var nextSibling = this.getChildren('ul');
			if (nextSibling!=""){
				nextSibling.setStyle('display','block');
			}
		});
		
		$$('#mesdemarches ul').addEvent('mouseleave',function(){
			
				this.setStyle('display','none');
			
		});
		
		$$('#mesdemarches ul a').addEvent('mouseenter',function(){ 
			$$('#mesdemarches ul').setStyle('display','block');
		});
		
		
		$$('#mesdemarches ul a').addEvent('mouseleave',function(){ 
			var nextSibling = $$('#mesdemarches').getChildren('ul');
			if (nextSibling!=""){
				nextSibling.setStyle('display','block');
			}
		});*/
		
		
		
		/*		
		/*******************************************************************************
		*
		*                         	      FOOTER
		*
		*******************************************************************************/

		$('closefooter').addEvent('click',function(){
			var hauteur = $('footer').getStyle('height');
			//var ouvert = Cookie.read("ouvert");
			if (hauteur=="500px"){
				
				/*var formProfile = document.getElementById('formProfile');
				if (formProfile!=null){
					formProfile.style.display = "block";
				}*/
				/* On cache tous les inputs */
				$$('input').each(function(form) {
				    form.setStyle('opacity','1');
				});
				$$('textarea').each(function(form) {
				    form.setStyle('opacity','1');
				});
				$$('select').each(function(form) {
				    form.setStyle('opacity','1');
				});
								
				var footer = new Fx.Morph('footer', {duration:500, transition: Fx.Transitions.Back.easeOut});
				footer.start({
					'height':55
				});
				$('closefooter').set('class','open');
			}else{
			
				/* On cache tous les inputs */
				$$('input').each(function(form) {
				    form.setStyle('opacity','0');
				});
				$$('textarea').each(function(form) {
				    form.setStyle('opacity','0');
				});
				$$('select').each(function(form) {
				    form.setStyle('opacity','0');
				});
				
				var formProfile = document.getElementById('footsearch');
				formProfile.setStyle('opacity','1');
				
				var rechercheHaut = document.getElementById('topsearch');
				rechercheHaut.setStyle('opacity','1');
				
				/*alert("test");*/
				
				/*
				var formProfile = document.getElementById('formProfile');
				if (formProfile!=null){
					formProfile.style.display = "none";
				}*/
				
				/*var myCookie  = Cookie.write("ouvert","oui");*/
				var footer = new Fx.Morph('footer', {duration:500, transition: Fx.Transitions.Back.easeOut});
				footer.start({
					'height':500
				});
				$('closefooter').set('class','close');
			}
		});
		/********************************************************************************
		*
		*				    TELEX POWA !
		*
		********************************************************************************/		
		function go(){
			setTimeout(function(){
				$('telex').set('tween',{duration: 1500});
				$('telex').tween('opacity', '1');
				//$('telex').tween('color', '#000000');
				go2();
			},1500);
		}
		
		function go2(){
			setTimeout(function(){
				$('telex').set('tween',{duration: 1500});
				$('telex').tween('opacity', '0.3');
				//$('telex').tween('color', '#CF0688');
				go();
			},1500);
		}
		
		var url = window.location.href;
		if (url == "http://www.ville-romans.fr/index.php"){
			
			setTimeout(function(){
				go2();
			},5000);
			
		}
		
		
		
		/*******************************************************************************
		*
		*                         	     SHAKE IT !
		*
		*******************************************************************************/
		var url = window.location.href;
		if (url == "http://www.ville-romans.fr/index.php" || url == "http://www.ville-romans.com/index.php"){
			Element.implement({shake: function () {
	
					var running = false, fx1, fx2;
			
					if(!this.retrieve('shake:fix1')) {
			
						this.store('shake:fx2', new Fx.Morph(this, {duration: 50, link: "chain", onChainComplete:function() { running = false; } })).
						store('shake:fx1', new Fx.Morph(this, {duration: 100, link: "chain", onComplete:function() {
							fx2.start({"margin-top":"-7px"}).start({"margin-top":"-4px"}).start({"margin-top":"-6px"}).start({"margin-top":0});
								}
							})
						);
					}
					fx2 = this.retrieve('shake:fx2'),
					fx1 = this.retrieve('shake:fx1');
			
					if(!running) {
			
							fx1.start({"margin-top":"-10px"}).start({"margin-top":"-4px"});
							running = true;
					}
				}
			});
		
			var y = function() {
				$('flottant').shake();
			}; 
			y.periodical(3000); 
		}
		

		 initPolice();
	});


function initPolice(){
	var curFont = LireCookie("taille");
	if (curFont==null){
		var curFont = 11;
	}
	if (curFont=="reset"){
		var curFont = 11;
	}
	var el = document.getElementById('fondgfx');
	el.style.fontSize = curFont +'px';
}

function taillePolice(step){
	if (step=="reset"){
		EcrireCookie("taille","reset");
		var el = document.getElementById('fondgfx');
		el.style.fontSize = '11px';
	}else{
		var curFont = LireCookie("taille");
		
		if (curFont==null){
			var curFont = 11;
		}
		if (curFont=="reset"){
			var curFont = 11;
		}
		step = parseInt(step,10);
		curFont = parseInt(curFont,10);
		var newtaille = (curFont+step);
		EcrireCookie("taille", newtaille);
		var el = document.getElementById('fondgfx');
		el.style.fontSize = newtaille +'px';
	}
}




function EcrireCookie(name, value){
   /* var dateExpire = new Date();
    dateExpire.setMonth(dateExpire.getMonth()+1);
    var argv=EcrireCookie.arguments;
    var argc=EcrireCookie.arguments.length;
    var expires=(argc > 2) ? argv[2] : null;
    var path=(argc > 3) ? argv[3] : null;
    var domain=(argc > 4) ? argv[4] : null;
    var secure=(argc > 5) ? argv[5] : false;
    document.cookie=nom+"="+escape(valeur)+
    ((expires==null) ? "" : ("; expires="+dateExpire.toGMTString()))+
    /*((path==null) ? "" : ("; path="+path))+
    ((domain==null) ? "" : ("; domain="+domain))+
    ((secure==true) ? "; secure" : "");*/
    
    //nouvel objet date
	var aujourdhui = new Date() ;
	 
	//nouvel objet date
	var expdate = new Date() ;
	 
	//plus an an à partir d'aujourdh'ui le cookie ne s'efface jamais
	expdate.setTime( aujourdhui.getTime() + ( 365*24*60*60*1000 ) )
	 
	//creation du cookie
	document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() ;

}



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;
}

