$(document).ready(function() {
	var total=0;
	var total1=0;
	var total2=0;
	
	
	$('.contins').hover(function(){
		$(this).stop().animate({color:"#fff",backgroundColor:"#545851"},500);
		$(this).find(".fleins img").attr({src:"../imgs/flecha5.png"});
    },function(){
		if ($(this).parent().is('.cerrado'))
		{
			$(this).stop().animate({color:"#63544a",backgroundColor:"#fff"},800);
			$(this).find(".fleins img").attr({src:"../imgs/flecha3.png"});
		}
    });

	$('.botins').hover(function(){
		$(this).parent().find(".contins").stop().animate({color:"#fff",backgroundColor:"#545851"},500);
		$(this).parent().find(".contins").find(".fleins img").attr({src:"../imgs/flecha5.png"});
    },function(){
		if ($(this).parent().is('.cerrado'))
		{
			$(this).parent().find(".contins").stop().animate({color:"#63544a",backgroundColor:"#fff"},800);
			$(this).parent().find(".contins").find(".fleins img").attr({src:"../imgs/flecha3.png"});
		}
    });
	
	$('.botins,.contins').click(function(){
		if ($(this).parent().is('.cerrado'))
		{
			total=0;
			total1=0;
			total2=0;
			$("input:checked").attr('checked', false);
			$(this).parent().find(".inscripcionint").find(".derins").find(".total .totinput").val(0);
			
			desactivar();
		
			$(this).parent().removeClass("cerrado");
			$(this).parent().addClass("abierto");
		
			if ($(this).is('.contins'))
			{
				$(this).stop().animate({color:"#fff",backgroundColor:"#545851"},500);
				$(this).find(".fleins img").attr({src:"../imgs/flecha5.png"});
				$(this).css({'cursor':'default'});
				$(this).parent().find(".botins").css({'cursor':'default'});
			}
			if ($(this).is('.botins'))
			{
				$(this).parent().find(".contins").stop().animate({color:"#fff",backgroundColor:"#545851"},500);
				$(this).parent().find(".contins").find(".fleins img").attr({src:"../imgs/flecha5.png"});
				$(this).css({'cursor':'default'});
				$(this).parent().find(".contins").css({'cursor':'default'});
			}
			
			//var pos=$(this).parent().attr('id');
			//$('html,body').animate({scrollTop: pos-100}, 1000);
			
			var cual=$(this);
			setTimeout(function(){
				var pos=$(cual).parent().attr('id');
				$('html,body').animate({scrollTop: pos-100}, 1000);
				
				$(cual).parent().find(".inscripcionint").slideDown(1000);
			},1000);
			
			/*var cual=$(this);
			setTimeout(function(){
				//var pos=$(cual).parent().position().top;
				var pos=$(cual).parent().attr('id');
				$('html,body').animate({scrollTop: pos-100}, 1000);
			},1000);*/
		}
    });

	function desactivar()
	{
		home=false;
		$('.inscripcionint').slideUp(1000);
		$('.contins').stop().css({color:"#63544a",'background-color':'#fff'});
		$('.contins,.botins').css({'cursor':'pointer'});
		
		$('.inscripcion').each(function(){
			$(this).removeClass("abierto");
			$(this).addClass("cerrado");
		});
	}



	$(":checkbox").click(function(){
		if ($(this).is('.precio1'))
		{
			if ($(this).parent().parent().find("input.descuento").is(':checked'))
			{
				if (this.checked)
					total1+=parseFloat(this.value-(this.value*$(this).parent().parent().find("input.descuento").val()));
				else
					total1-=parseFloat(this.value-(this.value*$(this).parent().parent().find("input.descuento").val()));
			}
			else
			{
				if (this.checked)
					total1+=parseFloat(this.value);
				else
					total1-=parseFloat(this.value);
			}
		}
		if ($(this).is('.precio2'))
		{
			if (this.checked)
				total2+=parseFloat(this.value);
			else
				total2-=parseFloat(this.value);
		}
		if ($(this).is('.descuento'))
		{
			if ($("input.precio1").is(':checked'))
			{
				if (this.checked)
					total1-=parseFloat(total1*this.value);
				else
				{
					tot=0;
					$("input:checked.precio1").each(function(){
						tot+=parseFloat($(this).val());
					});
					total1=tot;
				}
			}
		}
		
		total=total1+total2;
		
		/*$(this).parent().parent().parent().parent().find(".formtotal").find(".total .totinput1").val(total1);
		$(this).parent().parent().parent().parent().find(".formtotal").find(".total .totinput2").val(total2);*/
		
		$(this).parent().parent().parent().parent().find(".formtotal").find(".total .totinput").val(total);
	});
	
	$(".botcancel input").click(function(){
		total=0;
		total1=0;
		total2=0;
		$("input:checked").attr('checked', false);
		$(this).parent().parent().find(".total .totinput").val(0);
	});
});

