Shadowbox.init({
    language: 'fr',
    players:  ['html', 'iframe'] 
});


$(document).ready(function() {
   if($("#s3slider").length)  
	{ 
		jQuery('#s3slider').s3Slider({
		timeOut: 4000
		});
	}
});

 


//Hover sur les vignettes références page d'accueil
var LaMarge = "-32px";
$(document).ready( function(){
	$('div.ReferenceSmall').each(function () {
	var rollover = $(this).children(".imageRef");
	var corners = $(this);
	$(corners).mouseover(function(event){
	$(rollover).stop().animate({marginTop: LaMarge},{queue:false, duration:200});
	})
	$(corners).mouseout(function(event){
	$(rollover).stop().animate({marginTop: "0px"},{queue:false, duration:200, complete:function(){
	}});
	})
	})
	}); 
	


// Fonctions pour slider vers la gauche ou la droite 
function Prev(){
  
  $('#ReferenceAffiche').stop(true, true);
  if($('#ReferenceAffiche').css('margin-left') >= '0px') {
  		$('.prevProjet').html('');
  }
  
  if($('#ReferenceAffiche').css('margin-left') < '0px') {
  		$('#ReferenceAffiche').stop(true, true).animate({"marginLeft": "+=225px"}, 400, 'swing', function() {
  			
  			$('.nextProjet').html('<a href="" title="Références Suivantes" id="suiv" onclick="Suiv(); return false;"></a>');
  			
  			if($('#ReferenceAffiche').css('margin-left') >= '0px') {
  				$('.prevProjet').html('');
  			}
  		});
  }
}

function Suiv(){

  $('#ReferenceAffiche').stop(true, true);
  if($('#ReferenceAffiche').css('margin-left') == $('#ReferenceAffiche').css('margin-right')) {
  		$('.nextProjet').html('');
  }
  
  if($('#ReferenceAffiche').css('margin-left') <= '0px') {
  		$('#ReferenceAffiche').animate({"marginLeft": "-=225px"}, 400, 'swing', function() {
  			
  			$('.prevProjet').html('<a href="" title="Références Précédentes" id="prev" onclick="Prev(); return false;"></a>');
  			
  			if($('#ReferenceAffiche').css('margin-left') == $('#ReferenceAffiche').css('margin-right')) {
  				$('.nextProjet').html('');
  			}
  		});
  }
}

$(document).ready(function() {
		
	var i = 0;
	var j = 1;
	var maxi = 0;
	
	$('.ImageDiapo').each(function(){ maxi++; });
	
	var Transition = function(i, j) {
		
		$('#diapo'+i).fadeOut(600);
		
		$('#diapo'+j).fadeIn(600, function() {
			$('#bouton'+i).removeClass('Active');
			$('#diapo'+i).removeClass('Current');
			$('#bouton'+j).addClass('Active');
			$('#diapo'+j).addClass('Current');
		});
	}
	
	/*var Delai = function(i) {
		
		//alert(i);
		setTimeout(function() { Transition(i); }, 2000);
		
	}*/
	
	if(maxi > 1) {
		window.setInterval(function() {
			
			Transition(i, j);
			
			if(i < maxi) {
				
				i++;
				if((i + 1) == maxi) {
					j = 0;
				} else {
					j = i + 1;
				}
			} else {
				
				i = 0;
				j = 1;
			}
		}, 7000);
	}
});

function DiapoFade(j) {
	
	var maxi = 0;
	
	$('.ImageDiapo').each(function(){ maxi++; });
	
	//alert(maxi);
	
	$('.Current').fadeOut(600);
	
	$('#diapo'+j).fadeIn(600, function() {
		$('.Active').removeClass('Active');
		$('#bouton'+j).addClass('Active');
		$('.Current').removeClass('Current');
		$('#diapo'+j).addClass('Current');
	});
	
	return false;
}


function NewRef(pos, cible, cat) {
	
	$.ajax({
		url: '../ajax/new_reference.php',
		data: 'pos='+pos+'&cible='+cible+'&cat='+cat,
		success: function(data) {
			
			if(cible == 'next') {
				
				$('#CurrentRef').stop(true, true);
				
				$('#NextRef').html(data);
				$('#CurrentRef').animate({"marginLeft": "-=698px"}, 500, function() {
					  $('#CurrentRef').replaceWith('');
					  $('#NextRef').attr('id', 'CurrentRef');
					  $('#CurrentRef').after('<div id="NextRef"></div>');
		  		});
			}
			if(cible == 'prev') {
				
				$('#PrevRef').stop(true, true);
				
				$('#PrevRef').html(data);
				$('#PrevRef').animate({"marginLeft": "+=698px"}, 500, function() {
					  $('#CurrentRef').replaceWith('');
					  $('#PrevRef').attr('id', 'CurrentRef').css('margin-left', '0px');
					  $('#CurrentRef').before('<div id="PrevRef"></div>');
		  		});
			}
		}
	});
	$.ajax({
		url: '../ajax/new_reference_haut.php',
		data: 'pos='+pos+'&cible='+cible+'&cat='+cat,
		success: function(data) {
			$('#haut').html(data);
		}
	});
	return false;
}
