jQuery(document).ready(function() {
	
	// Slide show ----------------------------------
	$('#pai').show();
	$('#pai').cycle({
		fx: 'fade',
		timeout: 5000,
		speed: 400,
		next:   '.pro',
		prev:   '.ant'
	});

	//tempo ----------------------------------------
	$.post("modulos/tempo/1.php",function(msg) {
		$("#tag1").html(msg);
		$.post("modulos/tempo/2.php",function(msg) {
			$("#tag2").html(msg);
			$.post("modulos/tempo/3.php",function(msg) {
				$("#tag3").html(msg);
				$.post("modulos/tempo/4.php",function(msg) {
					$("#tag4").html(msg);
					$.post("modulos/tempo/5.php",function(msg) {
						$("#tag5").html(msg);
						$('#tempo').css("cursor","pointer")
						$('#tempo').cycle({
							fx:     'scrollLeft', 
							timeout: 10000,
							next: '#tempo'
						});
	}); }); }); });	});

	//Slide show de miniaturas ---------------------
	$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
		
	$('ul.gallery_demo').galleria({
		history   : true, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#main_image', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			
			// fade in the image & caption
			image.css('display','none').fadeIn(1000);
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Pr&oacute;xima image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.6';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.6); } // don't fade out if the parent is active
			)
		}
	});
	
	//Limite para texarea --------------------------
	//este código está contido na pagina de recados -> $("#TexRecado").textlimit('span.counter',250);
	
	//Recados --------------------------------------
	$("#form_recado").bind("submit", function(){
		if((this.AutRecado.value == "") || (this.EmaRecado.value == "") || (this.TexRecado.value == "")){
			o = getOffsets(this);
			$("#parc_tex").html("Ocorreu um erro. Por favor preencha todos os campos.")
			$("#parceiro").css("top",o.top+175).css("left",o.left+40).show();			
		}
		else{
			var params = $(this.elements).serialize();
			$.ajax({
				type: "POST",
				url: this.action,
				data: params,
				beforeSend: function(){
					$("#FormRecado").html("<div class='pause'>Enviando dados...</div>");
				},
				success: function(txt){
					$("#FormRecado").html(txt);
					this.reset();
				},
				error: function(){
					$("#FormRecado").html("<div class='stop'>Erro ao enviar mensagem. Tente Novamente. <a href='?id=recados'>Voltar</a></div>");
					//$("#FormRecado").html("<div class='stop'>"+txt+"</div>");
				}
			});
		}
		return false;
	});
	$('#rec_sub').bind('mouseout',
		function(){
			$("#parceiro").hide();
		}
	);
	
	// Termo de Uso --------------------------------
	$('#termodeuso').bind('click',function (){
		o = getOffsets(this);
		$("#termo_tex").html(
		"<h3>Regras de Uso</h3>"+
		"Os autores dos Murais n&atilde;o devem publicar material protegido por direitos autorais nem publicar fotos ou textos sem autoriza&ccedil;&atilde;o do autor "+
		"ou de seu representante. N&atilde;o devem tamb&eacute;m publicar mensagems sem autoriza&ccedil;&atilde;o dos autores e n&atilde;o devem distribuir arquivos de som sem "+
		"autoriza&ccedil;&atilde;o de pessoas ou empresas respons&aacute;veis.<br><br>"+
		"O Mural n&atilde;o deve conter em seu conte&uacute;do os seguintes itens:<br><br>"+
		"* material pornogr&aacute;fico, grosseiro, racista ou ofensivo;<br>"+
		"* informa&ccedil;&atilde;o sobre atividades ilegais e incita&ccedil;&atilde;o ao crime;<br>"+
		"* material pornogr&aacute;fico ou atividades ilegais incluindo menores;<br>"+
		"* material calunioso;<br>"+
		"* afirma&ccedil;&otilde;es injuriosas ou difamat&oacute;rias;<br>"+
		"* propaganda pol&iacute;tica para candidatos, partidos ou coliga&ccedil;&otilde;es;<br>"+
		"* programas e arquivos que ponha em risco o computador;<br>"+
		"* informa&ccedil;&atilde;o relativa ou que direcione &agrave; pirataria de software;<br><br>"+
		"O folhadeguanhaes.com.br se reserva o direito de, a qualquer tempo e a seu exclusivo crit&eacute;rio, apagar qualquer mensagem e/ou Mural que "+
		"possam ser interpretados contr&aacute;rios &agrave;s regras de uso do Mural de Recados ou &agrave;s normas legais em vigor.")
		$("#termo_tex").css("top",o.top).css("left",o.left-290).show();
	});
	$('#termo_tex').hover(
      function () {
		$("#termo_tex").show();
      }, 
      function () {
		$("#termo_tex").hide();
      }
    );
	
	//Imóveis --------------------------------------
	$('#box_imo').cycle({
		fx:     'fade', 
		timeout: 4000,
		next:   '.imovolta',
		prev:   '.imoavanca'
	});
	
	//Fotos ----------------------------------------
	$("a[rel^='lightboxF']").slimbox();
	
	//Publicidade ----------------------------------------
	$("#pp1").slimbox();
	$("#pp2").slimbox();
	$("#pp3").slimbox();
	$("#pp4").slimbox();
	$("#pp5").slimbox();
	$("#pp6").slimbox();
	$("#pp7").slimbox();
	
	// funções -------------------------------------
	function getOffsets(e){
	   var o = {
		 height: e.offsetHeight,
		 width: e.offsetWidth
	   };
	
	   var x = e.offsetLeft;
	   var y = e.offsetTop;
	   var p = e.offsetParent;
	
	   while(p && (p.nodeType != 9))
	   {
		 x += p.offsetLeft;
		 y += p.offsetTop;
		 p = p.offsetParent;
	   }
	   o.left = x;
	   o.top = y;
	   return o;
	
	}
	
});