
(function($) {
$.fn.ListaDestaques = function (options) {

	var opts = $.extend({
		timer: 4000,
		fadeSpeed: "normal",
		autoPlay: true,
		classAt: "dstBtAt",
		classOver: "dstBtOver"
	}, options);

	this.each(function(){

		//Configs iniciais
		var Interval;
		var Father		= $(this);
		var selItem		= 1;
		var nItens 		= $(".dstItem", Father).size();

		$('.dstItem', Father).hide();
		//$('.dstItem:first', Father).show();

		$(".dstItens", Father).css('position', 'relative');
		$('.dstItem', Father).css('position', 'absolute');

		//----------------

		//Funcoes
		function showDst (n){
			if (opts.autoPlay) { stopDst(); }

			$(".dstItem", Father).fadeOut(opts.fadeSpeed);
			$(".dstItem:eq("+(n-1)+")", Father).fadeIn(opts.fadeSpeed);

				selItem = n;
				$(".btRpt", Father).removeClass(opts.classAt);
				$(".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) {
			Interval = setTimeout(nextDst, t);
		}

		function stopDst () {
			clearTimeout(Interval);
		}
		//-------

		//Crio os Botoes
		var btModel = $(".btRpt:last", Father);
		for (i=0; i<nItens-1; i++) { btModel.clone().insertAfter(btModel); }

		var lblBt = 0;
		$(".btRpt", Father).each(function(){
			lblBt++;
			$(this).html(lblBt);
			$(this).click(function(){
				n = parseFloat($(this).html());
				if (selItem != n) {
					showDst(n);
				}
			});

			$(this).hover(function(){
				$(this).addClass(opts.classOver);
			},
			function(){
				$(this).removeClass(opts.classOver);
			});
		});
		//--------------

		showDst (1);
		if (opts.autoPlay) { playDst(opts.timer); }


	});
}
})(jQuery);
