$(document).ready(function(){

	$("ul#newsteaser").slideMyChildren({ interval: 5000, stopOnHover: true, inverse: false });

});


(function($){
 	$.fn.extend({ 
 		slideMyChildren: function(options) {
			var options =  $.extend({ interval: 10000, speed: 2000, inverse: false, stopOnHover: false }, options);
			var myChildren = this.children();
			var a = 0; var b = myChildren.eq(0).width();
			var i = 0;
			
			if(!options.inverse) {
			//Inverse False
				myChildren.each(function(){
					$(this).css({ "position": "absolute", "top": a, "left": b * i });
					i = i + 1;
				});
			}
			else {
			//Inverse True
				myChildren.each(function(){
					$(this).css({ "position": "absolute", "top": a, "left": b * i });
					i = i - 1;
				});
			}
			
			function myTimerFunction( ) {
				if(!options.inverse) {
				//Inverse False
				myChildren.animate({ "left": "-=" + b + "px" }, options.speed, function(){
					myChildren.each(function(){
						if( parseInt( $(this).css("left") ) < 0 ) $(this).css("left", b * (i - 1));
					});
				});
				}
				else {
				//Inverse True
				myChildren.animate({ "left": "+=" + b + "px" }, options.speed, function(){
					myChildren.each(function(){
						if( parseInt( $(this).css("left") ) >= b ) $(this).css("left", b * (i + 1));
					});
				});
				}
				
			}
			var myTimer = window.setInterval(myTimerFunction, options.interval);
			
			if(options.stopOnHover) {
				this.mouseover(function(){
					window.clearInterval(myTimer);
				}).mouseleave(function(){
					myTimer = window.setInterval(myTimerFunction, options.interval);
				});
    			}
    	}
	});
})(jQuery);



  
