var GalleryJs = new Class({
		options : {
				aImages :  [],
				
				sVignette : "",
				sShowPicture:"",
				sLoading:'', 
				iIdFisrt : ''
			},
   		initialize: function(options){
   			// variables
   			this.setOptions(options);
   			this.iCountLoaded 	= 0;
   			this.iPourcent 			= 0;
       		this.oVignette = $(this.options.sVignette);
       		this.oShowPicture = $(this.options.sShowPicture);
       		this.oLoading =$(this.options.sLoading);  
       		this.aImagesLoaded = [];
			
       		if (this.options.aImages.length > 0) {
       			var oGallery = this;
       			var begining = false;
	   			this.Asset = new Asset.images(this.options.aImages, {
	   			
					onComplete: function () { // GALLERY LOADING IS COMPLETE -----------------------------------
						if (begining != true) {
							oGallery.DisplayGalerie();
						}
					}.bind(this),
					onProgress:function(i) { // GALLERY LOADING  PROGRESS ----------------------------------------
						oGallery.iCountLoaded++;
						oGallery.iPourcent = (oGallery.iCountLoaded/oGallery.options.aImages.length)*100;
						oGallery.UpdateLoading();
						oGallery.aImagesLoaded[i] = this;
						
						if (parseInt(oGallery.iPourcent)> 80 && begining != true) {
							
							oGallery.DisplayGalerie();
							begining = true;
						}
					}			
	   			});
	   		}
   		},
   		DisplayGalerie:function() {

   			var oShowPict = $('showpicture');
			var aDiv = oShowPict.getElements("div");
			var iIChain = 0;
			var runChain = function() { 
				ChangeShowedPicture(aDiv[iIChain].getProperty('id'));
				iIChain++;
				if (iIChain > aDiv.length-1) {
			 		iIChain = 0;
				}
				
			}
			iIChain = 0;
			var aHref  = $$('div.clicpicture a');
			aHref.each(function(a) {
				a.addEvent("mouseover",function() {
						$clear(timer);
						ChangeShowedPicture("gallery_"+this.id);
				});
				a.addEvent("mouseout",function() {
					timer = runChain.periodical(6000);
				});
			});
			var timer = runChain.periodical(6000);
			
   			ChangeShowedPicture("gallery_"+this.options.iIdFisrt);
   		},
   		UpdateLoading:function () {
   			this.oLoading.innerHTML = " Loading " + parseInt(this.iPourcent) + " % ";
   		}
});
GalleryJs.implement(new Options);
