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

		var defaults = {
			auto :true,
			timeView :1000,
			timeAnime :1000,
			classItens :'.item_pass'
		};

		options = jQuery.extend(defaults, options);

		var AVANCAR = 'A';
		var RECUAR = 'R';

		var intervalo = options.timeView + options.timeAnime;
		var timer = null;
		var timerPause = null;
		var itens = new Array();
		var ponteiro = 0;
		var ponteiroAntigo = 0;
		var direcao = AVANCAR;
		var podeMover = true;

		function _initialize()
		{
			clearTimeout(timer);
			itens = jQueryMatchedObj.find('.' + options.classItens);

			itens.each( function(i)
			{
				window.objPass = jQueryMatchedObj;

				if (i == 0)
				{
					this.style.left = '0px';
				}
				else
				{
					this.style.left = jQueryMatchedObj.width() + 'px';
				}

				this.objPass = jQueryMatchedObj;
				this.onmouseover = _pause;

				this.onmouseout = function()
				{
					if (this.objPass.podeMover())
					{
						timerPause = setTimeout(_next, options.timeView);
					}
				};
			});

			_run();
		}

		function _pause()
		{
			clearTimeout(timerPause);
			this.objPass.pause();
		}

		function _next()
		{
			this.objPass.next();
		}

		function _habilitaMovimento()
		{
			podeMover = true;
		}

		function _avancarPonteiro()
		{
			ponteiroAntigo = ponteiro;

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

			direcao = AVANCAR;
		}

		function _recuarPonteiro()
		{
			ponteiroAntigo = ponteiro;

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

			direcao = RECUAR;
		}

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

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

			podeMover = false;

			if (direcao == AVANCAR)
			{
				itens[ponteiro].style.left = width + 'px';

				jQuery(itens[ponteiroAntigo]).animate( {
					left :"-=" + width + "px"
				}, options.timeAnime, null);
				jQuery(itens[ponteiro]).animate( {
					left :"-=" + width + "px"
				}, options.timeAnime, null);
			}
			else
			{
				itens[ponteiro].style.left = -width + 'px';

				jQuery(itens[ponteiroAntigo]).animate( {
					left :"+=" + width + "px"
				}, options.timeAnime, null);
				jQuery(itens[ponteiro]).animate( {
					left :"+=" + width + "px"
				}, options.timeAnime, null);
			}

			setTimeout(_habilitaMovimento, options.timeAnime);
		}

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

		this.podeMover = function()
		{
			return podeMover;
		}

		this.pause = function()
		{
			clearTimeout(timer);
		}

		this.next = function()
		{
			if (!podeMover)
			{
				return;
			}

			this.pause();

			_avancarPonteiro();
			_view();
			_run();
		}

		this.prior = function()
		{
			if (!podeMover)
			{
				return;
			}

			this.pause();

			_recuarPonteiro();
			_view();
			_run();
		}

		_initialize(jQueryMatchedObj);

		return this;
	}
})
