$(document).ready(function() {
	$("#barmenu1 li a").click(function() {					
		var x = $(this).attr("href");	
		
		$.post("includes/bar.php",{id:x},function(datos){			  
			eval("datos = "+datos);
			
			$("#descripcion").html('<h4>'+datos.nombre+'</h4><p id="info_trago">'+datos.descripcion+'</p>');										  			$("#top_t").html("Tragos con "+datos.nombre);
			$("#marco2 .receta").hide('fast', function(){
				$("#marco3").hide('fast');
				$("#mensaje").hide('fast');
				$("#marco2").slideDown('slow', function(){
					$("#tragos_lista").show('fast');
					$("#tragos_lista").load("includes/tragos.php", {li:x}, eventoClic);
				});												   
			});				
		});	
		
		
		return false;
	});
	function eventoClic(){
		$("#tragos_lista li").click(function(){	
											 
			$("#marco3 img").fadeOut('fast');
			var x = $(this).children('a').attr("href");			
			$("#marco3").show('fast', function(){			
				
				$.post('includes/detalles.php', {id:x}, function(datos){					
										
					eval('datos='+datos);					
					$("#marco2 .receta").show('fast', function(){												   
						
						$("#marco2 .trago_titulo b").text(datos.nombre);
						$("#lista_ingredientes").html(datos.ingredientes);
						$("#preparacion").text(datos.preparacion);
					});
					
					
					$("#marco3").html('<img src="imagenes/bar_tragos/'+datos.imagen+'" alt="'+datos.nombre+'" width="193" height="273" />');
					$("#marco3 img").fadeIn('slow');
					
				});				
			});
			return false;
		});		
	}
	$("#right p").click(function(){
		if (tk_cfg.usuario == undefined) {
			if ($('#login').length == 0) {
				$.get('bits/login.php', function(data) {
					$('#wrap').append(data);
					
					
					$('#login').prepend('<span class="closeDialog"><a href="home.php">Cerrar</a></span>');
					
					animateLogin();
				});
			} else {
				animateLogin();
			}
		} else {
			$("#mensaje").hide('fast');
			$("#marco4").toggle('fast');
		}
		return false;
	});
	$("#agregar_ingrediente p a").click(function(){							   
		var ingrediente = $("#ingrediente").attr('value');
		var medida = $("#medida2").attr('value');
		if(ingrediente.length & medida.length){			
			var texto = $("#texto_ingrediente").attr('value');
			if(texto.length){
				var coma = ", ";	
			}else{
				var coma = "";	
			}
			$("#texto_ingrediente").attr("disabled","");
			$("#texto_ingrediente").val(texto+coma+medida+" "+ingrediente);
			$("#texto_ingrediente").attr("disabled","disabled");
		}
		return false;
	});	
	$("#form_trago").bind("submit", function(){
		
		var datosEnviados = 'nombre='+$("#nombre").attr('value')
							+'&ron='+$("#tipo_ron").attr('value')
							+'&medida_ron='+$("#medida1").attr('value')
							+'&ingredientes='+$("#texto_ingrediente").attr('value')
							+'&preparacion='+$("#trago_preparacion").val();
									
		$.ajax({
		   type: "POST",
		   url: "includes/cargar_trago.php",
		   data: datosEnviados,
		   success: function(){	
		   	$("#marco4").hide('slow',function(){
				$("#mensaje").show('show');									  
			});						  		   
		   }
		});	
		return false;
	});
});

