jQuery(document).ready(function(){
	
	$(".box:eq(0) .numbera").css({"margin-left":-120,"opacity":0});
	$(".box:eq(0) .numberb").css({"margin-left":0,"opacity":1});
	$(".box:eq(0) .titulo").css({color:"#fec353"});
	
	$(".form form:eq(0)").submit(function(){

		$email = $("input[name=email]",this).val();
	
		if($email=="- Digite seu email" || $email==""){
			Shadowbox.open({content:"<div style='padding:15px; color:#c20981'>- Informe seu email</div>",player:"html",width:"350",height:"50"});
			setTimeout(function(){Shadowbox.close()},5000);
		}else if(!checkMail($email)){
			Shadowbox.open({content:"<div style='padding:15px; color:#c20981'>- O email informado é inválido</div>",player:"html",width:"350",height:"50"});
			setTimeout(function(){Shadowbox.close()},5000);
		}else{
			$.post('acoes.php','a=verifica-email&'+$(".form form:eq(0)").serialize(),function(s){
				if(s==1){
					Shadowbox.open({content:"<div style='padding:15px'>- Email já cadastrado, <a href='cadastro_editar.php'>clique aqui</a> para editar o seu cadastro.</div>",player:"html",width:"350",height:"50"});
				}else{
					window.location='cadastro.php?email='+$email;
				}
			});
		}

		return false;
		
	});


	$(".box").mouseover(function(){
		$o = $(this);
		$($o).addClass("over");
		
		$(".numberb").stop(false,false).animate({"margin-left":-120,"opacity":0});
		$(".numbera").stop(false,false).animate({"margin-left":0,"opacity":1});
		$(".titulo").css({color:"white"});
		
		$(".numbera",$o).stop(false,false).animate({"margin-left":-120,"opacity":0});
		$(".numberb",$o).stop(false,false).animate({"margin-left":0,"opacity":1});
		$(".titulo",$o).css({color:"#fec353"});
		
		$("#foto img").attr("src",$("img",$o).attr("src"));

		
		$show = false;
	});
	$(".box").mouseout(function(){
		$o = $(this);
		$($o).removeClass("over");
		$(".numberb",$o).stop(false,false).animate({"margin-left":-120,"opacity":0});
		$(".numbera",$o).stop(false,false).animate({"margin-left":0,"opacity":1});
		$(".titulo",$o).css({color:"white"});
		$show = true;
		$fade = true;
	});
	
	//setInterval("showBox()",4000);
	
	
	
	// 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);
		});
		
	$('#stage0').carouFredSel({
		autoPlay		: false,
		visibleItems		: 1,
		direction			: "right",
		scroll : {
			items			: 0,
			effect			: 'swing',
			speed			: 1000,
			pauseOnHover	: true
		},
		next : {
			button		: $('#st_next')
		},
		prev : {
			button		: $('#st_prev')
		}
	});
	$('#stage').carouFredSel({
		auto : {pauseDuration: 4000},
		autoPlay		: true,
		visibleItems		: 3,
		direction			: "right",
		scroll : {
			items			: 1,
			effect			: 'swing',
			speed			: 1000,							
			pauseOnHover	: true
		},
		next : {
			button		: $('#st_next')
		},
		prev : {
			button		: $('#st_prev')
		}
	});

	$(".flyer").click(function(){
		$("#cadastro-festas").show();
		$(this).hide();
		$(".filipeta").hide();
	});

	$('#imprensa').jqm({
		trigger: $(".imp"),
		overlay: 60,
		onHide: function(h) {
		   h.o.remove(); // remove overlay
		   h.w.fadeOut(444); // hide window
		 }
	});

	/*$('#premium').jqm({
		trigger: $(".premium"),
		overlay: 60,
		onHide: function(h) {
		   h.o.remove(); // remove overlay
		   h.w.fadeOut(444); // hide window
		 }
	});*/
	
	$(".resumo .bt").click(function(){
		$(".box .borda-pink").hide();
		$(".box .resumo").hide();
		$o = $(this).parent().parent();
		$(".borda-pink",$($o).parent()).show();
		$(".resumo",$($o).parent()).show();
		/*$(".resumo a",$($o).parent()).css({"font-size":"14px", "color":"#ffffff"});*/
		
		$(".conteudo",$o).show();
		$(this).parent().show();
	});
	
	$(".clique").click(function(){
		
		$(".box .borda-pink").hide();
		$(".box .resumo").hide();
		$o = $(this).parent();
		$(".borda-pink",$($o)).show();
		$(".resumo",$($o)).show();
		$("#btleiamais").hide();
		/*$(".resumo a",$($o)).css({"font-size":"14px", "color":"#ffffff"});*/
		$(".conteudo",$o).show();
		$(this).parent().show();
	});
	
	$('.g-fotos').jScrollPane({showArrows:true, scrollbarWidth:8});

	//$('#enderecos').jScrollPane({showArrows:true, scrollbarWidth:8});
	
	$c=0;
	$("#add-endereco").click(function(){
		$('#enderecos').append($('#enderecos div:last').clone(true).append("<img src='imagens/bt-excluir.gif' class='bt-excluir'/>"));
		$('#enderecos div:last input').val("");
		if($c<1){
			$('#enderecos').css({"height":($('#enderecos').height()+27)+"px"});
			$c++;
		}else{
			$('#enderecos').jScrollPane({showArrows:true, scrollbarWidth:8});
		}
		
		$('#enderecos input:last').focus();
		
		$(".bt-excluir").click(function(){
			$('#enderecos').jScrollPane({showArrows:true, scrollbarWidth:8});
			$(this).parent().remove();
			//$('#enderecos').css({"height":($('#enderecos').height()-27)+"px"});
			$('#enderecos input:last').focus();
			$c++;
			$c--;
		});
	});
	
	$("#cadastro-festas input[name=email]").bind('blur change',function(){
		if($(this).val()!=""){
			$.post('acoes.php','a=verifica-email&'+$("#cadastro-festas").serialize(),function(s){
				if(s==1){
					$("#cadastro-festas #password").show();
					$("#cadastro-festas #novo-cadastro").hide();
					$("#error").hide();
					$("#error").html("");
				}else{
					$msg = '- Para criar sua lista VIP você precisa se cadastrar, <a href="cadastro.php" style="color:#e212a6">clique aqui</a><br>';
					$("#cadastro-festas #password").hide();
					$("#error").show();
					$("#error").html($msg);
					
				}
			});
		}
		
	});
	
	$("input[name=residencial],input[name=telefone],input[name=celular]").mask("(99) 9999-9999");
	$("input[name=cep]").mask("99999-999");
	
	$("#senha").submit(function(){
		$("#error").show();
		$("#error").addClass("sucess");
		$("#error").html("Aguarde...");
		$.post('acoes.php?r'+Math.random(),'a=esqueci-minha-senha&'+$("#senha").serialize(),function(s){
			if(s=="1"){
				$("#error").show();
				$("#error").addClass("sucess");
				$("#error").html("Sua senha foi informada para o email abaixo.");
				
				$("#cadastro").find(':input').each(function() {
					switch(this.type) {
						case 'password':
						case 'select-multiple':
						case 'select-one':
						case 'text':
						case 'textarea':
							$(this).val('');
							break;
						case 'checkbox':
						case 'radio':
							this.checked = false;
					}
				});
			}else{
				$("#error").show();
				$("#error").removeClass("sucess");
				$("#error").html(s);
			}
			
		});
		return false;
	});
	

	$("#login").submit(function(){
		$("#error").show();
		$("#error").addClass("sucess");
		$("#error").html("Aguarde...");
		$.post('acoes.php?r'+Math.random(),'a=login&'+$("#login").serialize(),function(s){
			if(s=="1"){
				window.location = 'cadastro_editar.php';
				
				$("#login").find(':input').each(function() {
					switch(this.type) {
						case 'password':
						case 'select-multiple':
						case 'select-one':
						case 'text':
						case 'textarea':
							$(this).val('');
							break;
						case 'checkbox':
						case 'radio':
							this.checked = false;
					}
				});
			}else{
				$("#error").show();
				$("#error").removeClass("sucess");
				$("#error").html(s);
			}
			
		});
		return false;
	});


	$("#flyer form input[name=email]").focus(function(){
		$(this).val("");
	});
	$("#flyer form input[name=email]").blur(function(){
		if($(this).val()==""){
			$(this).val($(this).attr("title"));
		}
	});

	
	$("#contato").submit(function(){
		$("#error").show();
		$("#error").addClass("sucess");
		$("#error").html("Aguarde...");
		$.post('acoes.php?r'+Math.random(),'a=contato&'+$("#contato").serialize(),function(s){
			if(s=="1"){
				$("#error").show();
				$("#error").addClass("sucess");
				$("#error").html("Sua mensagem foi enviada com sucesso.");
				
				$("#cadastro").find(':input').each(function() {
					switch(this.type) {
						case 'password':
						case 'select-multiple':
						case 'select-one':
						case 'text':
						case 'textarea':
							$(this).val('');
							break;
						case 'checkbox':
						case 'radio':
							this.checked = false;
					}
				});
			}else{
				$("#error").show();
				$("#error").removeClass("sucess");
				$("#error").html(s);
			}
			
		});
		return false;
	});
	
	$("#cadastro").submit(function(){
		$("#error").show();
		$("#error").addClass("sucess");
		$("#error").html("Aguarde...");
		$.post('acoes.php?r'+Math.random(),'a=cadastro&'+$("#cadastro").serialize(),function(s){
			if(s=="1"){
				$("#error").show();
				$("#error").addClass("sucess");
				$("#error").html("Cadastro realizado com sucesso. Aguarde confirmação por email. Sem esta confirmação você não poderá solicitar inclusão de seu nome na lista de convidados.");
				
				$("#cadastro").find(':input').each(function() {
					switch(this.type) {
						case 'password':
						case 'select-multiple':
						case 'select-one':
						case 'text':
						case 'textarea':
							$(this).val('');
							break;
						case 'checkbox':
						case 'radio':
							this.checked = false;
					}
				});
			}else{
				$("#error").show();
				$("#error").removeClass("sucess");
				$("#error").html(s);
			}
			
		});
		return false;
	});

	$("#cadastro-editar").submit(function(){
		$("#error").show();
		$("#error").addClass("sucess");
		$("#error").html("Aguarde...");
		$.post('acoes.php?r'+Math.random(),'a=cadastro-editar&'+$("#cadastro-editar").serialize(),function(s){
			if(s=="1"){

				window.location = 'cadastro_editar.php?e=1';
				
				/*$("#cadastro-editar").find(':input').each(function() {
					switch(this.type) {
						case 'password':
						case 'select-multiple':
						case 'select-one':
						case 'text':
						case 'textarea':
							$(this).val('');
							break;
						case 'checkbox':
						case 'radio':
							this.checked = false;
					}
				});*/
			}else{
				$("#error").show();
				$("#error").removeClass("sucess");
				$("#error").html(s);
			}
			
		});
		return false;
	});
	
	$("#cadastro-festas").submit(function(){
		$("#error").show();
		$("#error").addClass("sucess");
		$("#error").html("Aguarde...");
		$.post('acoes.php?r'+Math.random(),'a=cadastro-festas&'+$("#cadastro-festas").serialize(),function(s){
			if(s=="1"){
				$("#error").show();
				$("#error").addClass("sucess");
				$("#error").html("Lista enviada com sucesso!");
				
				$("#cadastro-festas").find(':input').each(function() {
					switch(this.type) {
						case 'password':
						case 'select-multiple':
						case 'select-one':
						case 'text':
						case 'textarea':
							$(this).val('');
							break;
						case 'checkbox':
						case 'radio':
							this.checked = false;
					}
				});
			}else{
				$("#error").show();
				$("#error").removeClass("sucess");
				$("#error").html(s);
			}
			
		});
		return false;
	});

	$("#stage li image").click(function(){
		alert($(this).index());
	});
	
	$("#cadastro-festas2").submit(function(){
		$("#error").removeClass("sucess");
		$msg= "";
		$email = $("input[name=email]").val();
		$festas = $("input[name=festas]:checked");
		$convidados = $("input[name=convidados]:empty");
		$p = $("input[name=convidados[]]").serialize();
		$senha = $("input[name=password]").val();
		$f = $("input[name=festas]").val();
		$.post('acoes.php?r'+Math.random(),'a=verifica-email&email='+$email,function(s){
			$("input[name=t]").val(s);
			
			if(!checkMail($email)){
				$msg += "- Endereço de email inválido.<br>";
			}else if($("input[name=t]").val()==0){
				$("#cadastro-festas #password").hide();
				$msg += '- Para criar sua lista VIP você precisa se cadastrar, <a href="cadastro.php" style="color:#e212a6">clique aqui</a><br>';
			}else{
				$("#cadastro-festas #password").show();
				$("#cadastro-festas #novo-cadastro").hide();
				$("#error").hide();
				$("#error").html("");
			}
			
			if($("#cadastro-festas #password").is(":visible") && $senha==""){
				$msg += "- Digite sua senha.<br>";
			}
			
			if($festas.length==0){
				$msg += "- Escolha a festa.<br>";
			}
			
			
			if($msg!=""){
				$("#error").removeClass("sucess");
				$("#error").show();
				$("#error").html($msg);
			}else{
				$("#error").show();
				$("#error").html("Aguarde, enviando...");
				$("#error").addClass("sucess");
				$("#cadastro-festas input").attr({"disabled":"disabled"})
				
				
				$.post('acoes.php?r'+Math.random(),'a=lista-vip&email='+$email+"&festas="+$f+"&"+$p+"&password="+$senha,function(s){
					
					$("#cadastro-festas input").attr({"disabled":""})
					$("#error").removeClass("sucess");
					if(s=="2"){	
						$msg += "- Senha inválida.<br>";
						$("#error").show();
						$("#error").html($msg);
					}
					if(s=="1"){
						$("#error").addClass("sucess");
						$msg += "Lista enviada com sucesso!<br>";
						$("#error").show();
						$("#error").html($msg);
						
						$("#cadastro-festas").find(':input').each(function() {
							switch(this.type) {
								case 'password':
								case 'select-multiple':
								case 'select-one':
								case 'text':
								case 'textarea':
									$(this).val('');
									break;
								case 'checkbox':
								case 'radio':
									this.checked = false;
							}
						});
					

					}
					if(s=="0"){
						$msg += "- Erro ao enviar a lista.<br>";
						$("#error").show();
						$("#error").html($msg);
					}
				})
		
			}
		});
		
		
		return false;
	});


	
});

