
/*
jQuery plugin : pause resume animation
Created by Joe Weitzel
BOX Creative LLC
http://plugins.jquery.com/project/Pause-Resume-animation
*/
jQuery.fn.startAnimation = function(  params, duration, easing, callback ) {
	jQuery(this).animate( params, duration, easing, callback );
	var data = { target:this.get(0), params: params, duration: duration, easing: easing, callback: callback,
				startTime: new Date().getTime(), timePlayed: 0, timeRemaining: 0 };
	if( !jQuery.pauseableAnimations ) {
		jQuery.extend({ pauseableAnimations: new Array( data ) });
	} else {
		for( var i in jQuery.pauseableAnimations ) {
			if( jQuery.pauseableAnimations[i].target == this.get(0) ) {
				jQuery.pauseableAnimations[i] = data;
			} else {
				jQuery.pauseableAnimations.push( data );
			};
		};
	};
};
jQuery.fn.pauseAnimation = function() {
	if( jQuery.pauseableAnimations ) {
		for(var i in jQuery.pauseableAnimations ) {
			if( jQuery.pauseableAnimations[i].target == this.get(0) ) {
				jQuery(this).stop();
				var now = new Date().getTime();
				var data = jQuery.pauseableAnimations[i];
				data.timePlayed += ( now - data.startTime );
				data.timeRemaining = data.duration - data.timePlayed;
				if( data.timePlayed > data.duration ) {
					var newArray = new Array();
					for( var p in jQuery.pauseableAnimations ) {
						if( jQuery.pauseableAnimations[p] != data ) newArray.push( jQuery.pauseableAnimations[p] );
					};
					jQuery.pauseableAnimations = newArray.length > 0 ? newArray : null;
					delete newArray;
					return this;
				};
				break;
			};
		};
	};
	return this;
};
jQuery.fn.resumeAnimation = function() {
	if( jQuery.pauseableAnimations ) {
		for(var i in jQuery.pauseableAnimations ) {
			var data = jQuery.pauseableAnimations[i];
			if( data.target == this.get(0) ) {
				this.animate( data.params, data.timeRemaining, data.easing, data.callback );
				data.startTime = new Date().getTime();
				return this;
			};
		};
	};
};



$( document ).ready( function()
{
	var orientation	= 1,
		property	= 'top',
		duration	= 35000,
		easing		= 'linear',
		complete	= swapElements;


	var end_value = 0;

	var parent = $( 'div#sidebar .logos' );
		parent.addClass( 'scroll-area' );

	var element = parent.children( 'ul' ),
		clone	= element.clone();

	clone.appendTo( parent );


	end_value = element.outerHeight( true ) * orientation;

	clone.css( property, end_value + 'px' );


	element.startAnimation({ 'top': -end_value + 'px' }, duration, easing, function(){ complete( element ); });
	clone  .startAnimation({ 'top': '0px' },			 duration, easing, function(){ complete( clone ); });


	parent.mouseenter( function(){ element.pauseAnimation();
								   clone  .pauseAnimation(); });

	parent.mouseleave( function(){ element.resumeAnimation();
								   clone  .resumeAnimation(); });



	function swapElements( element )
	{
		var end = -end_value;

		if( element.css( property ) == end + 'px' )
		{
			element.css( property, end_value + 'px' );
			end = 0;
		}

		element.startAnimation({ 'top': end + 'px' }, duration, easing, function(){ complete( element ); });
	}
});

