jQuery.fn.extend( {
	foto_pass : function(options)
	{
		var jQueryMatchedObj = this;

		var defaults = {
			auto :false,
			timeView :3000,
			timeAnime :100
		};

		options = jQuery.extend(defaults, options);

		var intervalo = options.timeView + options.timeAnime;
		var timer = null;
		var timerPause = null;
		var itens = null;
		var controlNumPass = null;
		var ponteiro = 0;
		var ponteiroAntigo = 0;

		function _initialize()
		{
			clearTimeout(timer);

			itens = jQueryMatchedObj.find('.item_pass');
			controlNumPass = jQueryMatchedObj.find('.control_num_pass');

			itens.each( function(i)
			{
				if (i == 0)
				{
					this.style.display = 'block';
				}
				else
				{
					this.style.display = 'none';
				}

				this.onmouseover = _pause;

				this.onmouseout = function()
				{
					timerPause = setTimeout(_run, options.timeView);
				};
			});

			jQueryMatchedObj.find('.control_pause_pass').click( function()
			{
				_pause();
			});

			jQueryMatchedObj.find('.control_play_pass').click( function()
			{
				_run();
			});

			controlNumPass.each( function(i)
			{
				jQuery(this).click( function()
				{
					_nextAt(i);
				});
			});

			_run();
		}

		function _pause()
		{
			clearTimeout(timerPause);
			clearTimeout(timer);
		}

		function _avancarPonteiro()
		{
			ponteiroAntigo = ponteiro;

			if (ponteiro < (itens.length - 1))
			{
				ponteiro++;
			}
			else
			{
				ponteiro = 0;
			}
		}

		function _start()
		{
			_avancarPonteiro();
			_view();
			_run();
		}

		function _view()
		{
			var width = jQueryMatchedObj.width();

			jQuery(controlNumPass.get(ponteiroAntigo)).removeClass('selected');
			jQuery(itens[ponteiroAntigo]).fadeOut(options.timeAnime, function()
			{
				jQuery(itens[ponteiro]).fadeIn();

				jQuery(controlNumPass.get(ponteiro)).addClass('selected');
			});
		}

		function _run()
		{
			if (options.auto)
			{
				timer = setTimeout(_start, intervalo);
			}
		}

		function _nextAt(index)
		{
			_pause();

			ponteiroAntigo = ponteiro;
			ponteiro = index;

			_view();
			_run();

			_pause();
		}

		_initialize(jQueryMatchedObj);

		return this;
	}
});
