$(document).ready(function() {
	$('form input:radio').css('border', 'none');						   
						   
						   
	$('#slider4').nivoSlider({
		effect:'boxRainGrow,boxRainGrowReverse',
		pauseTime:5000,
		pauseOnHover:false,
		boxCols: 12,
		boxRows: 6
	});
	$(".fancy").fancybox({ 'width': '800' });
	$("a .masinfo").fancybox({ 'width': '200', 'height': '200' });
	$("a[rel=fancy]").fancybox();
	
//Para la subscripcion al newsletter	
	var objetivo = $("#suscripcionnewsletter");
	objetivo.validate({
		errorElement: "em",
		errorPlacement: function(error, element) {
			error.appendTo(element.parent("p"));
		},
		rules: {
			emailLista: { required: true, email: true}
		},
		messages: {
			emailLista: {required: "Requerido.", email: "No parece v&aacute;lido"}
		},
		submitHandler: function(form){
			$('.bloque_envio').load('listaCorreoValidar.php?redireccionar=no&accion=alta&email='+$('#suscripcionnewsletter #emailLista').val(),function(){}).slideDown('slow').delay(12000).slideUp('slow');
         	return false;
      	}
	});

//Actualización del carrito
	$('form #cantidad').keyup(function(){
		if( $(this).val() != "" ){
			$(this).val( $(this).val().replace(/[^0-9]/g, "") );
			$('#recuento_cesta').load(
				'ajax_recuento_cesta.php?ref='+$(this).parents('form').find('#l').val()+'&cantidad='+$(this).parents('form').find('#cantidad').val(),
				function(msg){
					var datos = msg.split("::");
					//ponemos la base, transporte e iva
					$("#tt_base span:first").html( datos[0] + '&euro;' );
					$("#tt_iva span:first").html( datos[3] + '&euro;' );
					$("#tt_trans span:first").html( datos[2] + '&euro;' );
					
					//Ahora vemos el gasto seleccionado
					var gastos = 0;
					if( $('#formas_pago input:checked').val() == 'Tpv' ) gastos = datos[4];
					else if( $('#formas_pago input:checked').val() == 'Contrareembolso' ) gastos = datos[5];
					else if( $('#formas_pago input:checked').val() == 'Paypal' ) gastos = datos[6];
					
					gastos = Number(gastos).toFixed(2);
					
					
					$("#tt_gastos span:first").html( gastos + '&euro;' );
					
					//Ahora el total
					
					
					var total = Number(datos[0]) + Number(datos[2]) + Number(datos[3]) + Number(gastos);
					$(".cesta_total span:first").html( 'Total: <b>' + total.toFixed(2) + '&euro;' );
					
        		}
			);
		}
	});

});
