jQuery.fn.newsRotator = function(options) {
   var settings = jQuery.extend({
     boxtype:"ct", artigo: 0, seccao: 0, divid: '', newscounter:0, totalcounter:0, pglen:0, page: 0
   }, options);
   return jQuery.fn.newsRotator.prepare( jQuery( this ), settings);
 };
jQuery.fn.newsRotator.prepare = function($this, settings){
	var div = jQuery( ".ct", $this );
	var $next = jQuery( "a.nl", $this );
	var $back = jQuery( "a.pl", $this );
	$back.css( "display", "none" );
	var animating = false;
	var currentcount = settings.pglen*(settings.page+1);
	if(settings.totalcounter>currentcount){
		$next.css( "display", "block" );
		$next.click(function() {
			if ( !animating ) {
				animating = true;
				settings.page++;
				$.get("ct/get"+settings.boxtype+".asp", { id: settings.seccao, det: settings.artigo, page: settings.page, pglen: settings.pglen},
				function(data){
					div.fadeOut(1000, function(){
						div.html(data);
						div.fadeIn(1000, function(){$back.css( "display", "block" );});
					});
					animating = false;
				});
				currentcount = settings.pglen*(settings.page+1);
				if(settings.totalcounter<=currentcount){
					$next.css( "display", "none" );
				}
			}
		});
		$back.click(function() {
			if ( !animating ) {
				animating = true;
				settings.page--;
				$.get("ct/get"+settings.boxtype+".asp", { id: settings.seccao, det: settings.artigo, page: settings.page, pglen: settings.pglen},
				function(data){
					div.fadeOut(1000, function(){
						div.html(data);
						div.fadeIn(1000, function(){$next.css( "display", "block" );});
						
					});
					animating = false;
				});
				if(settings.page==0){
					$back.css( "display", "none" );
				}
			}
		});
	}else{
		$next.css( "display", "none" );
	}
};
