/*
	Horizontal Marquee Class
	Scrolls content horizontally and pauses on rollover
	
	- requires a '<table>' element
	- call the function on the parent element of the '<table>'
	
	example:
		<div class="news_ticker" style="overflow: hidden">
			<div class="news_ticker_marquee">
				<table cellpadding="5px" cellspacing="0">
					<tr>
						<td>Suspendisse pretium ultricies odio sed porta</td>
						<td> | </td>
						<td>Suspendisse potenti fusce non ipsum cursus justo</td>
						<td> | </td>
						<td>Fusce non ipsum cursus justo varius sollicitudin</td>
						<td> | </td>
						<td>Ultricies odio sed porta fusce non ipsum cursus justo varius</td>
					</tr>
				</table>
			</div>
		</div>
		
		<script type="text/javascript">
			HorizontalMarquee.call( $('.news_ticker_marquee') );
		</script>
	
*/
	
	function HorizontalMarquee(durationMultiplier, leadingPixels) {
		
		// set variables
		this.this_width = $(this).width();
		this.table_width = $('table', this).width();
		this.parent_width = $(this).parent().width();
		this.left_position = -(this.table_width) + 'px';
	
		// scroll if there is hidden content
		if ( ($.browser.msie && parseInt($.browser.version, 10) < 8) ||
			 this.table_width > this.this_width ) {		

			// reset back to beginning
			this.onReset = function() {
				$(this).css('margin-left', this.parent_width + 'px');
				this.onAnimate();
			};
			
			// scroll the content
			this.onAnimate = function() {
				$(this).stop(true);
				
				// reset the animation time
				offset = $(this).css('margin-left');
				offset = offset.replace('px', '') * 1;
				duration = ($('table', this).width() + offset) * durationMultiplier;
				$(this).animate({ 'margin-left': -(this.table_width) + 'px' }, duration, 'linear', function() { this.onReset(); } );
			};
			
			// stop on mouse over, start on mouse out
			$(this).hover(
				function() { $(this).stop(true); },
				function() { this.onAnimate(); }
			);
			
			// add some leading space
			$(this).css('margin-left', leadingPixels + 'px');
			
			// start scrolling
			this.onAnimate();
		}
	};


