$(document).ready(function() {
						   
	// Mascara geral
	$('<div id="mascara"></div>')
	.css({
		opacity: 0.8,
		width:$(document).width(),
		height:$(document).height(),
		position: 'absolute',
		background: '#000',
		zIndex: 99999,
		top: 0
	}).appendTo('body').hide();
	///////////////////////////////#mascara {position:absolute; background:#000; z-index:1; top:0;}
	
	// margem para banners laterais
	$('#destaques .bannerlateral:even').css({marginRight: 10});
	///////////////////////////////
	
	// Frases de tempo real
	$('#frasereal').cycle({ 
		fx:     'scrollDown'
	});
		
	$('#frasereal').hover(
		function () {
			$('#frasereal').cycle('pause')
		},
		function () {
			$('#frasereal').cycle('resume')
		}
	);
	//////////////////////////////
	
	// Valida e envia form contato
	$("#form_contato").validate({})
	
	$('#form_contato').submit(function(e) {		
		e.preventDefault();
		if ($('#form_contato').valid()) {
			$.ajax({
				url: 'lib/mail.php',
				dataType: 'html',
				type: 'post',
				data: $('#form_contato').serialize(),
				beforeSend: function() {
					$('#loader-contato').css({display: 'block'});
				},
				complete: function() {
					$('#loader-contato').css({display: 'none'});
				},
				success: function(data, textStatus) {
					
					if (data == 'enviado') {
						$('#rescontato').text('Email enviado com sucesso!');
						$('#form_contato input[type="text"], #form_contato textarea').val('');
					}
					
					else {
						$('#rescontato').text('Falhou, tente novamente!');
					}
				},
				error: function(xhr, er) {
					//$('#rescontato').html('Error ' + xhr.status + ' - ' + xhr.statusText);
				}
			});
		}
	});

	/////////////////////////////
	
	
	// Slideshow
	$('#slide').cycle({ 
		fx:     'fade',
		timeout: 6000,
		pager:  '#navslide'
	});
	/////////////////////////////
	
	// caixa comentario
	$('#comentario_cx').css({
		left:($(window).width()/2 - $('#comentario_cx').width() / 2),
		top:($(window).height()/2 - $('#comentario_cx').height() / 2)
	});
	
	$('#coment_open').click(function(e) {
		e.preventDefault();
		$('#comentario_cx').css({display: 'block'});
	});
	
	$('#coment_close').click(function(e) {
		e.preventDefault();
		$('#comentario_cx').css({display: 'none'});
	});
	
	$('#comentar').click(function(e) {
		e.preventDefault();
		$('#lista_coment, #comentar').slideUp();
		$('#form_coment').slideDown();
		$('.coment_header h2').text('Faça seu comentário');
	});
	
	$('#cancelar').click(function() {
		$('#form_coment').slideUp();
		$('#lista_coment, #comentar').slideDown();
		$('.coment_header h2').text('Comentários');
	});
	
	$('#form_coment').submit(function(e) {
		e.preventDefault();
		
		$.ajax({
			url: 'lib/coment.php',
			dataType: 'html',
			type: 'post',
			data: $('#form_coment').serialize(),
			beforeSend: function() {
				$('#coment_res').html('<img src="images/layout/ajax-loader.gif" alt="" />').css({marginLeft: 110, marginTop: 20});
			},
			complete: function() {
				$('#coment_res').empty();
			},
			success: function(data, textStatus) {
								
				$('#mascara').fadeIn(500, function(){
					
					if (data == 'nome') {					
						jAlert('O campo nome deve ser preenchido!', 'Atenção', function() {
							$('#form_coment #nome').focus();
							$('#mascara').fadeOut(500);
						});
					}
					else if (data == 'email') {					
						jAlert('O campo email deve ser preenchido corretamente!', 'Atenção', function() {
							$('#form_coment #email').focus();
							$('#mascara').fadeOut(500);
						});
					}
					else if (data == 'mensagem') {					
						jAlert('O campo comentário deve ser preenchido!', 'Atenção', function() {
							$('#form_coment #mensagem').focus();
							$('#mascara').fadeOut(500);
						});
					}
					else if (data == 'gravado') {					
						jAlert('Comentário gravado com sucesso, logo ele será avaliado e liberado!', 'Obrigado', function() {
							$('#form_coment input[type="text"], #form_coment textarea').val('');
							$('#form_coment').slideUp();
							$('#lista_coment, #comentar').slideDown();
							$('.coment_header h2').text('Comentários');
							$('#mascara').fadeOut(500);
						});
					}
					
					
				});
				
			},
			error: function(xhr, er) {
				$("#mascara").fadeIn(500, function(){
					jAlert('Error ' + xhr.status + ' - ' + xhr.statusText, "Atenção", function() {
						$("#mascara").fadeOut(500);		
					});
				});
			}
		});

	});
	////////////////////////////
	
	// Expande superbanner
	expandeSuperbanner = function(height) {
		$('#superbanner').hover(
			function(){
				$(this).css({height: height});								   
			},
			function() {
				$(this).css({height: 90});
			}
		)
	}
	////////////////////////////
	
	// Expande superbanner
	expandeFullbanner = function(height) {
		$('#fullbanner').hover(
			function(){
				$(this).css({height: height});								   
			},
			function() {
				$(this).css({height: 96});
			}
		)
	}
	////////////////////////////
		
	// busca
	$('#form_busca').submit(function() {
		if ($('#form_busca input[type="text"]').val().length < 3) {
			
			$('#mascara').fadeIn(500, function(){
				$.alerts.okButton = 'OK';
				jAlert('Sua busca deve conter pelo menos 3 caracteres!', 'Atenção', function() {
					$('#form_busca input[type="text"]').focus();
					$('#mascara').fadeOut(500);
				});
				$('#popup_overlay').click(function(){
					$('#mascara').fadeOut(500);
					$.alerts._hide();
					$('#pesquisar').focus();
				});
			});
			return false;
		}
	});
	////////////////////////////
				
});