var indexBandeau = 1;
var intervalCarrousel = null;

$(document).ready(function(){
	$(".slideshow ul li").each(function(){
		$.preloadImages(this, $(this).attr("rel"));
	});
		
	if($(".vignettes").size() > 0){
		// Chargement de la premiere image
		var src = $(".slideshow ul li").attr("rel");		
		$(".slideshow .img").append("<img src='"+ src +"'>");				
	  	
		initCorners();
		
		// Activation de la premiere vignette
		$(".slideshow ul li:eq(0)").addClass("act");	
		
	  	$("li.vignettes").click(function(){
			if (! $(this).hasClass("act")){
				loadimg(this);
			}
	  	});
	  	
	  	// Fix: on reinitialise l'index du slideshow
	  	$(".slideshow").css('z-index', '1');
	  	
		animateBandeau();
	}
});

function animateBandeau(){
	intervalCarrousel = window.setTimeout("showBandeau('" + indexBandeau + "')", 12000);
}

function showBandeau(index){
	indexBandeau = index;
	
	// Nombre de vignettes au total
	nbImg = $('.slideshow .vignettes').size();
	
	if (nbImg > 0){
		if (indexBandeau == (nbImg - 1)){
			indexBandeau = 0;
		} else {
			indexBandeau++;
		}
	}
	loadimg($(".slideshow ul li:eq("+ index +")"));
}

function loadimg(dom){
 	$(".slideshow ul li").removeClass("act");
 	$(".slideshow .img img").ImageSwitch({Type:"ScrollOut", NewImage:""+$(dom).attr("rel")+""});
 	$(dom).addClass("act");	
	
	if (intervalCarrousel != null)
			window.clearTimeout(intervalCarrousel);
	intervalCarrousel = window.setTimeout("showBandeau('" + indexBandeau + "')", 5000);
};

function initCorners() {
    var settings = {
      tl: { radius: 10 },
      tr: { radius: 10 },
      bl: { radius: 10 },
      br: { radius: 10 },
      antiAlias: true
    }
    curvyCorners(settings, ".roundact");
    curvyCorners(settings, ".round");     
 }
 
jQuery.preloadImages = function(dom, src){ 
	$(dom).find('img').attr("src", src);
}

