var Picture = new Class({
	
	path: ROOT_URL+'upload/images/',
	dir: '',
	
	Implements: [Options, Events],
	
	options: {
		container: null,
		infos: null,
		work_id: 0
	},
	
	initialize: function(options) {
		this.setOptions(options);
		
		this.init();
		
	},
	
	init: function() {
		this.initElements();
		
		this.initFx();

		this.total = 0;
		for(img in this.options.infos) {
			if(parseInt(img) || img == 0) {
				this.total ++;
			}
		}

		this.current = parseInt(this.options.infos.current);
		this.loadImage(this.current);
	},
	
	initElements:function() {
		
	},
		
	initFx: function() {
		this.fx = new Fxable({
			target: this.fx_target,
			type: 'opacity',
			src: '0',
			dest: '1',
			duration:300,
			link:'cancel'
		});
		
		this.bound_laod_close_complete = this.loadCloseComplete.bind(this);
		
		this.fx.setClose();
		
		this.cont_fx = new Fx.Morph(this.cont, {
			duration: 300
		});
		this.cont.addClass('loader');
		this.cont_fx.addEvent('complete', this.contComplete.bind(this));
	},
	
	loadImage:function(index) {
		this.next_index = parseInt(index);
		this.fx.addEvent('complete', this.bound_laod_close_complete);
		this.fx.close();
	},
	
	loadCloseComplete: function() {
		//this.cont.addClass('loader');
		this.fx.removeEvent('complete', this.bound_laod_close_complete);
		src = this.path + this.dir + this.options.infos[this.next_index].md5;
		this.asset = new Asset.images(src, {
			onComplete : this.loaded.bind(this)
		});
	},
	
	loaded:function() {
		this.current = this.next_index;
		this.updateImage();
		//this.resize();
		//this.cont.removeClass('loader');
		this.initLinks();
		this.fireEvent('imageloaded', {uri: 'work='+this.options.work_id+'&img='+this.options.infos[this.current].id});
	},
	
	resize: function(){
		return false;
	}
});
