window.addEvent('domready', function()
{
	
	if($('Les-Tops')){
		
		// Roll lestops
		var aItems = $$('.group-measures .box .item');
		aItems.each(function(el,i){
			var aPic = $$('.group-measures .item .pic');
			var aTitle = $$('.group-measures .item h5 a');
			var aTxt = $$('.group-measures .item p a');
			var aTheme = $$('.group-measures .item').getElement('.theme');
			var aColor = aTheme[i].getStyle('color');
			//alert(aColor);
			
			var fxImg   = new Fx.Morph(aPic[i], {duration:400});
			var fxlinkTitle  = new Fx.Morph(aTitle[i], {duration:400});
			var fxlinkTxt  = new Fx.Morph(aTxt[i], {duration:400});
	
			el.addEvents({
				'mouseenter' : function() {
					fxImg.cancel();
					fxlinkTitle.cancel();
					fxlinkTxt.cancel();

					fxImg.start({'opacity': 0.8});
					fxlinkTitle.start({'color': aColor});
					fxlinkTxt.start({'color': aColor});
					
	
				},
				'mouseleave' : function() {
					fxImg.cancel();
					fxlinkTitle.cancel();
					fxlinkTxt.cancel();
					
					fxImg.start({'opacity': 1});
					fxlinkTitle.start({'color': '#000'});
					fxlinkTxt.start({'color': '#3b3b3b'});
				}
			});
		});
	}


	// LINK _BLANK
	/*$$('#exchangeMesure .element a').each(function(el){
		el.setProperty('target','_blank');
	});*/
	
	if($('filtre0')){
		$$('#filtre0 span').set('html', '<strong>Les 3 mesures <br /> les plus consult&eacute;es</strong><br />depuis 24h');
	}
	
	if($('filtre1')){
		$$('#filtre1 span').set('html', '<strong>Les 3 mesures <br /> les plus comment&eacute;es</strong><br />depuis 24h');
	}
	
	if($('filtre2')){
		$$('#filtre2 span').set('html', '<strong>Les 3 mesures <br /> les plus r&eacute;centes</strong><br />depuis 24h');
	}
	if($('filtre3')){
		$$('#filtre3 span').set('html', '<strong>Les 3 mesures <br /> &agrave; d&eacute;couvrir</strong><br />depuis 24h');
	}
	
	if($('bloc-vote')){
		$('bloc-vote').setStyle('display', 'block');
	}
	
	// INIT LAYERS POSITION
	$('Add-Survey').setStyle('top', -400);
	$$('.roar').setStyle('top', -400);
	$('Add-Subject').setStyle('top', -400);
	$('AddComm-level1').setStyle('top', -400);
	$('Explain').setStyle('top', -400);
	$$('.errorIndex').setStyle('top', -400);
	$$('.popup').setStyle('top', -400);
	$$('.send-friend').setStyle('top', -400);
	$('Lay-reg-photo').setStyle('top', -800);

	//initSmoothScroll();

	//ROLL TAGS - FAQ
	animTags();
	rollFadeBg();

	//SYSTEM AJAX FORMULAIRE
	startAjax.delay(0);


	//SYSTEM VOTE
	var imageOnStar;
	var imageOffStar;

	startVote();

	//SELECT VALUE INPUT RADIO FORM
	radioSelect('Frm_add_comm');
	radioSelect('Frm_addsurvey');
	radioSelect('Frm_addsubject');
	radioSelect('Frm_add_comm_level1');
	//radioSelect('Frm_orienteur');
	radioSelect('SexeFltr');
	radioSelect('tonAge');

	//ORIENTEUR SHOW FILTER BUBBLES
	/*if ($('Btn-Bubbles')){
		$('Btn-Bubbles').addEvent('click', function(){
		 	new LoadBubbles();
		});
	}*/

	//AJAX ORIENTEUR
	if ($('BtnFrm_orienteur')){
		$('BtnFrm_orienteur').addEvent('click', function(){
			ajaxLoader(this);
			count('BtnFrm_orienteur');
		});
	}

	if ($('BtnFrm_orienteur_log')){
		$('BtnFrm_orienteur_log').addEvent('click', function(){
			ajaxLoader(this);
			count('BtnFrm_orienteur_log');
		});
	}

	//BTN FILTRE MEASURES
	btnFilter('chooseFltr');

	//INIT PAGE MEASURE CONTENT
	/*if ($('exchangeMesure')){
		showMeasure.delay(800);
	}*/

	//INIT PAGE FAQ
	/*if ($('Faq-Box')){
		showResponses();
	}*/

	//SONDAGES VOTE
	if ($('Survey-Box')){
		//page surveys
		$$('.responses li a').addEvent('click', function(){SurveyBoxVote(this);});
	}else{
		//box surveys home
		$$('.responses li a').addEvent('click', function(){SurveysVote(this);});
	}

	/* Search BTN
	value_search_input = $('search_input').get('value');
	//alert(value_search_input);
	if (value_search_input = 'Mot cl&eacute;'){
		$('searchbtn').set('disabled', true);
		$('searchbtn').addClass('disabled');
	}
	/*/



	// FX event navigation
	$$('#Nav a').each(function(el) {
		var size = el.getSize();
		var position = Math.round(size.x*4);
		var fx = new Fx.Morph(el,{duration: 400,
     		onComplete:function() {
				el.setStyle('visibility', 'visible');
        	}
		});
		var fx2 = new Fx.Tween(el,{
      		duration: 300,
     		onComplete:function() {
				el.setStyle('background-position','0 0');
        	}
    	});
		el.addEvents({
			'mouseover': function() {
				fx.cancel();
				fx2.cancel();
				fx.start({opacity:[1,0]});
				fx2.set('background-position','0 0');
			},
			'mouseout': function() {
				fx.cancel();
				fx2.cancel();
				fx.start({opacity:[0,1]});
				fx2.start('background-position','-'+position+'px 0');
			}/*,
			'click': function() {
				$$('#Nav a').removeClass('on');
				el.addClass('on');
			}*/
		});
	});

	// FX event resources
	$$('.effect li a').each(function(el,i) {
		var fx = new Fx.Morph(el,{duration: 500});
		el.addEvents({
			'mouseover': function() {
				fx.cancel();
				fx.start({opacity:[1,.1]});
				$$('.icontext').setStyle('display', 'none');
				//alert($(el).get('id'));
				title = $(el).get('id');
				$('resourceTitle-'+title).setStyle('display', 'block');
			},
			'mouseout': function() {
				fx.cancel();
				fx.start({opacity:[.1,1]});
			},
			'click': function() {
				$$('.effect li span').removeClass('on');
				$(el).addClass('on');
			}
		});
	});

	// ROLL ie6
	$$('#affine-search .age span').each(function(el) {
		el.addEvents({
			'mouseover': function() {
				el.addClass('on');
			},
			'mouseout': function() {
				el.removeClass('on');
			}
		});
	});

	// ROLL TEXTE
	$$('.fxtween').each(function(el) {
		var fx = new Fx.Tween(el,{ duration:300 });

		el.addEvents({
			'mouseover': function() {
				fx.cancel();
				fx.start('color','#3B3B3B','#7eb403');
			},
			'mouseout': function() {
				fx.cancel();
				fx.start('color','#7eb403','#3B3B3B');
			}
		});
	});
	
	$$('.btntween').each(function(el) {
		var fxBtn = new Fx.Tween(el);
		el.addEvents({
			'mouseenter': function() {
				fxBtn.cancel();
				fxBtn.start('opacity',0.01);
			},
			'mouseleave': function() {
				fxBtn.cancel();
				fxBtn.start('opacity',1);
			}
		});
	});
	
	// clear texarea Siganler un abus
	if ($('Lay-ReportAbus')){
		$('Lay-ReportAbus').setStyle('top', -400);
		$$('#Lay-ReportAbus .textarea').addEvent('click', function(){
			$$('#Lay-ReportAbus .textarea').set('value', '');
		});
	}
	
	// ANCRE REGLEMENT PHOTO
	if ($('Lay-reg-photo')){
		var contenu = $$('#Lay-reg-photo .scroll')[0];
		var btnContent = $$('#Lay-reg-photo li');
		btnContent.each(function(el,i) {
			el.addEvents({
				'click': function() {
					btnContent.removeClass('on');
					
					var PositionContenu = contenu.getPosition();
					//alert(PositionContenu.y);
					initPositionContenu = 374;
					
					var Position = $('article'+i).getPosition();
					var PositionAncre = (Position.y)-(PositionContenu.y-initPositionContenu);
					//alert(PositionAncre);
					
					var scrollPosition = PositionAncre-(PositionContenu.y);
					//alert(scrollPosition);

					//contenu.scrollTo(PositionAncre, scrollPosition);
					var myFx = new Fx.Scroll(contenu).chain(function(){
							el.addClass('on');
					}).start(PositionAncre, scrollPosition);

				}
			});
		});
	}
	

});


