window.addEvent('domready', function() {

	
	
	////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////	
	
	var backgroundElements = $$('div#background'), color = [134, 198, 26];
	var updateColor = function() {
		
			var colorElements = ($$('h2')).extend($$('div#footer-menu')).extend($$('a:hover')).extend($$('div#home a')).extend($$('div#contentRequest ul'));
		
		colorElements.each(function(el){
			el.setStyle('color', color);
		});
		backgroundElements.each(function(el){
			el.setStyle('background-color', color);
		});
		//$('hexaColor').setStyle('color', color).set('text', color.rgbToHex());
		//alert($$('div#content').get('text'));
	}
	
	
	$$('div.slider.advanced').each(function(el, i){
		var slider = new Slider(el, el.getElement('.knob'), {
			steps: 255,  // Steps from 0 to 255
			wheel: true, // Using the mousewheel is possible too
			onChange: function(){
				// Based on the Slider values set an RGB value in the color array
				color[i] = this.step;
				// and update the output to the new value
				updateColor();
			}
		});
				
		if(i==0)
			slider.set(134);
		else if(i==1)
			slider.set(198);
		else if(i==2)
			slider.set(26);

	});
	
	var liensMenus = $$('ul.sousMenu li a');
	
	liensMenus.each(function(el){
	
		el.addEvent('mouseover', function () {
			el.setStyle('color', color);
		});
		el.addEvent('mouseout', function () {
			el.setStyle('color',  '#FFFFFF');
		});

	
	});

	
	// --
	
	var newsRequest = new Request.HTML({
		onSuccess: function(html) {
				//Clear the text currently inside the results div.
				$('newsRequest').set('text', '');
				//Inject the new DOM elements into the results div.
				$('newsRequest').adopt(html);
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function() {
			$('newsRequest').set('text', "We're sorry. under construction.");
		}
	});

	//We can use one Request object many times.
	var contentRequest = new Request.HTML({
		onSuccess: function(html) {
			
			//Clear the text currently inside the results div.
			$('contentRequest').set('text', '');
			//Inject the new DOM elements into the results div.
			$('contentRequest').adopt(html);
			updateColor();
			if ($('newsRequest')) {
				newsRequest.send({url:'news.html'});
			}
		},
		//Our request will most likely succeed, but just in case, we'll add an
		//onFailure method which will let the user know what happened.
		onFailure: function(xhr) {
			$('contentRequest').set('text', "We're sorry. under construction.");
		}
	});

	
	var mesLiens = $$('ul.sousMenu li a').extend($$('div#contact a')).extend($$('ul.footer-menu-principal li ul li a')).extend($$('div#home a'));
	
	mesLiens.each(function(el){
		el.store('lien', el.href);
		el.href = '#ancre-'+el.id;
	});
	
	mesLiens.addEvent('click', function (e) {
		contentRequest.send({url:this.retrieve('lien')});

	});

	if (window.location.href.test('#')) {
		var idEl = window.location.href.replace(/.*#ancre-/g, '');
		if ($(idEl) && $(idEl).retrieve('lien')) {
				contentRequest.cancel().send({url:$(idEl).retrieve('lien')});
			}
	} 
	else {
		contentRequest.send({url:'accueil.html'});
	}
	


	
	
	
});