﻿$(function(){
	timer = setTimeout("autoDiapo()",6000);//initialisation du diapo
	
	$('.bloc_animation .next').click(function(){//le click sur next
		nextButton();
		return false;
	})
	
	$('.bloc_animation .prev').click(function(){//le click sur prev
		prevButton();
		return false;
	})
	
	/* Le choie d'une reponse "Quiz" */ 
	QustionChoice()
	
	$('body > img').remove();
	
	
	InitQUIZZ();
	
	if($('.network ul li .visuel').length){
		$('.network ul li .visuel span img').pixastic("desaturate");
		/*pushNetworkHover();*/ /*modifs*/
	}
	
	if($('.select_box').length)
	selectEvent();
	
	if($('.network').length) setBorder();

})

/*-- l'auto diapo --*/
function autoDiapo(){
	if($('.bloc_animation ul').css("left") == "-2298px"){
		var html = $($('.bloc_animation > ul > li')[3]);
		$('.bloc_animation > ul > li:first').before(html);
		$('.bloc_animation > ul').css({"left" : "0" });
		$('.bloc_animation > ul').animate({"left" : "-=766" })
	}
	else{
		$('.bloc_animation > ul').animate({"left" : "-=766" })
	}
	clearTimeout(timer);
	timer = setTimeout("autoDiapo()",6000);
}

function nextButton(){
	var p = $('.bloc_animation ul');
	var position = p.position();
	var left = position.left;
	if(left == -2298 && (left%766)== 0){
		var html = $($('.bloc_animation > ul > li')[3]);
		$('.bloc_animation > ul > li:first').before(html);
		$('.bloc_animation > ul').css({"left" : "0" });
		$('.bloc_animation > ul').animate({"left" : "-=766" })
	}
	else if((left%766)== 0){
		$('.bloc_animation > ul').animate({"left" : "-=766" })
	}
	clearTimeout(timer);
	timer = setTimeout("autoDiapo()",6000);
}

function prevButton(){
	var p = $('.bloc_animation ul');
	var position = p.position();
	var left = position.left;
	if(left == 0 && (left%766)== 0 ){
		var html = $('.bloc_animation > ul > li:first');
		$('.bloc_animation > ul > li:last').after(html);
		$('.bloc_animation > ul').css({"left" : "-2298px" });
		$('.bloc_animation > ul').animate({"left" : "+=766" });
	}
	else if((left%766)== 0){
		$('.bloc_animation > ul').animate({"left" : "+=766" });
	}
	clearTimeout(timer);
	timer = setTimeout("autoDiapo()",6000);
}

/* Le choie d'une reponse "Quiz" */ 
function QustionChoice(){
	$('.question label').click(function(){
		$('label.checked',$(this).parents('.question')).removeClass('checked');
		$(this).addClass('checked');
	})
}

/* la  fonction qui gére les fonctions de  la quize */


function InitQUIZZ(){
answersArr=[];

//tab=RepArrayContent;
	$(".question label").bind('click',function(e){
			t=$(e.currentTarget).attr('rel').split('|');
			$(".wrong_answer").eq([Number(t[2]-1)]).show();
			rep=$(".question").eq([Number(t[2]-1)]);
			
			div=$(e.currentTarget).parents('.question');
			desc=div.find(".wrong_answer").eq([Number(t[2]-1)]);
				h=rep.find("h5");
				desc=desc.find('p');
				if(t[0]!=t[1]){
					h.text("Mauvaise réponse").show();
					$("p span",div).hide();
					if($(div.find("span")[parseInt(t[1]-1)]).length)
					$(div.find("span")[parseInt(t[1]-1)]).show();
					desc.show();
				}else{
					h.text("Bonne réponse");
					h.show();
					$("p span",div).hide();
					desc.show();
					if($(div.find("span")[parseInt(t[1]-1)]).length)
						$(div.find("span")[parseInt(t[1]-1)]).show();	
				}
	});
}
/*modifs*/
/* la hover sur les push   reseau 
function  pushNetworkHover(){
	$('.network ul li .visuel').hover(function(){
		$('span',$(this)).hide();
		$('>img',$(this)).css({display: 'block'});
	},function(){
		$('span',$(this)).show();
		$('>img',$(this)).hide();
	});
	
}
*/
/*__ le select personnalisé __*/
function selectEvent(){
	$('.select_box > span').click(function(){
		if ($(this).next('ul').hasClass('open'))
			$(this).next('ul').removeClass('open');
		else{
			$(this).next('ul').addClass('open');}
	});
	
	$('.select_box li a').bind('click',function(){
		$('span',$(this).parents('.select_box')).text($(this).text());
		$(this).parents('ul').removeClass('open');
		//return false;
	});
	
	$(document).click(function(e){
		if(!$(e.target).parents('.select_box').length){
			$('.select_box ul.open').removeClass('open');
		}
	});
}

/*__ mettre les dernieres Li sans  bordure page  "mieux nous connaitre"___*/
function setBorder(){
	var nb = $('.network ul li').length;
	$($('.network ul li')[nb-2]).css({border:0});
	$($('.network ul li')[nb-1]).css({border:0});
}
