/*

	----------------------------------------------------------------------------------------------------
	Accessible News Slider
	----------------------------------------------------------------------------------------------------
	
	Author:
	Brian Reindel
	
	Author URL:
	http://blog.reindel.com

	License:
	Unrestricted. This script is free for both personal and commercial use.

*/
var firstTime=1;
jQuery.fn.accessNews = function( settings ) {
	settings = jQuery.extend({
        headline : "Top Stories",
        speed : "normal",
		slideBy : 1,
		delay	: 5000
    }, settings);
    return this.each(function() {
		jQuery.fn.accessNews.run( jQuery( this ), settings );
    });
};

jQuery.fn.accessNews.run = function( $this, settings ) {
	jQuery( ".javascript_css", $this ).css( "display", "none" );
	var ul = jQuery( "ul:eq(0)", $this );
	var li = ul.children();
	if ( li.length > settings.slideBy ) {
		var liWidth = jQuery( li[0] ).width();
		var animating = false;
		ul.css( "width", ( li.length * liWidth ) );
			animating = true;
			offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
			if(firstTime>1){
			if ( offsetLeft + ul.width() > 0 ) {
				ul.animate({
					left: offsetLeft
				}, settings.speed, function() {
					animating = false;
				});
			} else {
				animating = false;
			}
			
			if ( !animating ) {
				 offsetRight = 0;
				 //ul.css("left", offsetRight);	
					ul.animate({
						left: offsetRight
					}, 0, function() {
						
						animating = false;
					});
			
			}
		}
		var timeout;
		timeout = setTimeout(function(){
			jQuery.fn.accessNews.run($this, settings);
		},settings.delay);		
		
		
		firstTime++;
	}
};
