// JavaScript Document

var itemToDeleteLink = '';


$(document).ready(function(){	
	
	// BACK TO TOP ANIMATE
	$('.top').click(function(){
		$('html, body').animate({scrollTop:0}, 'fast');
		return false;
	});
	
	// SCROLLDOWN
	$('.scrollPage').click(function() {
		var elementClicked = $(this).attr("rel");
	   	/*var elementHref = $(this).attr("href");
	   	document.location = elementHref;*/
	   	var destination = $(elementClicked).offset().top;
	   	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 'fast' );
   		return false;
	});
			
	//1 seul volet ouvert
	$("#accordion").accordion({
	    collapsible: true,
		autoHeight: false,
		active: 'none',
		navigation: true

	});	
	
	//1 seul volet ouvert
	/*
	
	//1 seul volet ouvert
	$("#accordion").accordion({
	    collapsible: false,
		autoHeight: false,
		event: 'mouseover',
		navigation: true

	});
	
	
	$("#accordion").accordion({
	    collapsible: true,
	    active: 'none',
		autoHeight: false,
		change: function(event, ui){ 
			alert($(this).att('href'));
			document.location = $(this).att('href');
		}

	});*/
	
	//CODE POUR LA GALERIE
	
	var totWidth=0;
	var positions = new Array();
	var actualPosition=0;
	var limit;
	var counter=1;
	
	$('#galerieSlide .slide').each(function(i){
		/* Traverse through all the slides and store their accumulative widths in totWidth */
		positions[i]= totWidth;
		totWidth += $(this).width();
		
		/* The positions array contains each slide's commulutative offset from the left part of the container */
		if(!$(this).width()){
			alert("Please, fill in width & height for all your images!");
			return false;
		}	
	});
	
	$('#galerieSlide').width(totWidth);
	
	$('#next').click(function(){
		var limit = totWidth - 905;
		if(actualPosition >= limit){
			$('#galerieSlide').animate({'left':'0'},550);
			actualPosition = 0;
			$('#navNum').html(counter = 1);
		}else{
			actualPosition = actualPosition + 905;
			$('#galerieSlide').animate({'left':'-=905'},550);
			$('#navNum').html(counter = counter + 1);

		}
	});
	
	$('#galerie img').click(function(){
		var limit = totWidth - 905;
		if(actualPosition >= limit){
			$('#galerieSlide').animate({'left':'0'},550);
			actualPosition = 0;
			$('#navNum').html(counter = 1);
		}else{
			actualPosition = actualPosition + 905;
			$('#galerieSlide').animate({'left':'-=905'},550);
			$('#navNum').html(counter = counter + 1);

		}
	});
	
	$('#prev').click(function(){
		
		if(actualPosition == 0){
			return false;
		}else{
			actualPosition = actualPosition - 905;
			$('#galerieSlide').animate({'left':'+=905'},550);
			$('#navNum').html(counter = counter - 1);
		}	
	});
	
	
	$('.close').click(function() {
		document.location = "galeries";
	});
	
	//location.hash => reprend tout ce qui est après le dièse dans l'url
	if(location.hash != "") {
		var elementClicked = $("#content_"+location.hash.replace(/#/, ''));
	   	var destination = $(elementClicked).offset().top;
	   	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 'fast' );
	}
}); 