$show = true;
$index = 0;
function showBox(){
	if($show == true){
		if($index==0){
			$(".numbera:eq("+($index)+")").stop(false,false).animate({"margin-left":-120,"opacity":0});
			$(".numberb:eq("+($index)+")").stop(false,false).animate({"margin-left":0,"opacity":1});
			$(".titulo:eq("+($index)+")").css({color:"#fec353"});
		}
		if($index>0 && $index <= $(".box").length){
			$(".numberb:eq("+($index-1)+")").stop(false,false).animate({"margin-left":-120,"opacity":0});
			$(".numbera:eq("+($index-1)+")").stop(false,false).animate({"margin-left":0,"opacity":1});
			$(".titulo:eq("+($index-1)+")").css({color:"white"});

			$(".numbera:eq("+($index)+")").stop(false,false).animate({"margin-left":-120,"opacity":0});
			$(".numberb:eq("+($index)+")").stop(false,false).animate({"margin-left":0,"opacity":1});
			$(".titulo:eq("+($index)+")").css({color:"#fec353"});
		}

		if($index==$(".box").length){
			$index=0;
			$(".numberb:eq("+($(".box").length)+")").stop(false,false).animate({"margin-left":-120,"opacity":0});
			$(".numbera:eq("+($(".box").length)+")").stop(false,false).animate({"margin-left":0,"opacity":1});
			$(".titulo:eq("+($(".box").length)+")").css({color:"white"});

			$(".numbera:eq("+($index)+")").stop(false,false).animate({"margin-left":-120,"opacity":0});
			$(".numberb:eq("+($index)+")").stop(false,false).animate({"margin-left":0,"opacity":1});
			$(".titulo:eq("+($index)+")").css({color:"#fec353"});
			$index++;
		}else{
			$index++;
		}
		
		$src = $(".thumb:eq("+($index)+")").attr("src");
		$("#foto img").attr("src",$src);
		$("#foto img").fadeOut(100);
		$("#foto img").fadeIn(100);
		
		

	}
}



