var ImgSlider = Class.create({
	element: null,
	options: {
		curdiv: 'bgcurrent',
		curimg: 'img_bgcurrent',
		bg1div: 'bg1',
		bg1img: 'img_bg1',
		bg2div: 'bg2',
		bg2img: 'img_bg2',
		duration: 1
	},
	non_breakable_fx: null,
	
	initialize: function(options) {
		Object.extend(this.options, options);
	  },
	
	slideLeft: function(options)
	{
		var v = $(this.options.curdiv).getDimensions();
	
		$(this.options.bg1div).style.marginLeft="0px";
		$(this.options.bg2div).style.marginLeft=v.width+"px";
		
		
		$(this.options.bg1div).style.display='block';
		$(this.options.bg2div).style.display='block';
		
		that = this;
		
		$(that.options.curimg).src=$(that.options.bg2img).src;
		
		this.non_breakable_fx = new Effect.Parallel([
		  new Effect.Morph(that.options.bg1div, { sync: true, style: 'margin-left: -'+v.width+'px;', transition: Effect.Transitions.linear}), 
		  new Effect.Morph(that.options.bg2div, { sync: true, style: 'margin-left: 0px;', transition: Effect.Transitions.linear}) 
		], { 
		  duration: this.options.duration,
		  delay: 0,
		  afterFinish: function()
		  {
			  $(that.options.curimg).src=$(that.options.bg2img).src;
			  $(that.options.bg1img).src=$(that.options.curimg).src;
			  
			  $(that.options.bg1div).style.display='none';
			  $(that.options.bg2div).style.display='none';
			  
			  that.non_breakable_fx = null;
			  
			  if(options.afterFinish != undefined)
			  {
				  options.afterFinish();
			  }
		  }
		});
	},
	
	slideRight: function(options)
	{
		var v = $(this.options.curdiv).getDimensions();
		
		$(this.options.bg1div).style.marginLeft="0px";
		$(this.options.bg2div).style.marginLeft="-"+v.width+"px";
		
		
		$(this.options.bg1div).style.display='block';
		$(this.options.bg2div).style.display='block';
		
		that = this;
		
		$(that.options.curimg).src=$(that.options.bg2img).src;
		
		this.non_breakable_fx = new Effect.Parallel([
		  new Effect.Morph(that.options.bg1div, { sync: true, style: 'margin-left: '+v.width+'px;', transition: Effect.Transitions.linear}), 
		  new Effect.Morph(that.options.bg2div, { sync: true, style: 'margin-left: 0px;', transition: Effect.Transitions.linear}) 
		], { 
		  duration: this.options.duration,
		  delay: 0,
		  afterFinish: function()
		  {
			  $(that.options.curimg).src=$(that.options.bg2img).src;
			  $(that.options.bg1img).src=$(that.options.curimg).src;
			  
			  $(that.options.bg1div).style.display='none';
			  $(that.options.bg2div).style.display='none';
			  
			  that.non_breakable_fx = null;
			  
			  if(options.afterFinish != undefined)
			  {
				  options.afterFinish();
			  }
			  
		  }
		});
	},
	
	nextBild: function(bildpfad, options)
	{
		$(this.options.bg2img).src=bildpfad;
		var m = this.slideLeft.bind(this);
		m(options);
	},
	
	prevBild: function(bildpfad, options)
	{
		$(this.options.bg2img).src=bildpfad;
		var m = this.slideRight.bind(this);
		m(options);
	}
	
	
});
