/*!
 * Conjunto de instruções para o site ronaldogc.com
 * http://ronaldogc.com/
 */

jQuery.fn.fadeToggle = function(speed, easing, callback) {
    return this.animate({opacity: "toggle"}, speed, easing, callback);
};

$(document).ready(function(){
	$("a, form input[name=enviar]").focus(function(){
		$(this).blur();
	});
	
	$("#foto-home").cycle({
		fx: "fade" 
	});


	$("form").ajaxForm({ 
		// target identifies the element(s) to update with the server response 
		target: "#retorno-msg",
		url: "enviar.php",
		
		// success identifies the function to invoke when the server response 
		// has been received; here we apply a fade-in effect to the new content 
		success: function() { 
			$('#retorno-msg').fadeIn('slow'); 
			if($("#retorno-msg>p").length > 0){
				$("#foto-home").css("display", "none");
				$("form").css("display", "block");
				var padd;
				switch ($("fieldset>span>p").length) {
					case 1:
						padd = 200
						break
					case 2:
						padd = 220
						break
					default:
						padd = 180
				}
				$("#content-block").css("padding-bottom", padd+"px");
			}
		}
	}); 



	/*
	$("form input[name=enviar]").click(function(){
		window.Submit.disabled = true;
		alert("inicio ajax!");
		//var abc = "nome=" + $("input[name=nome]").val() + "&email=" + $("input[name=email]").val() + "&assunto=" + $("input[name=assunto]").val() + "&mensagem=" + $("textarea[name=mensagem]").val();
		$.post("enviar.php", { nome: $("input[name=nome]").val(), email: $("input[name=email]").val(), assunto: $("input[name=assunto]").val(), mensagem: $("textarea[name=mensagem]").val() },
			function(data){
			$("#retorno-msg").html(html);
			alert("Data Loaded: " + html);
		});

		alert("fim ajax! uhuull: " + retornoAjax);
		
		return false;
	});*/
	

	/*$("form").submit(function(){
		alert("inicio ajax!");
		var abc = "nome=" + $("input[name=nome]").val() + "&email=" + $("input[name=email]").val() + "&assunto=" + $("input[name=assunto]").val() + "&mensagem=" + $("textarea[name=mensagem]").val();
		$.ajax({
			type: "POST",
			url: "enviar.php",
			data: "nome=" + $("input[name=nome]").val() + "&email=" + $("input[name=email]").val() + "&assunto=" + $("input[name=assunto]").val() + "&mensagem=" + $("textarea[name=mensagem]").val(),
			
			success: function(html){
				$("#retorno-msg").html(html);
			}
		});
		alert("fim ajax! uhuull: " + abc);
		return false;
	});
	*/


	function limparCampos(){
		$("form input[type='text'], form textarea").each(function() {
			$(this).val("");
		});
		$("fieldset>span").empty();
	};


	/*$("form").has("fieldset>small", function() {
		$("#foto-home").css("display", "none");
		$("form").css("display", "block");
		$("#content-block").css("padding-bottom", "170px");
	}, function() {
		$("#mensagem").css("display", "none");
		$("#foto-home").css("display", "block");
	});*/
	//alert($("fieldset>small").html());

	
	$(".pirobox_gall_mus", ".pirobox_gall_lug", ".pirobox_gall_pes", ".pirobox_gall_fes").piroBox({
		my_speed: 300, //animation speed
		bg_alpha: 0.6, //background opacity
		radius: 4, //caption rounded corner
		scrollImage : false, // true == image follows the page _|_ false == image remains in the same open position
						   // in some cases of very large images or long description could be useful.
		slideShow : 'false', // true == slideshow on, false == slideshow off
		slideSpeed : 3, //slideshow
		pirobox_next : 'piro_next_out', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
		pirobox_prev : 'piro_prev_out', // Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
		close_all : '.piro_close, .piro_overlay' // add class .piro_overlay(with comma)if you want overlay click close piroBox
	});
	
	
	$("#mus").click(function(){
		$("#foto-home").fadeOut('slow', function() {
			$("#item-menu-lug div, #item-menu-pes div, #item-menu-fes div").slideUp('fast');
			$("form").fadeOut('fast');
			limparCampos();
			$("#item-menu-mus div").slideToggle('fast', function() {
				if($("#item-menu-mus div").css("display")=="none"){
					$("#content-block").css("padding-bottom", "130px");
					$("#foto-home:hidden").fadeIn('slow');
				}
				else {
					$("#content-block").css("padding-bottom", "60px");
				}
			});
		});
	});
	$("#lug").click(function(){
		$("#foto-home").fadeOut('slow', function() {
			$("#item-menu-mus div, #item-menu-pes div, #item-menu-fes div").slideUp('fast');
			$("form").fadeOut('fast');
			limparCampos();
			$("#item-menu-lug div").slideToggle('fast', function() {
				if($("#item-menu-lug div").css("display")=="none"){
					$("#content-block").css("padding-bottom", "130px");
					$("#foto-home:hidden").fadeIn('slow');
				}
				else {
					$("#content-block").css("padding-bottom", "60px");
				}
			});
		});
	});
	$("#pes").click(function(){
		$("#foto-home").fadeOut('slow', function() {
			$("#item-menu-mus div, #item-menu-lug div, #item-menu-fes div").slideUp('fast');
			$("form").fadeOut('fast');
			limparCampos();
			$("#item-menu-pes div").slideToggle('fast', function() {
				if($("#item-menu-pes div").css("display")=="none"){
					$("#content-block").css("padding-bottom", "130px");
					$("#foto-home:hidden").fadeIn('slow');
				}
				else {
					$("#content-block").css("padding-bottom", "60px");
				}
			});
		});
	});
	$("#fes").click(function(){
		$("#foto-home").fadeOut('slow', function() {
			$("#item-menu-mus div, #item-menu-lug div, #item-menu-pes div").slideUp('fast');
			$("form").fadeOut('fast');
			limparCampos();
			$("#item-menu-fes div").slideToggle('fast', function() {
				if($("#item-menu-fes div").css("display")=="none"){
					$("#content-block").css("padding-bottom", "130px");
					$("#foto-home:hidden").fadeIn('slow');
				}
				else {
					$("#content-block").css("padding-bottom", "60px");
				}
			});
		});
	});
	$("#con").click(function(){
		$("#foto-home").fadeOut('slow', function() {
			$("#item-menu-mus div, #item-menu-lug div, #item-menu-pes div, #item-menu-fes div").slideUp('fast');
			$("form").fadeToggle('fast', function() {
				if($("form").css("display")=="none"){
					limparCampos();
					$("#content-block").css("padding-bottom", "130px");
					$("#foto-home:hidden").fadeIn('slow');
				}
				else {
					switch ($("fieldset>span>p").length) {
						case 1:
							padd = 190
							break
						case 2:
							padd = 210
							break
						default:
							padd = 170
					}
					$("#content-block").css("padding-bottom", padd+"px");
				}
			});
		});
	});	
});
