jQuery(function($) {
	$("#contenedor_formulario label").live('click',function(){
		$(this).siblings('input').css('color','#B71B02').focus();
		$(this).css('display','none');
	});
	
	$("#contenedor_formulario input:text").val('');
	$("#contenedor_formulario textarea").val('');
	
	$("#contenedor_formulario input").live('focus',function(){
		$(this).siblings('label').css('display','none');
	});
	$("#contenedor_formulario input").live('blur',function(){
		if($(this).hasClass('error')==false && $(this).val() == "")
			$(this).siblings('label').css('display','block');
		});
	$("#contenedor_formulario textarea").live('focus',function(){
 		$(this).siblings('label').css('display','none');
	});
	$("#contenedor_formulario textarea").live('blur',function(){
		if($(this).hasClass('error')==false && $(this).val() == "")
			$(this).siblings('label').css('display','block');
	});
	
//carrusel para galerias
	$(".prev_galery").live('click',function(){
		var div_padre = $(this).parent("#content_galeria,#content_galeria_testimonios");
		var posicion = parseInt($(this).parent().find(".ngg-galleryoverview").css("left").split("px")[0]);
		posicion += 234;
		$(this).parent().find(".ngg-galleryoverview").animate({"left":posicion+"px"},{
			duration: 700,
    		//queue:false,
    		complete:function(){
    			div_padre.find(".ngg-gallery-thumbnail-box:last").prev().prev().clone().prependTo(div_padre.find(".ngg-galleryoverview"));
    			div_padre.find(".ngg-gallery-thumbnail-box:last").remove();
    			div_padre.find(".ngg-galleryoverview").css({"left":"-198px"});
    			div_padre.find("a:first").fancybox();
   	
    		}
    	});
	});
	$(".next_galery").live('click',function(){
		var div_padre = $(this).parent("#content_galeria,#content_galeria_testimonios");
		var posicion = parseInt($(this).parent().find(".ngg-galleryoverview").css("left").split("px")[0]);
		posicion -= 234;
		$(this).parent().find(".ngg-galleryoverview").animate({"left":posicion+"px"},{
    		duration: 700,
    		queue:false,
    		complete:function(){
    			div_padre.find(".ngg-gallery-thumbnail-box:first").next().clone().appendTo(div_padre.find(".ngg-galleryoverview"));
    			div_padre.find(".ngg-gallery-thumbnail-box:first").remove();
    			div_padre.find(".ngg-galleryoverview").css({"left":"-198px"});
    			div_padre.find("a:last").fancybox();
			}
		});
	});
	
	$("#content_galeria,#content_galeria_testimonios").each(function(){
		$(this).find(".ngg-galleryoverview").wrap("<div class='wrapper-ngg-gallery'/>");
		$(this).find(".ngg-galleryoverview").css({"left":"-198px"});
		$(this).find(".ngg-gallery-thumbnail-box:first").clone().appendTo($(this).find(".ngg-galleryoverview"));
		$(this).find(".ngg-clear:first").remove();
		$(this).find(".ngg-gallery-thumbnail-box:last").prev(".ngg-gallery-thumbnail-box").clone().prependTo($(this).find(".ngg-galleryoverview"));
	});	
	
//fin carrusel


	
	//Textos formularios
	$(".frm input[type='text']").click(function(){
		if ( $(this).val() == $(this).attr("rel") || !$(this).attr("rel")  ) {
			$(this).attr("rel",  $(this).val() ).val("");
		}
	});
	$(".frm input[type='text']").blur(function(){
		if ( $(this).val() == "" ){
			$(this).val( $(this).attr("rel") );
		}
	});

	//Effect Footer
	
	$("#footer_slide").show();
		$("a.ocultar").click(function () {
		    $("#footer_slide").slideUp('fast');
		$("#footer_slide2").slideToggle(400);
		return false;
	});
		$("a.mostrar").click(function () {
		    $("#footer_slide2").slideUp('fast');
		$("#footer_slide").slideToggle(400);
		return false;
	});
	
	// Formularios
	
	$("#form_matriculate").show();
	$('a.matriculate').css('background-position', '0px -42px');
	$('a.matriculategrupo').click(function() {
		$('#form_matriculate').fadeOut(); 
	    $('#form_matriculate_grupo').fadeIn();
	    $('a.matriculategrupo').css('background-position', '0px -126px');
	    $('a.matriculate').css('background-position', '0px 0px');
	    $("#summary").css('display','none');
		return false;
	  });
	
	$('a.matriculate').click(function() {
		$('#form_matriculate_grupo').fadeOut(); 
	    $('#form_matriculate').fadeIn();
	    $('a.matriculategrupo').css('background-position', '0px -84px');
	    $('a.matriculate').css('background-position', '0px -42px');
	    $("#summary").css('display','none');
		return false;
	  });
	
	// Tooltip TIP TIP
	
	$('#difusion_social a[title], a.subir[title]').tipsy({gravity: 'e'}); // nw | n | ne | w | e | sw | s | se
	$('a.ocultar[title], a.mostrar[title]').tipsy({gravity: 's'}); // nw | n | ne | w | e | sw | s | se
	
	// FANCYBOX
	
	$("a.fancybox, #content_galeria a, #content_galeria_testimonios a").fancybox();
	$(".jcarousel-next-horizontal, .jcarousel-prev-horizontal").live('click',function(){
		$("a.fancybox").fancybox();
	});
	
	/*$("a.social_contact").fancybox({
			'width'				: '75%',
			'height'			: '75%',
	        'autoScale'     	: false,
	        'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});*/
		
	/*	$("a.social_contact").click(function() {
		    $.fancybox.showActivity();
		    $.fancybox({
		        'type'              : 'iframe',
		        'width'             : '40%',
		        'height'            : '90%',
		        'href'              : '/voluntariado/index.php/voluntariado-2011/formulario-contacto-voluntariado'
		    });

		});
	
		*/
	
	// FUNCIONES SCROLL
	
	$('a.hazte-voluntario').click( function(){
		$.scrollTo('#seccion_haztevoluntario',700);
		return false;
	});
	$('#btn_matriculate_aqui').click( function(){
		$.scrollTo('#seccion_haztevoluntario',700);
		return false;
	});
	$('a.el-voluntariado').click( function(){
		$.scrollTo('#seccion_elvoluntariado',700);
		return false;
	});
	$('a.testimoniales').click( function(){
		$.scrollTo('#seccion_testimoniales',700);
		return false;
	});
	$('a.test-vocacional').click( function(){
		$.scrollTo('#seccion_testvocacional',700);
		return false;
	});
	$('a.subir').click( function(){
		$.scrollTo('#wrap',700);
		return false;
	});
	
	// Variable google analytics de los inputs de los formularios
	$("#contenedor_formulario #formulario input").change(function(){
		var nombre = $(this).attr('name');
		 _gaq.push(['_trackPageview', '/voluntariado/matriculate/'+nombre]);
	});
	$("#contenedor_formulario #formulario select").change(function(){
		var nombre = $(this).attr('name');
		 _gaq.push(['_trackPageview', '/voluntariado/matriculate/'+nombre]);
	});
	$("#contenedor_formulario #formulario textarea").change(function(){
		var nombre = $(this).attr('name');
		 _gaq.push(['_trackPageview', '/voluntariado/matriculate/'+nombre]);
	});
	$("#form_matriculate_grupo input").change(function(){
		var nombre = $(this).attr('name');
		 _gaq.push(['_trackPageview', '/voluntariado/matriculate_grupo/'+nombre]);
	});
	$(" #form_matriculate_grupo select").change(function(){
		var nombre = $(this).attr('name');
		 _gaq.push(['_trackPageview', '/voluntariado/matriculate_grupo/'+nombre]);
	});
	$(" #form_matriculate_grupo textarea").change(function(){
		var nombre = $(this).attr('name');
		 _gaq.push(['_trackPageview', '/voluntariado/matriculate_grupo/'+nombre]);
	});
	
	// SCROLL
	
	$('#content_video').jScrollPane();
	
	
	//Test Voluntariado
	
	$("#slide-final").hide();
	$("#slide-runner").hide();
	$total = 0;
	$("#slide-nav span.uno").addClass("now");
	
	$("#slide-inicio #btn_comenzar").click(function () {
		    $("#slide-inicio").hide();
		    $("#slide-runner").slideDown();
		return false;
	});
	$("#slide-final a#btn_volver").click(function () {
		    $("#slide-final").hide();
		    $("#slide-inicio").slideDown();
			$("#p-wrap").animate({"left": "+=2004px"}, "");
			$("#slide-nav span.cinco").removeClass("now");
			$("#slide-nav span.uno").addClass("now");
			$('#slide-final span').remove();
			$total = 0;
		return false;
	});
	$("#pregunta-1 .resp_si").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.uno").removeClass("now");
			$("#slide-nav span.dos").addClass("now");
			$total += parseInt(1);
		return false;
	});
	$("#pregunta-1 .resp_no").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.uno").removeClass("now");
			$("#slide-nav span.dos").addClass("now");
		return false;
	});
	$("#pregunta-2 .resp_si").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.dos").removeClass("now");
			$("#slide-nav span.tres").addClass("now");
			$total += parseInt(1);
			
		return false;
	});
	$("#pregunta-2 .resp_no").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.dos").removeClass("now");
			$("#slide-nav span.tres").addClass("now");
		return false;
	});
	$("#pregunta-3 .resp_si").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.tres").removeClass("now");
			$("#slide-nav span.cuatro").addClass("now");
			$total += parseInt(2);
		return false;
	});
	$("#pregunta-3 .resp_no").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.tres").removeClass("now");
			$("#slide-nav span.cuatro").addClass("now");
		return false;
	});
	$("#pregunta-4 .resp_si").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.cuatro").removeClass("now");
			$("#slide-nav span.cinco").addClass("now");
			$total += parseInt(2);
		return false;
	});
	$("#pregunta-4 .resp_no").click(function () {
			$("#p-wrap").animate({"left": "-=501px"}, "");
			$("#slide-nav span.cuatro").removeClass("now");
			$("#slide-nav span.cinco").addClass("now");
		return false;
	});
	
	//Resultados
	
	$animo = '<span><h4>&iexcl;&Aacute;nimo!</h4><p class="exito">Todos tenemos facultades para construir un pa&iacute;s m&aacute;s justo y solidario. Si te lo propones, t&uacute; puedes llegar a ser un gran voluntario.</p><a target="_blank" href="http://www.facebook.com/share.php?s=100&p[url]=http://voluntariado.hogardecristo.cl?o=t&p[images][0]=http://hogardecristo.cardumen.cl/voluntariado/wp-content/themes/theme_voluntariado2011/images/public_facebook.jpg&p[title]=Ha respondido el test de Vocaci&oacute;n Solidaria Voluntariado 2011 Hogar de Cristo y su resultado fue:&p[summary]=&iexcl;&Aacute;nimo!: Todos tenemos facultades para construir un pa&iacute;s m&aacute;s justo y solidario. Si te lo propones, t&uacute; puedes llegar a ser un gran voluntario." id="btn_compartir_resultado" >Comparte este resultado</a></span>';
	
	$conganas = '<span><h4>Con ganas de ser solidario</h4><p class="exito">Tienes vocaci&oacute;n solidaria, pero quiz&aacute;s no has encontrado el lugar indicado para ponerla en pr&aacute;ctica. Descubre al Voluntario que hay en ti.</p><a target="_blank" href="http://www.facebook.com/share.php?s=100&p[url]=http://voluntariado.hogardecristo.cl?o=t&p[images][0]=http://hogardecristo.cardumen.cl/voluntariado/wp-content/themes/theme_voluntariado2011/images/public_facebook.jpg&p[title]=Ha respondido el test de Vocaci&oacute;n Solidaria Voluntariado 2011 Hogar de Cristo y su resultado fue:&p[summary]=Con ganas de ser solidario: Tienes vocaci&oacute;n solidaria, pero quiz&aacute;s no has encontrado el lugar indicado para ponerla en pr&aacute;ctica. Descubre al Voluntario que hay en ti." id="btn_compartir_resultado">Comparte este resultado</a></span>';
	
	$muysolidario = '<span><h4>Muy Solidario</h4><p class="exito">&iexcl;Felicitaciones! Eres una persona comprometida con los que m&aacute;s sufren. Te invitamos a desarrollar tu vocaci&oacute;n en Hogar de Cristo.</p><a target="_blank" href="http://www.facebook.com/share.php?s=100&p[url]=http://voluntariado.hogardecristo.cl?o=t&p[images][0]=http://hogardecristo.cardumen.cl/voluntariado/wp-content/themes/theme_voluntariado2011/images/public_facebook.jpg&p[title]=Ha respondido el test de Vocaci&oacute;n Solidaria Voluntariado 2011 Hogar de Cristo y su resultado fue:&p[summary]=Muy Solidario: &iexcl;Felicitaciones! Eres una persona comprometida con los que m&aacute;s sufren. Te invitamos a desarrollar tu vocaci&oacute;n en Hogar de Cristo." id="btn_compartir_resultado">Comparte este resultado</a></span>';
	
	//Mostrar Resultados
	
	$("#pregunta-5 .resp_si").click(function () {
			$total += parseInt(2);
			$("#slide-runner").hide();
		    $("#slide-final").slideDown();
			if ($total < 3){
				_gaq.push(['_trackPageview', '/test_vocacion/completo/resultado/Animo']);
				$("#slide-final").prepend($animo);
				$("#btn_compartir_resultado").attr("onclick", "javascript:_gaq.push(['_trackPageview','/test_vocacion/completo/comparte']);");
			}
			if ($total > 2 && $total < 6){
				_gaq.push(['_trackPageview', '/test_vocacion/completo/resultado/Con-ganas']);
				$("#slide-final").prepend($conganas);
				$("#btn_compartir_resultado").attr("onclick", "javascript:_gaq.push(['_trackPageview','/test_vocacion/completo/comparte']);");
			}
			if ($total > 5){
				_gaq.push(['_trackPageview', '/test_vocacion/completo/resultado/Muy-solidario']);
				$("#slide-final").prepend($muysolidario);
				$("#btn_compartir_resultado").attr("onclick", "javascript:_gaq.push(['_trackPageview','/test_vocacion/completo/comparte']);");
			}
		return false;
	});
	
	$("#pregunta-5 .resp_no").click(function () {
			$total += parseInt(0);
			$("#slide-runner").hide();
		    $("#slide-final").slideDown();
			if ($total < 3){
				_gaq.push(['_trackPageview', '/test_vocacion/completo/resultado/Animo']);				
				$("#slide-final").prepend($animo);
				$("#btn_compartir_resultado").attr("onclick", "javascript:_gaq.push(['_trackPageview','/test_vocacion/completo/comparte']);");
			}
			if ($total > 2 && $total < 6){
				_gaq.push(['_trackPageview', '/test_vocacion/completo/resultado/Con-ganas']);
				$("#slide-final").prepend($conganas);
				$("#btn_compartir_resultado").attr("onclick", "javascript:_gaq.push(['_trackPageview','/test_vocacion/completo/comparte']);");
			}
			if ($total > 5){
				_gaq.push(['_trackPageview', '/test_vocacion/completo/resultado/Muy-solidario']);
				$("#slide-final").prepend($muysolidario);
				$("#btn_compartir_resultado").attr("onclick", "javascript:_gaq.push(['_trackPageview','/test_vocacion/completo/comparte']);");
			}
		return false;
	});
	
});

	

