(function($)
{
	$.fn.sliders = function()
	{
		var prefix = this.attr( 'id' );
		var elements = [];
		$('#news_sliders').children().each(function( index, item )
		{
			if( $(item).attr( 'class' ).search( prefix ) != -1 )
			{
				elements.push( $(item) );
			}
		});

		this.animOver = function( index, el )
		{
			//$(".slider .content")
			
			var top = el.position().top;
			var al = elements[index];
			if( top + al.height() > al.parent().height() )
			{
				top -= ( top + al.height() - al.parent().height() )
			}
			al.css('top', top );
			
			al.stop();
			
			var right = -686;
			var step = 1 - (Math.abs(parseInt(al.css("right")))/Math.abs(right));
			var initAni = true;
			
			
			
			al.animate({
				right:0
			}, { 
				easing: 'linear',
				duration: 2000,
				step: function(a, b){
					
					
					if(initAni == true){
						
						b.start = right;
						
						b.startTime = b.startTime - (b.options.duration * step);
						
						//b.startTime = b.startTime - 1200;
						
						initAni = false;
						return b;
					}
				}
			});
		};
		
		this.animOut = function( index, el )
		{	
			
			elements[index].stop();
			
			var right = 0;
			var step = 0;
			if(Math.abs(right) == 0){
				var step = 1 - (Math.abs(parseInt(elements[index].css("right")))/Math.abs(right));
			}
			var initAni = true;
			
			elements[index].animate({
				right:-(elements[index].width()+1)
			},{ 
				easing:'linear',
				duration: 2000,
				step: function(a, b){
					if(initAni == true){

						b.startTime = b.startTime - (b.options.duration * (b.state));

						initAni = false;
						return b;
					}
				}
			} );
			
			
		}.moo_bind( this );


		this.children('li').each(function( index, item )
		{
			var array = null;
			if( ( array = $(item).children('a') ) != null )
			{
				var a = $(array[0]);
				a.mouseenter(function( e )
				{
					this.animOver( index, a );
				}.moo_bind( this ));
				
				elements[index].mouseenter(function( e )
				{
					this.animOver( index, a );
				}.moo_bind( this ));
				
				a.mouseleave(function( e )
				{
					this.animOut( index, a );
				}.moo_bind( this ));
				
				elements[index].mouseleave(function( e )
				{
					this.animOut( index, a );
				}.moo_bind( this ));
			}
		}.moo_bind( this ));
	};
})(jQuery);
