//----------------------------------------------------------------------------------------------------------------
//										SLIDESHOW
//----------------------------------------------------------------------------------------------------------------
              
$(document).ready(function(){	
	
	//Decode email address
	if ( $("span.emailRewrite").length ) {
	  // variables, which will be replaced
	  var at = / AT /;
	  var dot = / DOT /g;
	
	  // function, which replaces pre-made class
	  $('span.emailRewrite').each(function () {
		var addr = $(this).text().replace(at, '@').replace(dot, '.');
		//$(this).after(addr);
		$(this).after('<a href="mailto:' + addr + '">' + addr + '</a>');
		$(this).remove();
	  });
	}
	
	/* SET HEIGHT FOR OVERFLOW AUTO */
	var newHeight = document.documentElement.clientHeight-107; // 107 = hauteur header + hauteur footer
	$("#wrapper").css('min-height',newHeight-2);
	
	/* CARROUSEL */
	if($('#mycarousel').length>0){
		
		$('#mycarousel').jcarousel({
			vertical: true,
			scroll: 3
		});
		
		var maxCarouselHeight = newHeight - 80 +3 -28 ; // 80 = hauteur menu  3 = pas de padding au dernier element -28 = fleche du bas
		var checkNbrElementCanBeDisplayed = Math.floor(maxCarouselHeight/55);
		var carouselHeight = (55*checkNbrElementCanBeDisplayed)-4;
		
		var nbrFilms = $("#mycarousel").children().length;
		
		if(checkNbrElementCanBeDisplayed>=nbrFilms){
			$(".jcarousel-next-vertical").css("display","none");
			$(".jcarousel-prev-vertical").css("display","none");
		}
		
		if(checkNbrElementCanBeDisplayed>(nbrFilms-3)){
			$(".jcarousel-container-vertical").height((55*(nbrFilms+2))-4);
			$(".jcarousel-clip-vertical").height((55*(nbrFilms+2))-4);
		}else{
			$(".jcarousel-container-vertical").height(carouselHeight);
			$(".jcarousel-clip-vertical").height(carouselHeight);	
		}
	}
});
            
//----------------------------------------------------------------------------------------------------------------
//	END									SLIDESHOW
//----------------------------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------------
//										Preparation Lightbox
//----------------------------------------------------------------------------------------------------------------
	$(document).ready(function(){
		$("a[rel='lightbox']").colorbox(
		{
			width:"800",
			height:"600",
			iframe:true,
			scroll:true,
			current:"PAGE {current} / {total}"
		});
		$("a[rel='road']").colorbox(
		{
			width:"500",
			height:"300",
			iframe:true,
			scroll:true,
			current:"PAGE {current} / {total}"
		});
		$("a[rel='widgetGallery']").colorbox(
		{
			scalePhotos:true,
			current:"IMAGE {current} / {total}"
		});
	});
//----------------------------------------------------------------------------------------------------------------
//	END										Preparation Lightbox
//----------------------------------------------------------------------------------------------------------------
