var SliceGallery = new Class({
    
    //implements
    Implements: [Options] ,
    
    //options
    options: {
        container: $$('body')[0],
        callback: null,
        path: './',
        progressBar: null
    }, 
    
    //initialization
    initialize: function(options) {
            //set options
            this.setOptions(options);
            this.images = [];
            this.fullPathImages = [];
    } 
    ,
    preload: function(){
        var req = new Request({
            url: 'file_retriever.php?p='+this.options.path,
            onSuccess: function(response) {
               
                var ret = JSON.decode(response);
                if (ret.code == 1){
                    this.images = ret.files;
                    ret.files.each(function(im){
                        //alert(this.options.path + '/' + im);
                        this.fullPathImages.include(this.options.path + '/' + im); 
                    }.bind(this));
                    
                    this.load();
                }
            }.bind(this),
            onFailure: function(){
		//alert("falhou");
	    }
        });
        
        req.send();

    } 
    ,
   
    load: function() {
        var loadOptions = {
            
            onProgress: function(counter, index) {  
                this.options.progressBar.set((counter + 1) *
                                             (100 / this.images.length));  
            }.bind(this),
            
            onComplete: function() {
               this.images.each(function(im){
                    var slideClass;
                    
                    /**  parametrizar depois */
                    if (im.substring(0,1) == 'E'){
                        slideClass = 'slideEsquerda';
                    }else if(im.substring(0,1) == 'C'){
                        slideClass = 'slideCentro';
                    }else if(im.substring(0,1) == 'D'){
                        slideClass = 'slideDireita';
                    }

			  var divElement =
                        new Element('div',{'class' : slideClass}).
                            inject(this.options.container);
                    new Element('img',{src:this.options.path + '/' + im}).inject(divElement); 
                }.bind(this));
               
                
                this.options.callback.run();
            }.bind(this)
        };
        
        loader = new Asset.images(this.fullPathImages, loadOptions);
         
    }

});
