jQuery.fn.accessNews = function( settings ) {
	settings = jQuery.extend({
        headline : "Top Stories",
        speed : "normal",
		slideBy : 2
    }, 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 $next = jQuery( ".next");
		var $back = jQuery( ".back");
		var liWidth = jQuery( li[0] ).width();
		var animating = false;
		ul.css( "width", ( li.length * 58 ) );
		$back.css( "display", "block" );
		
		$next.click(function() {
							
			if ( !animating ) {
				animating = true;
				offsetLeft = parseInt( ul.css("left") ) - ( 348 );
				//alert(ul.css( "left" ) + "----" + ( liWidth));
				if ( offsetLeft + ul.width() > 0 ) {
					
					$back.css( "display", "block" );
					ul.animate({
						left: offsetLeft
					}, settings.speed, function() {
						
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		$back.click(function() {
			if ( !animating ) {
				animating = true;
				offsetRight = parseInt( ul.css( "left" ) ) + ( 348 );
				if ( offsetRight + ul.width() <= ul.width() ) {
					$next.css( "display", "block" );
					ul.animate({
						left: offsetRight
					}, settings.speed, function() {
						
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		
	}
};



//VERTICAL SLIDER


jQuery.fn.accessNewsVertical = function( settings ) {
	settings = jQuery.extend({
        headline : "Top Stories",
        speed : "normal",
		slideBy : 2
    }, settings);
	

	
    return this.each(function() {
		jQuery.fn.accessNewsVertical.run( jQuery( this ), settings );
    });
};
jQuery.fn.accessNewsVertical.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 $nextVertical = jQuery( ".nextVertical");
		var $backVertical = jQuery( ".backVertical");
		var liHeight = jQuery( li[0] ).height();
		var animating = false;
		ul.css( "height", ( li.length * 49 ) );
		$backVertical.css( "display", "block" );
		
		$nextVertical.click(function() {
			
			if ( !animating ) {
				animating = true;
				offsetTop = parseInt( ul.css( "top" ) ) - ( 262 );
			
				if ( offsetTop + ul.height() > 0 ) {
					
					$backVertical.css( "display", "block" );
					ul.animate({
						top: offsetTop
					}, settings.speed, function() {
					
						
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		$backVertical.click(function() {
									 
			if ( !animating ) {
				animating = true;
				offsetBottom = parseInt( ul.css( "top" ) ) + ( 262 );
			
				if ( offsetBottom + ul.height() <= ul.height() ) {
					$nextVertical.css( "display", "block" );
					ul.animate({
						top: offsetBottom
					}, settings.speed, function() {
					
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		
	}
};


//SLIDER VERTICAL PARA LOS BREVES

jQuery.fn.accessNewsVerticalBreve = function( settings ) {
	settings = jQuery.extend({
        headline : "Top Stories",
        speed : "normal",
		slideBy : 2
    }, settings);
	
	
	
    return this.each(function() {
		jQuery.fn.accessNewsVerticalBreve.run( jQuery( this ), settings );
    });
};
jQuery.fn.accessNewsVerticalBreve.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 ) {
		//alert();
		var $nextVertical = jQuery( ".nextVerticalBreve");
		
		var $backVertical = jQuery( ".backVerticalBreve");
		
		var liHeight = jQuery( li[0] ).height();
		var animating = false;
		ul.css( "height", ( li.length * 90 ) );
		$backVertical.css( "display", "block" );
		
		$nextVertical.click(function() {

			if ( !animating ) {
				animating = true;
				offsetTop = parseInt( ul.css( "top" ) ) - ( 355 );
			
				if ( offsetTop + ul.height() > 0 ) {
					
					$backVertical.css( "display", "block" );
					ul.animate({
						top: offsetTop
					}, settings.speed, function() {
					
						
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		$backVertical.click(function() {
									 
			if ( !animating ) {
				animating = true;
				offsetBottom = parseInt( ul.css( "top" ) ) + ( 355 );
			
				if ( offsetBottom + ul.height() <= ul.height() ) {
					$nextVertical.css( "display", "block" );
					ul.animate({
						top: offsetBottom
					}, settings.speed, function() {
					
						animating = false;
					});
				} else {
					animating = false;
				}
			}
			return false;
		});
		
		
	}
};
