$(function() {
		   
	$.history.init(carrega);
	$('#listaModalidades a').click(function(e) {
		var url = $(this).attr('href');
		url = url.replace(/^.*#/, '');
		$.history.load(url);
		return false;
	});
	
	$("#cpf").mask("999.999.999-99",{placeholder:" "});
	$("#telefone").mask("(99) 9999-9999",{placeholder:" "});
	$("#celular").mask("(99) 9999-9999",{placeholder:" "});
	$("#cep").mask("99999-999",{placeholder:" "});
	$("#nascimento").mask("99/99/9999",{placeholder:" "});
	
	$("input[name='cep']").blur(function() {
		var cep = $(this).val();
		
		$.get('../wp-content/themes/TopFitness/incs/buscarendereco.php?cep=' + cep, function(retorno) {
			eval("var arr = "+retorno); //cria objeto com o resultado
			$("#endereco").val(arr.rua);
			$("#bairro").val(arr.bairro);
			$("#cidade").val(arr.cidade);
			$("#uf").val(arr.uf);
		});
	});
	
	$("#listaModalidades img").click(function () {
		var imgs = $("#listaModalidades").find("img");
		imgs.each(function (i, img) {
			var off = $(img).attr('src').replace('white.png','white-hover.png');
			$(img).attr('src',off);
		});
		var on = $(this).attr('src').replace('-hover.png','.png');
		$(this).attr('src',on);
	});
	
	$("#listaPlanos li").click(function (){
		var id = $(this).attr("id");
		$("#hiddenPlanosContent div").hide();
		$("." + id).show("slow");
	});
	
	$("#listaAulas li").click(function (){
		var id = $(this).attr("id");
		$(this).parent().find("a").css('color','#fff');
		$(this).children().css('color','#fff600');
		$("#hiddenSalas div").hide();
		$("." + id).show("slow");
	});
	
	$("#Slide2").jFlow({
			controller: ".jFlowControlBig", // must be class, use . sign
			slideWrapper : "#jFlowSliderBig", // must be id, use # sign
			slides: "#homeSlides",  // the div where all your sliding divs are nested in
			selectedWrapper: "jFlowSelectedBig",  // just pure text, no sign
			width: "766px",  // this is the width for the content-slider
			height: "389px",  // this is the height for the content-slider
			prev: ".jFlowPrevBig", // must be class, use . sign
			next: ".jFlowNextBig", // must be class, use . sign
			duration: 400,
			auto: false
    });
	$('#slider').jcarousel({
    	wrap: 'circular'
    });
	
	$("form").submit(function () {
		$('#form-response').hide();
		var url = '../wp-content/themes/TopFitness/incs/formmail.php';
		var campos = $(this).serialize();
		$.post(url, campos, function(retorno) {
			
			if (retorno == 'error')
			{
				
			}
			else
			{
				$('#form-response').html(retorno);
				$('#form-response').show();
			}
			//$('html, body').animate({scrollTop:0}, 'slow');
		});
		return false;
	});
});

function carrega(postID)
{
	if (postID)
	{
		$("#ajaxContent").html("<p>Aguarde, carregando...</p>");
		$.ajax({
			type: 'POST',
			url: '/wp-admin/admin-ajax.php',
			data: 'action=carregaPost&postID=' + postID,
			success: function( response )
			{
				$("#ajaxContent").hide();
				$("#ajaxContent").html(response);
				$("#ajaxContent").show("slow");
				Cufon.replace('h2');
				Cufon.now();
			}
		});
	}
}

function imprimir(id, titulo)
{
	$('#' + id).printArea({
		mode:'popup',
		popHt: 400,
		popWt: 1024,
		popX: 0,
		popY: 0,
		popTitle: titulo,
		popClose: true
	});
	return false;
}
