
/*
 *
 *
 *  $("outmatcher").scrollx( "innermatcher", scrolling_speed, scrolling_length, scrolling_stop_time, rewind_speed );
 *
 */ 

jQuery.fn.scrollx = function( child, speed, jump, stop, rewind)
{ 
				var xparent = this;
				var parentheight = jQuery(this)[0].offsetHeight;
				var childheight  = jQuery(child)[0].offsetHeight;
				var max_offset = (childheight - parentheight );
				if( max_offset < 0 ){
					max_offset = 0;
				}

				jQuery(child)[0].anim = function()
				{
					var current_offset =  jQuery(this).css("margin-top").replace("px","");
					var next_offset = ( 0 - (( 0 - current_offset ) + jump )) ;
					//console.log( current_offset + " -> " + next_offset + " == " + max_offset  );
					if ( current_offset < ( 0 -  max_offset ) )
					{
						jQuery(child).animate({marginTop: "0px" }, rewind, function(){
								jQuery(child).css("height",childheight);
								jQuery(child).css("margin-top","0px");
								setTimeout( function(){ 
									jQuery(child)[0].anim();	
								}, stop );
						});
					}
					else
					{	
						jQuery(child).animate({marginTop: "-" + jump +"px"}, speed, function(){
							setTimeout( function(){
								jQuery(child)[0].anim();
							}, stop );
						});
					}
				}
				setTimeout(function(){
						jQuery(child)[0].anim();
					}, stop );

			
			}

