var timerID = null;
var delay = 3000;
var delay_start = 3000;
var delay_pause = 30000;
var currentActu = 1;

jQuery(document).ready(function() {
  jQuery("#actus").hover(function(){
    timer(currentActu, delay_pause);
   },function(){
    timer(currentActu, delay_start);
   });
});

function aff(actu){
  nbNews = jQuery('#liste_actus').children().length;
  currentActu = actu;

  jQuery("#liste_actus li.currentActu").removeClass(jQuery("liste_actus li.currentActu").attr("class"));
  jQuery("#li"+currentActu).addClass("currentActu");
  if(jQuery('#actus .actu:visible').attr('id') != 'actu' + currentActu){
    jQuery('#actus .actu:visible').fadeTo(300, 0, function(){
        jQuery(this).hide();
        jQuery('#actu' + actu).css('opacity', '0').show().fadeTo(500, 1);
    });
  }

	if(currentActu >= nbNews) currentActu = 0;
	currentActu++;
	timer(currentActu, delay);
}

function timer(currentActu, pDelay){
  clearTimeout(timerID);
	timerID = self.setTimeout("aff(currentActu)", pDelay);
}

var ctimerID = null;
var cdelay = 10;
speed = 1;
currentPos = 0;
lastPos = -1;

function affClient(){
	if(lastPos == -1 && currentPos != 0){
		speed = (45-currentPos)/9;
		if(speed < 1) speed = 1;
	}
	if(lastPos == 1 && currentPos != 0){
		speed = (currentPos)/9;
		if(speed < 1) speed = 1;
	}
	else
	{
		speed = 1;
	}
	if(currentPos <= 45&& currentPos >= 0 && (lastPos == -1 || lastPos == 1))
	{
		currentPos -= speed*lastPos;
		jQuery("#barreOnglet").css("top", -currentPos);
		clearTimeout(ctimerID);
		ctimer();
	}
	else	{
		if(lastPos == -1){currentPos = 45;lastPos = 1;}
		else{currentPos = 0;lastPos = -1;}
		jQuery("#barreOnglet").css("top", -currentPos*lastPos);
		clearTimeout(ctimerID);
	}
}

function ctimer(){
	ctimerID = self.setTimeout("affClient()", cdelay);
}

/*******Mini lightbox start******/
function aff_minilightbox(bloc_id){
  jQuery("#"+bloc_id).show("slow");
  //probleme avec ie7
  jQuery("#leftnavbutton").hide();
  jQuery("#rightnavbutton").hide();
  return false;
}
function hide_minilightbox(bloc_id){
  jQuery("#"+bloc_id).hide("slow");
  //probleme avec ie7
  jQuery("#leftnavbutton").show();
  jQuery("#rightnavbutton").show();
  return false;
}
/*******Mini lightbox end******/

/*******Affiche bloc start******/
function aff_bloc(bloc_id, bloc_num){
  //on cache tous les blocs du popup
  jQuery.each(jQuery('#bloc_onglet_'+bloc_id+' .bloc_image'), function(){
    jQuery(this).hide();
  });
  //on affiche le bloc sélectionné
  jQuery('#bloc_'+bloc_id+'_'+bloc_num).show();
  
  //on enlève la class selected à l'ancien onglet sélectionné
  jQuery.each(jQuery('#bloc_onglet_'+bloc_id+' .bar_onglet .selected'), function(){
    jQuery(this).removeClass('selected');
  });
  //on met la class selected au nouvel onglet sélectionné
  jQuery('#onglet_'+bloc_id+'_'+bloc_num).addClass('selected');
  
  return false;
}
/*******Affiche bloc end******/

/*******LAMONDE SCROLLER*******/
var Lsecs = 0;
var LtimerID = null;
var LtimerRunning = false;
var Ldelay = 3;
var Lspeed = 10;
var LcurrentPos = new Array;
var LcurHeight = 0;
var Ldirection = 1;
var LbackupPage = "";
var LopenPage = "";
var Lclosing = false;
function init(){
	LcurrentPos[0] = 0;
	LcurrentPos[1] = 0;
	
	LcurHeight = 0;
	Ldirection = 1;
	clearTimeout(LtimerID);
}
init();

function LpreAff(page){
	LbackupPage = page;
	enterFrame("Laff", page)
}

