$(document).ready(function(){

	$('a.agregarCesta img').fadeTo("fast", 0.33);

	//Muestra el precio de la propiedad al pasar sobre ella
	/*
	$('.propiedad').hover(
		function(e)
		{
			var html =	'<div id="info" class="th12 rojo">';
			html +=		'€ '+ $(this).attr('id') + '.-';
			html +=		'</div>';
							
			$('body').append(html).children('#info').hide().fadeIn(400);
			$('#info').css('position','absolute').css('top', e.pageY + 10).css('left', e.pageX - 40);
		},
		function()
		{
			$('#info').remove();
			
		}
	);
	
	$('.propiedad').mousemove(function(e) {
		$('#info').css('position','absolute').css('top', e.pageY + 10).css('left', e.pageX - 40);
	});	
	*/
	
	
	
	//Selecciona el campo en el que nos encontramos
	var propiedadCantidad = $('.propiedadCantidad').parents('.propiedades').find('input');
	
	if(propiedadCantidad.length >0){
		propiedadCantidad.keyup(function(e){
			var total = 0;
			
			//Permite solo números positivos
			if( e.which!=8 && e.which!=9 && e.which!=16 && e.which!=0 && (e.which<48 || e.which>57) && (e.which<96 || e.which>105))
			{
				$(this).val('');
				return false
			}			 
			
			//Calcula el total de unidades por producto
			$(this).parents('.propiedades').find('input').each(function()
			{ 
			total = total + $(this).val();
			})
			
			//Actualiza el boton "Añadir a la cesta"
			//botonAgregar = $('a.agregarCesta img');
			botonAgregar = $(this).parents('.lineaProductos').find('a.agregarCesta img');
			if(total > 0){
				botonAgregar.fadeTo("normal", 1);
			}else{
				botonAgregar.fadeTo("normal", 0.33); 
			}
		
		
		});
	}else{
		botonAgregar = $('a.agregarCesta img');
		botonAgregar.fadeTo("normal", 1);
	}

	
});