var MSM_Animation = new Class({
	options:{
		images_path:null,
		contid:null,
		elt_start:null,
		elt_stop:null,
		elt_next:null,
		elt_previous:null,
		video:null
	},
	// implements:[new Option, new Event],
	initialize:function(options){
		this.setOptions(options);
		this.timer = 0;
		this.current_img = 0;
		
		this.images = new Asset.images(this.options.images_path,{
			onProgress:function(index){
				if(index>0){
					this.setStyle('opacity',0);
				}
				this.inject(document.getElementById('animation'));
			},
			onComplete:function(){
				this.start_anim();
			}.bind(this)
		});
		this.fx = new Fx.Elements(this.images,{duration:1000});
		$(this.options.elt_start).addEvent('click',function(){ 
			if ($(this.options.video)) {
				$(this.options.video).setStyle('display', 'none');
			};
			$('img_recept').setStyle('display', 'block');
			$(this.options.elt_start).addClass('selected');
			$(this.options.elt_stop).removeClass('selected');
			this.start_anim();
		}.bind(this));
		$(this.options.elt_stop).addEvent('click',function(){
			if ($(this.options.video)) {
				$(this.options.video).setStyle('display', 'block');
			};
			$('img_recept').setStyle('display', 'none');
			this.stop_anim();
		}.bind(this));
		// 	$(this.options.elt_next).addEvent('click',function(){ this.stop_anim();this.next_img(); }.bind(this));
		// 	$(this.options.elt_previous).addEvent('click',function(){ this.stop_anim();this.previous_img(); }.bind(this));
		
	},
		
	show:function(index){
		var fxElts = {};
		if(index>=this.images.length){
			index = 0;
		}else if(index<0){
			index = this.images.length-1;
		}
		for(var i=0;i<this.images.length;i++){
			fxElts[i] = (i==index)? {opacity:1}:{opacity:0};
		}
		this.fx.cancel();
		this.current_img = index;
		return this.fx.start(fxElts);
	},
	
	period:function(){	
		this.current_img += 1;
		this.show(this.current_img);
	},
	
	start_anim:function(){ this.timer = this.period.periodical(3000,this); },
	stop_anim:function(){ 
		$(this.options.elt_stop).addClass('selected');
		$(this.options.elt_start).removeClass('selected');
		$clear(this.timer);
	},
	next_img:function(){ this.stop_anim(); this.show(++this.current_img); },
	previous_img:function(){ this.stop_anim(); this.show(--this.current_img); }
});

MSM_Animation.implement(new Options,new Events);

var path = "/";

var paths = [
	path+"images/illustration/illustration3.jpg",
	path+"images/illustration/illustration1.jpg",
	path+"images/illustration/illustration2.jpg",
	path+"images/illustration/illustration4.jpg"
];

window.addEvent('domready',function(){
	msm_anim = new MSM_Animation({
		images_path:paths,
		contid:'animation',
		elt_start:'start',
		elt_stop:'stop',
		elt_next:'next',
		elt_previous:'previous',
		video:'msm_video'
	});	
});

