(function($) {
		  
	$.fn.jcarbanner = function(o) {
	
	o = $.extend({
			btnPrev: null,
			btnNext: null,
			ctPos: null,
			time: 3000,
			speed: 'slow',
			easing: 'easein',
			fading: true,
            fadingSpeed: 'fast',
			usecolor: false,
			parentBG: null,
            noSlide: false
		}, o || {});
	
	return this.each(function() {
		
		var div = $(this);
		div.parent().css({ 'display'	:	'block' });
		var li = $('li',div );
		var ul = div.find('ul').first();
	
		var totalLi = div.find('li').length;
		var liWidth = div.find('li').width();
		var totalWidth = totalLi * liWidth;		
		
		div.css ({ 'margin'	:	0 , 'padding'	:	0 , 'overflow'	: 'hidden' , 'display'	:	'block' , 'position'	:	'relative', 'z-index' : 9999, 'height' :  li.height() });
		li.css({ 'float'	:	'left' });
		ul.css({ 'position' : 'absolute' , 'height'	: 'auto' });
		ul.width(totalWidth);
		
		if ( o.fading == true ){
			$('li',ul).animate({ opacity: 0 },o.fadingSpeed);
			$('li',ul).first().animate({ opacity:1.0}, o.fadingSpeed);
		}
		
					
		var x = 0;
		var pos = 1;
		var posLocal = 0;
		var tempo = o.time;
		var t = 0;
		
		if (o.ctPos) {
			o.ctPos.append('<ul></ul>');
			for ( i = 0; i < totalLi; i++ ){
				o.ctPos.find('ul').append('<li><span>' + (i + 1) + '</span></li>');	
			}
			o.ctPos.find('ul').find('li').first().addClass('active');
			var posTotalLi = o.ctPos.find('li').length;
			var posLiWidth = o.ctPos.find('li').width();
			var posTotalWidth = posTotalLi * posLiWidth;
			o.ctPos.css({ 'display' : 'block' });
			o.ctPos.find('ul').width(posTotalWidth);
			o.ctPos.find('ul').css({ 'overflow'	: 'hidden', 'height'	: 'auto' });
			o.ctPos.find('ul').find('li').css({ 'float'	:	'left', 'display'	:	'block', 'cursor' : 'pointer'});
			o.ctPos.find('ul').find('li').each( function () {
				$(this).click( function () {
					clearTimeout(t);
					var direcao = 0;
					if ( pos < $(this).find('span').text() ) {
						direcao = -1;
					}
					else {
						direcao = 1;
					}

					pos = $(this).find('span').text();
			
					if ( direcao == -1 ){
						var position = -(liWidth * pos) + liWidth;
					} else if ( direcao == 1 ) {
						var position = ((liWidth * pos) - liWidth) * -1;
					}
			
					goto(position);								 
				});
	
			});
		}
	
		if (o.btnPrev) {
			o.btnPrev.click( function () {
				if ( pos > 1 ){
                    if ( o.noSlide ) {
                        ul.css({ 'margin-left' : (posLocal - div.offset().left ) + liWidth });
                         posLocal = ul.offset().left;  pos--; checagem(); 
                    } else {
                        ul.animate({ marginLeft: (posLocal - div.offset().left ) + liWidth },o.speed, function () { posLocal = ul.offset().left;  pos--; checagem();   });
                    }
				} else {
					$(this).addClass('disabled');
				}								  
			});
		}
		if (o.btnNext) {
			o.btnNext.click( function () {
				if ( pos < totalLi ){
					if ( o.fading == true) {
						if ( pos == totalLi - 1 ){
							$('li',ul).first().animate({opacity : 0.2 }, o.fadingSpeed); 	
						}
					}
                    if ( o.noSlide ) {
                        ul.css({ 'margin-left' : -(liWidth * pos) });
                        posLocal = ul.offset().left;
                        pos++;
                        checagem();
                    } else {
				    	ul.animate({ marginLeft: -(liWidth * pos) },o.speed, function () { posLocal = ul.offset().left; pos++; checagem();   });
                    }
				} else {
					$(this).addClass('disabled');
				}
			});
		}
	
		function checagem() {
			o.ctPos.find('.active').removeClass('active');
			o.ctPos.find('li:nth-child(' + (pos) + ')').addClass('active');
			var liAtual = $('li:nth-child('+ (pos) +')',ul);
			if ( o.fading == true) {
				$('li',ul).animate({opacity : 0 }, o.fadingSpeed); 
				liAtual.animate({opacity : 1 },o.fadingSpeed);
			}
			if ( o.usecolor == true ){
				o.parentBG.animate({ backgroundColor : liAtual.attr('rel') },'fast');
			}
			clearTimeout(t);
			time();
		}
		
		function goto(xpos) {
            if ( o.fading ) {
                 var liAtual = $('li:nth-child('+ (pos) +')',ul);
                 liAtual.animate({opacity : 0 },o.fadingSpeed, function () {
                    if ( o.noSlide ) {
                        ul.css({ 'margin-left' : xpos });
                        posLocal = ul.offset().left; checagem();
                    } else {
                        ul.animate({ marginLeft: xpos },o.speed, function () { posLocal = ul.offset().left; checagem();  });
                    }
                });
            } else {
                if ( o.noSlide ) {
                    ul.css({ 'margin-left' : xpos });
                    posLocal = ul.offset().left; checagem(); 
                } else {
                    ul.animate({ marginLeft: xpos },o.speed, function () { posLocal = ul.offset().left; checagem();  });		
                }
            }
		}
		
		function time () {
			t = setTimeout(function () { if ( pos < totalLi ) { 
											 if ( o.fading ) {
                                              var liAtual = $('li:nth-child('+ (pos) +')',ul);
                                              liAtual.animate({opacity : 0 },o.fadingSpeed, function () {
                                                  if ( o.noSlide ) {
                                                      ul.css({ 'margin-left' : -(liWidth * pos) });
                                                      posLocal = ul.offset().left; pos++; checagem();
                                                 } else {
                                                      ul.animate({ marginLeft: -(liWidth * pos) },o.speed, function () { posLocal = ul.offset().left; pos++; checagem();  });
                                                 }                                         
                                              });
                                             
                                             } else {
                                                if ( o.noSlide ) {
                                                     ul.css({ 'margin-left' : -(liWidth * pos) });
                                                     posLocal = ul.offset().left; pos++; checagem();
                                                } else {
                                                    ul.animate({ marginLeft: -(liWidth * pos) },o.speed, function () { posLocal = ul.offset().left; pos++; checagem();  });
                                                }
                                             }
											 } else { goto(0); pos = 1; }  }, tempo);
		}
		
		time();
		
		});			
		}
	
})(jQuery);

