/* Author:

*/

//pestañas

$(document).ready(function() {

	//Default Action
	$(".tab_content").not($(".tab_content[rel*=primero]")).hide(); //Hide all content
	//$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	//$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		//$("ul.tabs li").removeClass("active"); //Remove any "active" class
		//$(this).addClass("active"); //Add "active" class to selected tab
                var idactual = $(this).find("a").attr('rel');
		$("#tab1"+idactual).hide(); //Hide all tab content
		$("#tab2"+idactual).hide(); //Hide all tab content
                $("#tab3"+idactual).hide(); //Hide all tab content
                $("#tab4"+idactual).hide(); //Hide all tab content
                
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

 // botones de abrir/cerrar formularios
$(document).ready(function(){ 
 
 		$(".comment_write_buttom").click(function(){
				
				var visible=$("#comment_write_"+$(this).attr("rel")).css('display');
				if (visible=='none') $("#comment_write_"+$(this).attr("rel")).show("slow");
				else $("#comment_write_"+$(this).attr("rel")).hide("slow");
				
				$("#send_email_"+$(this).attr("rel")).hide("slow");
				
				
		
		});
	 
		$(".send_email_buttom").click(function(){
				
				
				var visible=$("#send_email_"+$(this).attr("rel")).css('display');
				if (visible=='none') $("#send_email_"+$(this).attr("rel")).show("slow");
				else $("#send_email_"+$(this).attr("rel")).hide("slow");
				
				$("#comment_write_"+$(this).attr("rel")).hide("slow");	
		
		});
});

//formularios de añadir comentario y enviar por email
$('.comment_write_forms').submit(function() {
    $.ajax({
        type: "POST",
        url: '/opiniones/opinar', //$(this).attr('action'),
        data: $(this).serialize(),
        success: function(datos){
            var resultado = $.parseJSON(datos);
            if (resultado.status=="ok"){
                $("#comment_write_"+resultado.idform).hide("slow");
                $("#comment_write_form"+resultado.idform)[0].reset();
                alert("Tu comentario ha sido enviado. Aparecerá en el listado próximamente. Gracias!");
            }else{
                alert('Ocurrió algun error!'+resultado.status);
            }
        }
    });
});
$('.send_email_forms').submit(function() {
    $.ajax({
        type: "POST",
        url: '/opiniones/send_email', //$(this).attr('action'),
        data: $(this).serialize(),
        success: function(datos){
            var resultado = $.parseJSON(datos);
            if (resultado.status=="ok"){
                $("#send_email_"+resultado.idform).hide("slow");
                $("#send_email_form"+resultado.idform)[0].reset();
                //alert("Tu comentario ha sido enviado. Gracias!");
            }else{
                alert('Ocurrió algun error!'+resultado.status);
            }
        }
    });
});