//SWFUPLOAD
function fileQueueError(){
	alert('Une seule image possible !');	
}
function fileQueued(){}
function fileDialogStart(){}
function loadFailed(){}
function preLoad(){}

function swfFileDialogComplete()
{
    this.startUpload();
}

function swfUploadSuccess(file, serverData, response)
{
	aServerData = serverData.split('****');

	if (aServerData.length == 3)
	{
		$('Edit-Pic-Api').setProperty('src',aServerData[0]);
		$('Edit-Pic-Api').setStyle('display', "block");
		oParcours.setPostParams({FORCEPHPSESSID : aServerData[2], tokenPost : aServerData[1]});
	}else{
		$('Edit-Pic-Api').setProperty('src',serverData);
	}
}

function swfUploadSuccessLook(file, serverData, response)
{
    document.getElementById('Edit-Look-Api').reloadImage(serverData);
}

function swfUploadError(){alert('error');}
function uploadProgress(){}

function savePicture()
{
    document.getElementById('Edit-Pic-Api').saveImage();
}

function saveLook()
{
    document.getElementById('Edit-Look-Api').saveImage();
}

function afterSaveImageAvatar(id, retour)
{
    $('photo').set("value", retour);
    document.getElementById('Concours_Mesures_Form').submit();
}

function afterSaveImageLook(id, retour)
{
    $('upload_look_hidden').set("value", retour);
    document.getElementById('Edit-Look-Form').submit();
}


