var something = null;
var xSlide = new Class({
	
	target : null,
	duration : 300,
	container : null,
	amount : null,
	time : 3000,
	timer : null,
	direction : 'left',
	currentSlide : 0,
	
	initialize : function( options ) {
		for( var key in options )
			this[key] = options[key];
		if( this.target != null ){
		this.target.setStyles({
			position : 'relative',
			overflow : 'hidden',
			width: slidewidth,
			height: 271
		});
		this.container = new Element( 'div', {
			styles : {
				position : 'absolute',
				top : 0,
				left : 0,
				width : this.target.getChildren().length * this.amount
			}
		});
		$each( this.target.getChildren(), function( item ) {
			item.setStyle( 'float', 'left' );
			item.injectInside( this.container );
		}.bind( this ));
		this.container.injectInside( this.target );
		this.amount = this.target.getSize().x;
//		alert(this.target.getChildren()[0].getChildren().length);
		if ( this.target.getChildren()[0].getChildren().length > 1 ) {
			this.start();
		}
		}
	},
	
	start : function() {
		this.timer = this.slide.periodical( this.time, this );
	},
	
	stop : function() {
		$clear( this.timer );
	},
	
	slide : function() {			
		new Fx.Morph( this.container, { duration : this.duration } ).start({
			left : this.container.getStyle( 'left' ).toInt() - this.amount
		}).chain( function() {
			this.container.getChildren()[0].injectInside( this.container );
			this.container.setStyle( 'left', 0 );
		}.bind( this ));
	}
})

window.addEvent( 'domready', function() {
	function test() {
		if( something )
			something.stop();
		something = new xSlide({
			target : $('x-fade'),
			amount : slidewidth,
			time : 7000
		})
	}
	test();
	try {
		MT.EDITOR.addEventListener( MT.EDITOR.FRAGMENT_RELOADED, test );
	} catch( e ){}
})