/*
Script banner 1.0.1
2009 djm Web sprl

Need jQuery 1.3.2
*/
jQuery.noConflict();
banner_djm = function(banner,time) {
	this.banner = banner;
	this.time = time*1000;
	this.init();
	}
jQuery.extend(banner_djm.prototype, {
	init: function() {
		var obj = this;
		var nbreImg = jQuery(this.banner + ' img').length;
		var nbreImgBlc = 0;
		jQuery(this.banner).addClass('waiting_banner');
		jQuery(this.banner + ' img').css('display','none');
		jQuery(this.banner + ' img').load( function() {
			jQuery(document.createElement("div")).css({
				'background' : 'url(' + jQuery(this).attr('src').replace(/ /g,'%20').replace(/\(/g,'%28').replace(/\)/g,'%29') + ') no-repeat center center',
				'width' : jQuery(obj.banner).width()+'px',
				'height' : jQuery(obj.banner).height()+'px',
				'position' : 'absolute',
				'z-index' : '0',
				'display' : 'none'
				}).appendTo(obj.banner);
			jQuery(this).remove();
			nbreImgBlc++;
			if (nbreImgBlc==nbreImg) {	
				if (nbreImg>1) {
					obj.init_anime();
					}
					else {	
						jQuery(obj.banner + ' div').fadeIn(500, function() {
							jQuery(obj.banner).removeClass('waiting_banner');			
							});		
						}
				}
			});
		},
	init_anime: function() {
		var obj = this;
		//Defini la derniere
		jQuery(this.banner + ' div:last').addClass('last');
		//Commence aléatoirement
		var nombreAlea = Math.floor(Math.random() * jQuery(this.banner + ' div').length)+1;
		this.alea_start(jQuery(this.banner + ' div:first'),jQuery(this.banner + ' div:first').next(),0,nombreAlea);		
		},
	anime_ban: function(objP, objN, objD) {
		var obj = this;
		//Applique le niveau des images
		objP.css('z-index','2');
		objN.css('z-index','1');
		if (objD!=0) {
			objD.css('z-index','0');
			objD.css('display','block');
			}
		//Anime les images
		objP.fadeOut(500);
		//Attribue les images suivantes
		objD = objP;
		objP = objN;
		if (objN.attr('class') == 'last') {
			objN = jQuery(this.banner + ' div:first');
			}
			else {
				objN = objN.next();
				}
		//Boucle l'animation
		setTimeout(function() {
			obj.anime_ban(objP, objN, objD);
			}, this.time);
		},
	alea_start: function(objP, objN, objD, alea) {		
		var obj = this;
		//Boucle un nombre aleatoire
		for (i=1; i<=alea;i++) {			
			if (i==alea) {
				//Applique le niveau des images
				objP.css('z-index','2');
				objN.css('z-index','1');
				if (objD!=0) {
					objD.css('z-index','0');
					}
				//Anime le premier
				objP.fadeIn(500, function() {
					jQuery(obj.banner + ' div').css('display','block');
					jQuery(obj.banner).removeClass('waiting_banner');
					setTimeout(function() {
						obj.anime_ban(objP,objN,objD);
						}, obj.time);
					});	
				}
				else {
					//Attribue les images suivantes
					objD = objP;
					objP = objN;
					if (objN.attr('class') == 'last') {
						objN = jQuery(this.banner + ' div:first');
						}
						else {
							objN = objN.next();
							}
					}				
			}			
		}
	});