$(function()
{
	// Faz o preload das imagens do css
	$.preloadCssImages();  

	//Aplica o PNGFix
	//$(document).pngFix();

	/*// Cria o Scroll
	$('#contCheio').jScrollPane({scrollbarWidth:7, scrollbarMargin:10});
	
	// Cria o Submenu		 
	$(".menu").each(function(){ 
			var el = $('#' + $(this).attr('id') + ' ul:eq(0)');
			
			$(this).mouseover(function(){ 
					el.show();
			});
			$(this).mouseout(function(){ 
					el.hide();
			});
			
			$('li', this).mouseover(function(){
					$('ul', this).show();
			});
			$('li', this).mouseout(function(){
					$('ul', this).hide();
			});
	
	}); 
	$(".menu ul").each(function(){ 
		$('li:last',this).css({border:'none'});
	});
	
	$(".botaoExpandir").click(function(){
		
		$divAnt = $(this).parent();
		if($("div",$divAnt).is(':hidden')){
			$("div",$divAnt).show();
		}else{
			$("div",$divAnt).hide();
		}
		posicionaRodape();
	});
	*/
	
	$('.noticias-conteudo').jScrollPane({showArrows:true, scrollbarWidth:7});  // habilita o scroll das noticias

	$("ul.tabs").tabs("div.panes > div",{effect:'fade'}); // cria o tab das franquias

	$("#btNewsletter").click(function(){
		$err="";
		$email = $("#input-texto").val();
		
		if($email=="" || $email.indexOf("@")<=0){
			$err += "<div style='color:red; font-size:10px; font-weight:bold'>Digite um email válido</div>";
		}

		if($err!=""){
			$("#erro").html($err);
			$("#erro").css({opacity:'0'});
			$("#erro").show();
			$("#erro").fadeTo('slow', 1);
			setTimeout(function(){$("#erro").fadeTo('slow', 0,function(){$("#erro").hide()});},2000);
		
			posicionaRodape();
		}else{
			$.post("cadastra_newsletter.php",{email:$email},
				function(retorno){
					if(retorno=="1"){
						$("#erro").html("<div style='color:#57a01d; font-size:10px; font-weight:bold'>Cadastrado com sucesso!</div>");
					}else if(retorno=="0"){
						$("#erro").html("<div style='color:#57a01d; font-size:10px; font-weight:bold'>Erro ao cadastrar!</div>");
					}else{
						$("#erro").html("<div style='color:#57a01d; font-size:10px; font-weight:bold'>Email já cadastrado!</div>");
					}
						$("#erro").css({opacity:'0'});
						$("#erro").show();
						$("#erro").fadeTo('slow', 1);
						setTimeout(function(){$("#erro").fadeTo('slow', 0,function(){$("#erro").hide()});},2000);
					
				}
			);
		}
		return false;
	});
	
	// Efeito mouseover da assinatura
	$("#assinatura a").css('opacity',0.20);
		$("#assinatura a").mouseover(function(){
			$(this).stop(true, true).fadeTo("normal", 1);
		});
		$("#assinatura a").mouseout(function(){
			$(this).stop(true, true).fadeTo("normal", 0.20);
		});
	
	// Define as mascaras para o formulário
	$("#txttelefone").mask("(99) 9999-9999");
	$("#txttelefone1").mask("(99) 9999-9999");
	$("#txttelefone2").mask("(99) 9999-9999");
	$("#txtcpf").mask("999999999999999999");
	$("#txtcep").mask("99999-999");
	

	//$('div,img').pngFix();

});

function carregaEstados(){
	$.post('includes/getEstados.php', '', function(retorno){
		$("#slctEstados").html(retorno);
	});
}
function carregaCidades(uf){
	$.post('includes/getCidades.php', {uf:uf}, function(retorno){
		$("#slctCidades").html(retorno);
	});
}

function insereFlash(filename,name,largura,altura){
	
			AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', largura,
			'height', altura,
			'src', filename,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'a',
			'bgcolor', '#ffffff',
			'name', 'a',
			'menu', 'false',
			'allowScriptAccess','sameDomain',
			'movie', filename,
			'salign', ''
			); //end AC code
	
}

function posicionaRodape(){
	altura = parseInt($(".materiaTexto").height()+$(".materiaTexto").offset().top+20);

	if(altura<500){
		altura = 770;

		$(".box")
		.css({"height":600})
		.show();
	}
	
	
	
	$("#rodape")
	.css({top:altura})
	.show();	
}

function vFormFaleConosco(){
	$("#msg").show();
	

	$err	 	= "";
	$nome		= $("#txtnome").val();
	$email		= $("#txtemail").val();
	$telefone	= $("#txttelefone").val();
	$mensagem	= $("#txtmensagem").val();
	
	
	
	if($nome==""){
		$err += "- Informe seu nome <br>";
	}
	
	if($email==""){
		$err += "- Informe seu email <br>";
	}
	
	if($mensagem==""){
		$err += "- Digite a mensagem <br>";
	}
	
	if($err!=""){
		$("#msg").html("<div font-size:11px'><b>Erro(s) encontrado(s):</b> <br><br><div style='color:red; >" + $err + "</div></div>");
	}else{
		$("#msg").html("Enviando...");
		$.post("faleconosco_enviaremail.php",$("#faleConosco").serialize(),
			function(retorno){
				if(retorno=="1"){
					$("#msg").html("<div style='color:#57a01d; font-size:11px; font-weight:bold'>Mensagem enviada com sucesso!</div>");
					$("#faleConosco")[0].reset();
				}
			}
		);
	}
	return false;
}

function vFormContatoFranquia(){
	$("#msg").show();
	

	$err	 	= "";
	$nome		= $("#txtnome").val();
	$email		= $("#txtemail").val();
	$telefone1	= $("#txttelefone1").val();
	$telefone2	= $("#txttelefone2").val();
	$cpf		= $("#txtcpf").val();
	$endereco	= $("#txtendereco").val();
	$cep		= $("#txtcep").val();
	$mensagem	= $("#txtmensagem").val();
	
	
	if($nome==""){
		$err += "- Informe seu nome <br>";
	}
	
	if($email==""){
		$err += "- Informe seu email <br>";
	}

	if($telefone1=="" && $telefone2==""){
		$err += "- Informe pelo menos um telefone <br>";
	}
	
	if($cpf==""){
		$err += "- Informe seu CPF ou CNPJ <br>";
	}

	if($endereco==""){
		$err += "- Informe seu endereço <br>";
	}
	
	if($cep==""){
		$err += "- Informe seu CEP<br>";
	}

	if($mensagem==""){
		$err += "- Digite a mensagem <br>";
	}
	
	if($err!=""){
		$("#msg").html("<div font-size:11px'><b>Erro(s) encontrado(s):</b> <br><br><div style='color:red; >" + $err + "</div></div>");
	}else{
		$("#msg").html("Enviando...");
		$.post("franquia_enviaremail.php",$("#contatoFranquia").serialize(),
			function(retorno){
				if(retorno=="1"){
					$("#msg").html("<div style='color:#57a01d; font-size:11px; font-weight:bold'>Mensagem enviada com sucesso!</div>");
					$("#contatoFranquia")[0].reset();
				}
			}
		);
	}
	return false;
}

//Função para localizar o objeto do flash, caso seja Internet Explorer ele usa o objeto window, se for qualquer outro, o objeto document
function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
//Função que recebe um valor e envia para o Flash através do método que criamos no AS3, onde FlashRecebe é a id do objeto Flash
function setaValor(filme,valor) {
     thisMovie(filme).enviar(valor);
}
