/*
 *	Escrito por Manoel Neto
 *  manoel@formaecor.com.br
 *  www.formaecor.com.br
 */
 
(function($)
{

	$.fn.galeriaSlide = function(options)
	{
		// default configuration properties
		var defaults = {
			AnteId: 'galeriaEsq',
			ProxId: 'galeriaDir',
			ImagemClass: '.galeria_img',
			Velocidade: 500,
			Acendimento: 500,
			Visiveis: 3,
			Transparencia: .6,
			Zoom: 0,
			Circular: false
		};

		var options = $.extend( defaults, options );

		return this.each(function()
		{
			obj = $(this);
			var nCol = $("li", obj).length;
			var nLargura = $("li:first", obj).width();
			var nLarguraImg = nLargura - 12;
			var nAltura = obj.height();
			var t = 0;
			
			$("ul", obj).css( 'width', nCol * nLargura );

			$("#"+options.ProxId).css( "cursor", "pointer" );
			$("#"+options.AnteId).css( "cursor", "pointer" );
			$( "li", obj ).css( { opacity: options.Transparencia } );

			$( "li", obj ).hover(
				function()
				{	
					$( this ).stop().animate( { opacity: 1 }, options.Acendimento );
					$( "img", this ).stop().animate( { width: nLargura - 2 }, options.Zoom );
				},
				function()
				{	
					$( this ).stop().animate( { opacity: options.Transparencia }, options.Acendimento );
					$( "img", this ).stop().animate( { width: nLarguraImg }, options.Zoom );					
				}
			);

			$("#"+options.AnteId).click( moverAnte );
			$("#"+options.ProxId).click( moverProx );
			
			function moverAnte()
			{
				nDeslocamento = $(obj).scrollLeft();
				if ( nDeslocamento <= 0 )	
				{
					if( options.Circular )
					{
						nDeslocamento = ( nCol - 1 ) * nLargura;				
					}
					else
					{
						$("#"+options.AnteId).animate( { opacity: .4 } );
					}
				}
				else
				{
					$("#"+options.AnteId).animate( { opacity: 1 } );
				}
				$(obj).stop().animate( { scrollLeft: nDeslocamento - nLargura }, {duration: options.Velocidade, easing: 'easeOutBounce'} );
				$("#"+options.ProxId).animate( { opacity: 1 } );				
			}			
			
			function moverProx()
			{
				nDeslocamento = $(obj).scrollLeft();
				if ( nDeslocamento >= ( ( nCol - options.Visiveis ) * nLargura ) )
				{
					if( options.Circular )
					{					
						nDeslocamento = -nLargura;
					}
					else
					{
						$("#"+options.ProxId).animate( { opacity: .4 } );
					}					
				}
				else
				{
					$("#"+options.ProxId).animate( { opacity: 1 } );
				}
				$(obj).stop().animate( { scrollLeft: nDeslocamento + nLargura }, {duration: options.Velocidade, easing: 'easeOutBounce'} );
				$("#"+options.AnteId).animate( { opacity: 1 } );
			}			
			
		});

	};

})(jQuery);
