jQuery.fn.ListaDestaques = function (options) {
	
	var opts = jQuery.extend({
		timer: 4000,
		animSpeed: "normal",
		autoPlay: true,
		classAt: "ativo",
		classOver: "",
		typeEffect: "fade" //fade, slide
	}, options);
	
	this.each(function(){
		
		//Configs iniciais
		var Interval;
		var Father		= jQuery(this);
		var selItem		= 1;
		var nItens 		= jQuery(".dstItem", Father).size();
		var activePage 	= true;
		
		jQuery('.dstItem', Father).hide();
		//jQuery('.dstItem:first', Father).show();
		
		jQuery(".dstItens", Father).css('position', 'relative');
		jQuery('.dstItem', Father).css('position', 'absolute');
		
		//----------------
		
		//Funcoes		
		function showDst (n){
			if (opts.autoPlay) { stopDst(); }
			
			$item = jQuery(".dstItem", Father);
			$currItem = jQuery(".dstItem:eq("+(n-1)+")", Father);
			
			if(opts.typeEffect=='fade'){
				$item.fadeOut(opts.animSpeed);
				$currItem.fadeIn(opts.animSpeed);
			} else if(opts.typeEffect=='slide'){
				$item.slideUp(opts.animSpeed);
				$currItem.slideDown(opts.animSpeed);
			}
			
			selItem = n;
			jQuery(".btRpt", Father).removeClass(opts.classAt);
			jQuery(".btRpt:eq("+(n-1)+")", Father).addClass(opts.classAt);
			if (opts.autoPlay) { playDst(opts.timer); }
		}
		
		function nextDst () {			
			if (selItem > nItens-1) {
				n = 1;
			} else {
				n = selItem + 1;
			}

			showDst(n);

		}
		
		function playDst (t) {
			if (activePage) {
				Interval = setTimeout(nextDst, t);
			} else {
				stopDst();
			}
		}
		
		function stopDst () {
			clearTimeout(Interval);
		}
		
		jQuery(window)
            .focus(function() { activePage = true; if (opts.autoPlay) { playDst(opts.timer); } })
            .blur(function() { activePage = false; });
		//-------
		
		//Crio os Botoes
		var btModel = jQuery(".btRpt:last", Father);
		for (i=0; i<nItens-1; i++) { btModel.clone().insertAfter(btModel); }
		
		var lblBt = 0;
		jQuery(".btRpt", Father).each(function(){
			lblBt++;
			jQuery(this).html(lblBt);
			jQuery(this).click(function(){
				n = parseFloat(jQuery(this).html());
				if (selItem != n) {
					showDst(n);
				}
			});
			
			jQuery(this).hover(function(){
				jQuery(this).addClass(opts.classOver);
			},
			function(){
				jQuery(this).removeClass(opts.classOver);
			});
		});
		//--------------
		
		showDst (1);
		if (opts.autoPlay) { playDst(opts.timer); }
		
		
	});
}
