$(document).ready(
	function()
	{
		setInterval(function(){
			var atual = $("#img img:visible");
			var prox = atual.next();
			if (prox.length < 1){
				prox = $("#img img:first");
			}
			prox.fadeIn(1500, function(){
				atual.fadeOut(1500);
			});
		},5000);

		$('#sinopse').css({opacity:.7});	
		
		$('#menu ul li.super ul').css({opacity:.9});	
		
		if(navigator.appName == 'Microsoft Internet Explorer' && navigator.appVersion.indexOf('MSIE 7.0') > -1  )
		{
			//$('#conteudo').css('height', '100%');
			//$('#conteudo').height( $('#conteudo').height()*3.5 );
		}
		
		$('#menu ul li.super').hover(
			function()
			{ $(this).find('ul').eq(0).slideDown('fast'); },
			function()
			{
				$(this).find('ul').eq(0).slideUp('fast');
				/*setInterval(
					function()
					{ $(this).find('ul').eq(0).slideUp('slow');  },
					2000
				);*/
			}
		);
		
		$('#imagem a, #assistir-video').fancybox({
			'zoomSpeedIn':1000,
			'zoomSpeedOut':1000,
			'easingIn':'easeOutBack',
			'easingOut':'easeInBack',
			'frameWidth':$('#video').width(),
			'frameHeight':$('#video').height()			
		});
		
		if(window.location.toString().indexOf('mapa') > -1)	
		{
			$('iframe').attr('width', '500');
		}
		
		$('#espelho').css({
			display:'none',
			opacity:.7,
			position:'absolute',
			left:0,
			top:0,
			width:'100%',
			height:$(document).height(),
			background:'#000'
		});	
		
		$('a#abrir-form, a#abrir-form2').click(
			function()
			{ 
				mostrarForm($(this).offset());
			}
		);
		
		$('#fechar').click(
			function()
			{ 
				$('#indicar').fadeOut(
					'slow',
					function()
					{
						$('#espelho').slideUp('slow');
					}
				);
				
				$('#indicar form input[type=text]').each(
					function()
					{ $(this).val(''); }
				);
				
				$('#erros').hide();
			}
		);
		
		$('#form-letter #email').focus(
			function()
			{ $(this).val(''); }
		);		
	}
);

function pesquisar()
{
	palavra = $('#form-busca #palavra').val();
	if(palavra.length > 4)
		window.location = $('#form-busca').attr('action')+palavra+'/0';
	else
		$('#form-busca p').fadeIn(
			'normal',
			function()
			{
				setTimeout(
					function()
					{ $('#form-busca p').fadeOut(); },
					5000
				);
			}
		);	
}

function indicar()
{
	$.ajax({
		url:$('#indicar form').attr('action'),
		type:'post',
		data:$('#indicar form').serialize(),
		dataType:'json',
		success:function(resp)
		{
			if(resp.status == 0)
			{
				$('#erros p').html(resp.mensagem);
				$('#erros ul').html('');
				$.each(
					resp.pacotes.errors,
					function(i, val)
					{
						$('#erros ul').append('<li>'+val[1]+'</li>');
					}
				);
				
				$('#erros').fadeIn('slow');
			}
			else
			{
				alert('Indicação enviada com sucesso.');
				$('#fechar').click();
			}
		}		
	});
}

function news()
{
	$.ajax({
		url:$('#form-letter').attr('action'),
		type:'post',
		data:$('#form-letter').serialize(),
		dataType:'json',
		success:function(resp)
		{
			//ajaxLoader();
					
			if(resp.status == 0)
			{ 
				if(resp.mensagem != 'Corrija o seguinte erro:') $('#form-letter p#erro').html(resp.mensagem);
				
				$('#form-letter p#erro').fadeIn(
					'normal',
					function()
					{
						setTimeout(
							function()
							{ $('#form-letter p#erro').fadeOut(); },
							5000
						);
					}
				); 
			}
			else
			{ 
				alert('Email cadastrado com sucesso.'); 
				$('#form-letter input[type=text]').val('');
			}
		}		
	});
	//ajaxLoader();

}

function mostrarForm(xy)
{
	$('#espelho').slideDown(
		'slow',
		function()
		{ 
			$('#indicar').css({
				top:xy.top-$('#indicar').height(),
				left:xy.left-$('#indicar').width()
			}).fadeIn('slow'); 
		}
	);
}

function ajaxLoader()
{
	if($('#carregando').length == 0 )
	{
		espelho = $('<div id="espelho-ajax"></div>').css({
			display:'none',	
			opacity:.6,
			background:'#000',
			position:'absolute',
			width:'100%',
			height:screen.height+'px',
			top:0,
			left:0
		});
		
		carregando = $('<div id="carregando"></div>').css({
			display:'none',
			background:'url(img/ajax-loader.gif) no-repeat',
			position:'absolute',
			width:'129px',
			height:'16px',
			top:parseInt(parseInt($('body').height())+16),
			left: parseInt(parseInt($('body').width()/2)-129)			
		});
		
		$('#geral').append(espelho).append(carregando);
		
		espelho.fadeIn(
			'fast',
			function()
			{ carregando.show(); }
		);
	}
	else
	{
		$('#carregando').fadeOut(
			'normal',
			function()
			{ $('#espelho-ajax').fadeOut('fast'); }
		);
		$('#carregando').remove();
		$('#espelho-ajax').remove();
	}
}
