setInterval ( "doSomething()", 25000 );

function doSomething ( )
{
	$('#bannerRodape').load('inicio/banners');
	$('#radioHome').load('inicio/radios');
}


$(document).ready(function() {

	$('.searchMenu, #searchMenuOptions').hover(
		function() {
			$('#searchMenuOptions').show();
		},
		function() {
			$('#searchMenuOptions').hide();
		}
	);

	// MÁSCARAS
	jQuery(function($){
		$("#telefone").mask("(99) 9999.9999");
	});

	// toggles the slickbox on clicking the noted link  
	$('a#slick-toggle').click(function() {
		$('#slickbox').toggle(400);
		return false;
	});

	// CONFIGURA A VALIDACAO DO FORMULARIO DE CONTATO
	$("#form_contato").validate({
		rules: {
			nome: {required: true, minlength: 5},
			email: {required: true, email:true},
			mensagem: {required: true, minlength: 10}
		},
		messages: {
			nome: {
				required: "<p><small>Informe seu nome</small></p>",
				minlength:"<p><small>Informe pelo menos 5 caracteres</small></p>"
			},
			email:{
				required: "<p><small>Informe um e-mail</small></p>",
				email: "<p><small>Informe um e-mail válido</small></p>"
			},
			mensagem: {
				required: "<p><small>Informe a mensagem</small></p>",
				minlength:"<p><small>Informe pelo menos 10 caracteres</small></p>"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_contato .formPreloader").css("display", "block");
			$("#form_contato .btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			
			// ENVIA O FORMULARIO
			$.post("contato/envia", $(form).serializeArray(), getContato, "json");
			return false;
		}
	});

	$("#form_sugestao").validate({
		errorPlacement: function(error, element) {
			$('#aguardeContato').html(error);
		},
		rules: {
			nome: {required: true, minlength: 5},
			email: {required: true, email:true}
		},
		messages: {
			nome: {
				required: "<p><small>Informe seu nome</small></p>",
				minlength:"<p><small>Informe pelo menos 5 caracteres</small></p>"
			},
			email:{
				required: "<p><small>Informe um e-mail</small></p>",
				email: "<p><small>Informe um e-mail válido</small></p>"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_sugestao .formPreloader").css("display", "block");
			$("#form_sugestao .btSubmit").attr("disabled","disabled");
			$("#aguardeContato").text("");
			
			// ENVIA O FORMULARIO
			$.post("contato/sugestao", $(form).serializeArray(), getSugestao, "json");
			return false;
		}
	});

	$("#form_anuncie").validate({
		rules: {
			razao: {required: true, minlength: 5},
			endereco: {required: true, minlength: 5},
			bairro: {required: true},
			cidade: {required: true},
			telefone: {required: true},
			atividade: {required: true, minlength: 5},
			nome: {required: true, minlength: 5}
		},
		messages: {
			razao: {
				required: "<p><small>Informe a Razão Social</small></p>",
				minlength:"<p><small>Informe pelo menos 5 caracteres</small></p>"
			},
			endereco: {
				required: "<p><small>Informe seu Endereço</small></p>",
				minlength:"<p><small>Informe pelo menos 5 caracteres</small></p>"
			},
			bairro: {
				required: "<p><small>Informe seu Bairro</small></p>"
			},
			cidade: {
				required: "<p><small>Informe sua Cidade</small></p>"
			},
			telefone: {
				required: "<p><small>Informe seu Telefone</small></p>"
			},
			atividade: {
				required: "<p><small>Informe sua Atividade</small></p>",
				minlength:"<p><small>Informe pelo menos 5 caracteres</small></p>"
			},
			nome: {
				required: "<p><small>Informe seu Nome</small></p>",
				minlength:"<p><small>Informe pelo menos 5 caracteres</small></p>"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_anuncie .formPreloader").css("display", "block");
			$("#form_anuncie .btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			
			// ENVIA O FORMULARIO
			$.post("anuncie/envia", $(form).serializeArray(), getAnuncie, "json");
			return false;
		}
	});

	// CONFIGURA A VALIDACAO DO FORMULARIO DE ANUNCIO
	$("#form_anuncio").validate({
		rules: {
			nome: {required: true, minlength: 5},
			email: {required: true, email:true},
			mensagem: {required: true, minlength: 10}
		},
		messages: {
			nome: {
				required: "<small>Informe seu nome</small>",
				minlength:"<small>Informe pelo menos 5 caracteres</small>"
			},
			email:{
				required: "<small>Informe um e-mail</small>",
				email: "<small>Informe um e-mail válido</small>"
			},
			mensagem: {
				required: "<small>Informe a mensagem</small>",
				minlength:"<small>Informe pelo menos 10 caracteres</small>"
			}
		},
		submitHandler: function(form){
			// APAGA O BOTAO
			$("#form_anuncio .formPreloader").css("display", "block");
			$("#form_anuncio .btSubmit").css("display", "none");
			$("#aguardeContato").text("");
			
			// ENVIA O FORMULARIO
			$.post("anuncio/envia", $(form).serializeArray(), getAnuncio, "json");
			return false;
		}
	});

});

// RECEBE O RETORNO DO FORMULARIO DE ANUNCIO
// -- ANUNCIO ANUNCIO ANUNCIO --
getAnuncio = function(rs){
	if(rs.result == "ok"){
		$("#aguardeContato").text("Mensagem enviada com sucesso");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$(".formReset").click();
		}, 2000);
	}
	if(rs.result == "erro"){
		$("#aguardeContato").text("Erro ao enviar mensagem");
		//$("#aguardeContato").fadeIn("slow");
	}
	// MOSTRA O BOTAO
	$("#form_anuncio .formPreloader").css("display", "none");
	$("#form_anuncio .btSubmit").css("display", "");
}

// -- ANUNCIE ANUNCIE ANUNCIE --
getAnuncie = function(rs){
	if(rs.result == "ok"){
		$("#aguardeContato").text("Mensagem enviada com sucesso");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$(".formReset").click();
		}, 2000);
	}
	if(rs.result == "erro"){
		$("#aguardeContato").text("Erro ao enviar mensagem");
		//$("#aguardeContato").fadeIn("slow");
	}
	// MOSTRA O BOTAO
	$("#form_anuncie .formPreloader").css("display", "none");
	$("#form_anuncie .btSubmit").css("display", "");
}

getSugestao = function(rs){
	if(rs.result == "ok"){
		$("#aguardeContato").text("Mensagem enviada com sucesso");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$(".formReset").click();
		}, 2000);
	}
	if(rs.result == "erro"){
		$("#aguardeContato").text("Erro ao enviar mensagem");
		//$("#aguardeContato").fadeIn("slow");
	}
	// MOSTRA O BOTAO
	$("#form_sugestao .formPreloader").css("display", "none");
	$("#form_sugestao .btSubmit").removeAttr("disabled");
}

// RECEBE O RETORNO DO FORMULARIO DE CONTATO
getContato = function(rs){
	if(rs.result == "ok"){
		$("#aguardeContato").text("Mensagem enviada com sucesso");
		$("#aguardeContato").fadeIn("slow");
		setTimeout(function(){
			$(".formReset").click();
		}, 2000);
	}
	if(rs.result == "erro"){
		$("#aguardeContato").text("Erro ao enviar mensagem");
		//$("#aguardeContato").fadeIn("slow");
	}
	// MOSTRA O BOTAO
	$("#form_contato .formPreloader").css("display", "none");
	$("#form_contato .btSubmit").css("display", "");
}
//////////////////////
// INICIA SHADOWBOX //
//////////////////////
function doInit(){
	Shadowbox.init();
}


// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
    
    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){    
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }


    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}