function Laff(page){
	if(LcurrentPos[0] != 0 || LcurrentPos[1] != 0)
	{
		if(LcurrentPos[0] != 0) page = "sm1";
		if(LcurrentPos[1] != 0) page = "sm2";
		
		if(LcurHeight > 0)
		{
			LcurHeight -= Lspeed;
			jQuery("#"+page).css("height", LcurHeight);
			clearTimeout(LtimerID);
			enterFrame("Laff", page);
		}
		else	{
			LclosingTest(page);
			init();
			if(Lclosing != true) Laff(LbackupPage);
		}
	}
	else{
		jQuery("#"+page).css("display", "block");
		if((LcurHeight < 90 && Ldirection == 1 && page == 'sm1') || (LcurHeight < 150 && Ldirection == 1 && page == 'sm2'))
		{
			LcurHeight += Lspeed;
			jQuery("#"+page).css("height", LcurHeight);
			clearTimeout(LtimerID);
			enterFrame("Laff", page);
		}
		else
		{
			if((LcurHeight == 90 && page == 'sm1') || (LcurHeight == 150 && page == 'sm2'))
			{
				Ldirection = -1;
				if(page == "sm1") LcurrentPos[0] = LcurHeight;
				if(page == "sm2") LcurrentPos[1] = LcurHeight;
				LopenPage = page;
				clearTimeout(LtimerID);
			}
			else
			{
				clearTimeout(LtimerID);
			}
		}
	}
}

function LclosingTest(cible){
	if(LbackupPage == LopenPage){
		Lclosing = true;
	}
	else{
		Lclosing = false;
	}
}

function enterFrame(fonction, cible){
	LtimerID = self.setTimeout(fonction+"('"+cible+"')", Ldelay);
}

/* CURSEUR */
function GetId(id)
 {
 return document.getElementById(id);
 }
 var i=false; // La variable i nous dit si la bulle est visible ou non

 function move(e) {
 if(i) { // Si la bulle est visible, on calcule en temps réel sa position idéale
 if (navigator.appName!="Microsoft Internet Explorer") { // Si on est pas sous IE
 GetId("curseur").style.left=e.pageX + -210+"px";
 GetId("curseur").style.top=e.pageY + 10+"px";
 }
 else { // Modif proposé par TeDeum, merci à lui
 if(document.documentElement.clientWidth>0) {
 GetId("curseur").style.left=-190+event.x+document.documentElement.scrollLeft+"px";
 GetId("curseur").style.top=10+event.y+document.documentElement.scrollTop+"px";
 }
 else {
 GetId("curseur").style.left=-190+event.x+document.body.scrollLeft+"px";
 GetId("curseur").style.top=10+event.y+document.body.scrollTop+"px";
 }
 }
 }
 }

 function montre(text) {
 if(i==false) {
 GetId("curseur").style.visibility="visible"; // Si il est caché (la vérif n'est qu'une securité) on le rend visible.
 GetId("curseur").innerHTML = text; // Cette fonction est a améliorer, il paraît qu'elle n'est pas valide (mais elle marche)
 i=true;
 }
 }
 function cache() {
 if(i==true) {
 GetId("curseur").style.visibility="hidden"; // Si la bulle était visible on la cache
 i=false;
 }
 }
 //document.onmousemove=move; // dès que la souris bouge, on appelle la fonction move pour mettre à jour la position de la bulle.
 
function checkboxModification(button_id){

  jQuery.each(jQuery('#mygallery .panel'), function(){
    if(jQuery(this).hasClass(button_id)){
      
      if(jQuery('#' +button_id).attr("checked") ){
        jQuery(this).show("slow");
        //jQuery(this).fadeIn("slow");
        /*jQuery(this).css("opacity", "1");
        jQuery(this).css("filter", "alpha(opacity=100)");
        jQuery(this).css("-moz-opacity", "1");*/
      }
      else
      {
        jQuery(this).hide("slow");
        //jQuery(this).fadeOut("slow");
        /*
       jQuery(this).css("opacity", "0.5");
       jQuery(this).css("filter", "alpha(opacity=50)");
       jQuery(this).css("-moz-opacity", "0.5");*/
      }
    }
  });
}
 
 function initFilter(){
    jQuery.each(jQuery('#filter input'), function(){
      jQuery('#' + this.id ).attr("checked", "checkcked");
   });
 }
 /*jQuery(document).ready(function() {initFilter();});*/
 
