(function($){
	// simplefadeshow
	$.fn.simplefadeshow=function(settings) {
		var fadeshow=$(this);
		var fadebloc=fadeshow.find(".fade-bloc"); 
		var options=$.extend({
			index:0,
			listeImgs:new Array(),
			nbImgs:4,
			actif:null,
			effet:false,
			showDelay:4000
		}, settings);

		var tabLinks = new Array();

		this.each(function () {		
			if(fadeshow.length<0) {
				return;
			}
			if(fadeshow.find("ul#listeImgs li").length<0) {
				return;
			}

			fadeshow.find("ul#listeImgs").hide(1000,function(){				
				$(this).find("li").each(function(i){										
					var src=$(this).attr("rel");
					createTmpImg(src);
					tabLinks.push( $(this).find("a") );
					var fnom=src.substring(src.lastIndexOf('/')+1);
					options.listeImgs[i]=fnom;
				});
				fadeshow.find(".fade-bloc").html(tabLinks[0]).find("a").click(function(){
					$(this).blur();
				});
			});

			//nb imgs
			options.nbImgs = fadeshow.find("ul#listeImgs li").length;

			//unload : stop process
			$(window).unload(function() {
				setStop();
			});

			//next
			$('#next').click(function(){
				setStop();
				$(this).blur();
				options.index+=1;
				if( options.index>=options.nbImgs) {
					options.index=0;
				}
				changeBgImg(options.index);
				start();
			});

			//prev
			$('#prev').click(function(){
				setStop();
				$(this).blur();
				options.index-=1;
				if( options.index<=0){
					options.index=options.nbImgs-1;
				}
				changeBgImg(options.index);
				start();
			});

			//start
			start();
		});// fin : each()	
		
		

		function createTmpImg(src) {			
			var content="<div style='display:none;margin:0;padding:0;'><img src="+src+" /></div>"
			fadeshow.find("ul#listeImgs").after(content);
		}

		function start() {
			setStop();
			options.actif=setInterval(function(){setAuto();},options.showDelay);
		}

		function changeBgImg(n){
			var bgImg=options.listeImgs[n];
			var url=fadebloc.css("backgroundImage");
			var path=url.substring(0,url.lastIndexOf('/')+1);
			var pathfin=url.substring(url.indexOf('jpg')+3);
			var newUrl=path+bgImg+pathfin;

			fadeshow.find(".fade-bloc").html(tabLinks[n]).find("a").click(function(){
				$(this).blur();
			});

			if(!options.effet) {
				fadebloc.css("backgroundImage",newUrl);
			} else {
				fadebloc.fadeOut(300,function(){
					$(this).css("backgroundImage",newUrl);			
					$(this).fadeIn(300);
				});
			}
		}

		function setAuto(){
			options.index+=1;
			if(options.index==options.nbImgs) {
				options.index=0;
			}			
			changeBgImg(options.index);
			//start();
		}

		function setStop(){
			window.clearTimeout(options.actif);
			options.actif=null;
		}

		return this;
	};   // fin : $.fn.simplefadeshow
})(jQuery);   // fin
jQuery(document).ready(function($) {   
	//$("#fadeshow").simplefadeshow({effet:true});
	if($("ul#listeImgs").length>0) {$("ul#listeImgs").hide(1000);}
});

function initFromFlash() {
	// affichage boutons de controle
	if($("#Page .fade-content #ch-bg-img").length>0) {$("#Page .fade-content #ch-bg-img").fadeIn();}
	if($("#Page .fade-content #EnTete #Logo object").length>0) {$("#Page .fade-content #EnTete #Logo object").hide();}
	if($("#Page .fade-content #EnTete #Logo embed").length>0) {$("#Page .fade-content #EnTete #Logo embed").hide();}
	if($("#Page .fade-content #EnTete #Logo a").length>0) {$("#Page .fade-content #EnTete #Logo a").show();}
	$("#fadeshow").simplefadeshow({effet:true});
}