var helvetica = {
  src: 'flash/helvetica.swf',
  wmode: 'transparent'
};
var trebushet = {
  src: 'flash/trebushet.swf',
  wmode: 'transparent'
};
sIFR.activate(helvetica, trebushet);
sIFR.replace(helvetica, {
  selector: '#m ul li'
  ,css:[
	 'a{ color: #fec353; text-decoration:none;}'  
     ,'a:link { color: #FFFFFF; }'  
     ,'a:hover { color: #fec353; }' 
	]
});
sIFR.replace(trebushet, {
  selector: '.titulobranco'
  ,css:['.sIFR-root {color:#ffffff; font-size:20px; }']
});
sIFR.replace(trebushet, {
  selector: '.tituloamarelo'
  ,css:['.sIFR-root {color:#fec353; font-size:25px; }']
});
sIFR.replace(trebushet, {
  selector: '.tituloamarelo-2'
  ,css:['.sIFR-root {color:#fec353; font-size:20px; }']
});
sIFR.replace(trebushet, {
  selector: '.titulobranco-2'
  ,css:['.sIFR-root {color:#ffffff; font-size:16px;}', 'a{color:#ffffff; text-decoration:none}', 'a:hover{color:#ffffff; text-decoration:none}']
});

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
	return er.test(mail);
}

function SomenteNumero(e){
	
    var tecla=(window.event)?event.keyCode:e.which;
	
    if((tecla > 47 && tecla < 58) || tecla == 0) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function open360(){
	Shadowbox.open({
        content:    'flash/360.swf',
        player:     "swf",
        height:     600,
        width:      800
    });
}
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
	
}
