var Platen = new Class({
	Implements: [Options,Events],
    initialize: function(options){
				
						this.setOptions(options);
						
						this.images 	  = this.options.images;
						this.currentimage = this.options.currentimage;
						
						this.imagesarr 	= [];
						this.images.each(function(item){ 
							this.imagesarr.include(item.img);
						}.bind(this));
						this.images 	= this.imagesarr;
						
						$('next').getElement('a').addEvent('click', function(e) { 
							e.stop();
							this.gotonext();			
						}.bind(this));
						
						$('prev').getElement('a').addEvent('click', function(e) { 
							e.stop();
							this.gotoprev();	
						}.bind(this));	
						
						$('case').setStyle('overflow','hidden');
									
						this.loadimages();
						
						uri = new URI($('next').getElement('a').get('href'));
						this.basefragment = uri.get('directory');
						
						$('case').setStyle('background','none');
						$('case').empty();
						$('case').set('opacity',0);
    
				}, 
	
	loadimages: function() {
		
		var myImages = new Asset.images(this.images, {
			'onProgress': function(counter,index){ 

			}.bind(this), 
			'onComplete': function(){ 
				
				this.slide  = new Element('div', { 'id': 'slide', 'styles': { 'width': this.images.length * 640, 'left': this.currentimage*-640 } }).inject($('case'));
				this.slider = new Fx.Morph(this.slide, {duration: 500, transition: Fx.Transitions.Cubic.easeInOut});
				this.images.each(function(item,index){ 
					new Element('img', {'src': '/images/werk/'+ item, 'styles': {'left': index * 640 } }).inject(this.slide);			
				
				$('case').set('opacity',0);
				$('case').fade('in');
				
				}.bind(this));
			}.bind(this)
		});
	},
	
	gotonext: function(){
		
		if(this.currentimage < this.images.length -1) { 
			this.currentimage++;
		} else { 
			this.currentimage = 0;
		}
		this.doslide();
	},
	
	gotoprev: function() {
		if(this.currentimage > 0) { 
			this.currentimage--;
		} else { 
			this.currentimage = this.images.length -1;
		}
		this.doslide();	
	},
	
	doslide: function() {	
		
		this.slider.start({ 'left': this.currentimage*-640 });
		$('inloop').set('text',this.currentimage+1 + ' / ' + this.images.length);

		url = this.basefragment + (this.currentimage + 1);
		uri = new URI('/');
		uri.set('fragment',url);
		uri.go();
		$(document.body).set('page',url);
		
	}
});
