(function( $ ){
  
	var methods = {
		init : function( options ) {},
		show : function(){
			this.animate({
				opacity: 1,
				left: 0
			}, 10000, function(){
				// animation complete
				$this = $('#'+this.id);
				$next = $this.is($this.parent().children().last()) ? $this.parent().children().first() : $this.next() ;
				$this.delay(1000).scroller('hide');
				$next.delay(1000).scroller('show');
			});
		},
		hide : function(){
			this.animate({
				opacity: 0,
				left: 0-this.parent().width()
			}, 10000, function(){
				// animation complete
				$this = $('#'+this.id);
				$this.css('left',$this.parent().width());	
			});
		}
	};

	$.fn.scroller = function( method ) {
		// Method calling logic
		if ( methods[method] ) {
			return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.scroller' );
		}    
	};  
  
})( jQuery );

jQuery(document).ready( function(){
	
	// Slideshow
	var $sw = $('#scroller_wrap');
	$sw.css('display','block');
	$sw.css('position','relative');
	$sw.css('overflow','hidden');

	//transfer elelemts to the container	
	$('span.scroller_msg').each(function(){
		$this = $('#'+this.id);
		$this.css('left',$sw.width()+'px');
		$this.css('width',$sw.width()+'px');
		$this.css('position','absolute');
		$this.css('opacity',0);
		$this.css('display','block');
		$sw.append($this);
	});

	//$sw.find('span.scroller_msg').first().scroll();
	$sw.children().first().scroller('show');

});


