var Geral = {
	__construct: function() {
		var _this = this;
		$('input[@type=text][default], textarea[default]').resetDefaultValue();

		$("input[type=file]").filestyle({ // plugin para personalizar input type 'file'
			 image: "img/bt-selecionar.gif",
			 imageheight : 31,
			 imagewidth : 83,
			 width : 240
		 });

		$(".bglegenda, #sidebar .legenda").css("opacity",0);
		$(".paginacao p a:first-child").addClass('first');
		_this.coberturas();
		_this.agenda();
		_this.thumbs();
		_this.dropdown();
		_this.frmNewsletter();
		_this.frmBusca();
		
		$('.fancy_single').fancybox();

	},

	frmBusca : function(){
		var $oForm = $('form[name=frmBusca]');
		var textoPadrao = "O que você procura?";
		$oForm.submit(function(){
			var texto = $oForm.find('.input input').val();
			if(texto==textoPadrao || texto == ""){
				alert('Digite alguma palavra para realizar a busca');
				return false;
			} else {
				return true;
			}
		});
	},

	frmNewsletter : function(){
		var $oForm = $('form[name=frmNewsletter]');
		var textoPadrao = "digite seu e-mail";
		$oForm.submit(function(){
			var email = $oForm.find('.input input').val();
			if(validarEmail(email)){
				$.get('newsletter',{m1:email},function(msg){
					alert(msg);
				});
			} else {
				alert(email==""?'Digite o seu e-mail':'Verifique o e-mail informado');
			}
			return false;
		});
	},

	coberturas: function() {
		$(".cobertura").hover(
			function() {
				$(this).find(".legenda:not(:animated)").animate({opacity: 1});
				$(this).find(".bglegenda:not(:animated)").animate({opacity:.5});
			},
			function() {
				$(this).find(".bglegenda,.legenda").animate({opacity:0});
			}
		).click(function(e) {
			var id = $(this).attr('id');
			location.href="cobertura?cobertura="+id;
		});
	},

	agenda: function() {
		var $obj = $(".mes:not(.comevento)");
		$obj.hide();
		$("h1.linha a").toggle(
			function() {
				$(this).parent().next().next(".mes").show();
			},
			function() {
				$(this).parent().next().next(".mes").hide();
			}
		);
	},

	calendario : function(direcao){
		if(direcao == "menos"){
			var _mes = $("#wp-calendar #mesMenos").val();
			var _ano = $("#wp-calendar #anoMenos").val();
		} else {
			var _mes = $("#wp-calendar #mesMais").val();
			var _ano = $("#wp-calendar #anoMais").val();
		}
		if(_mes != "" && _ano != ""){
			var _$ = $('#calendario');
			$('.carregando').show()
			.css(
				{
					width: _$.width()+1,
					height: _$.height()+1
				}
			)
			.find("img")
			.css(
				{
					top: Math.ceil(_$.height()/2)-15,
					left: Math.ceil(_$.width()/2)-15
				}
			);
			_$.load(
				"inc.calendario.php",
				{
					mes: _mes,
					ano: _ano
				}
			);
		}
	},

	thumbs: function() {
		$(".thumbs li a").click(function() {
			var pagina = $(this).attr('id');
			window.divopen(pagina,519,561);
			return false;
		});
	},

	dropdown: function() {
		$('ul.submenu').hide();
		window.t = 0;
		$('#menu td.servicos').bind('mouseenter',function(){
			if (t) clearTimeout(t);
			$('ul.submenu',this).slideDown('fast');
			$(this).css("background","url(img/bg-hoverservicos.gif) no-repeat 10px top");
		}).bind('mouseleave',function(){
			var self = this;
			t = setTimeout(function(){
				$('ul.submenu',self).stop().slideUp('fast', function() { $('#menu td.servicos').css("background","url(img/bullet-menu.gif) no-repeat 20px 17px"); });
			},350);
		});
	}
};

$(function() {
	Geral.__construct();			 
});
