$(document).ready(function(){
	
	function alea(nb){
		sortie = Math.round(Math.random()*nb);
		return sortie;
	}
	
	var act = 'aller';
	
	
	function anim(x){
		ajout = '<img src="img/layout/ginkgo2.gif" class="element" id="elt'+x+'">';
		$("#anim").append(ajout);
		taille = alea(120);
				
			$("#elt"+x).css({left: alea(300), width: 6}).animate({left: alea(300), top: alea(200), width: taille,  opacity: .8}, alea(1000)).css('filter', 'none');
			
		if(act != 'stop'){
			setTimeout(function(){anim(x+5)},450);//meme val que nb de boucles, si moins les element sont repris et bougent...
		}	
	}
		
	function arret(){
		act = 'stop';
		
		$("#anim img").stop(true);
		setTimeout(function(){
			$("#anim img.element").fadeOut(1000);
			setTimeout(function(){
				
					$("#feuille img").css('filter', 'none');//filter: pour IE
					$("#feuille").fadeIn(3000, function(){
						if($.browser.msie && $.browser.version == '6.0'){
							//$("#feuille img").attr('src','img/layout/ginkgo.png');//filter: pour IE
						}
						else {
							$("#feuille img").attr('src','img/layout/ginkgo.png');//filter: pour IE
						}
						//$("#feuille").css('filter', 'none');//filter: pour IE
					});
					
					//$("#feuille").css({opacity: 0, display: "block"}).fadeIn(2000);
					$("#anim_coin").fadeOut();
					
				},500);
		},1000);
	}
	
	$("#stop").click(function(){
		arret();		
	});
	
	
	
	
	
	
$("#feuille1").css({display: "none"});

	
	$("#feuille").addClass("inv");
	
	
		$("#feuille1").fadeIn(4000, function(){
			
			$(this).fadeOut(7000);
			
						
			for(i=0; i<5; i++){
				anim(i);
			}
			setTimeout(function(){
				arret();
			
				
		
			},8000);

		});
		
	$("#textes").hide().show(800);
});

