jQuery(function($) {
	var base = "http://www.kubenidorm.es";
	$(".dialog").click(function() {
		$("#dialog").remove()
		$("body").append("<div id=\"dialog\"></div>");
		var id_evento = $(this).attr("id").split("_");
		$.get(base+"/dialog.php?", { tipo: "evento", id: id_evento[1] }, function(datos) {
			$("#dialog").empty();
			$("#dialog").append(datos);
			var titulo = $("#titulod").text();
			var anchura = parseInt($("#anchura").text());
			var altura = parseInt($("#altura").text());
			var masanchura = 100;
			var masaltura = 150;
			anchura = anchura<340-masanchura ? 340 : anchura+masanchura;
			altura = altura<300-masaltura ? 300 : altura+masaltura;
			$(".remover").remove();
			$("#dialog").dialog({ modal: true,  title: titulo, overlay: { opacity: 0.5, background: "black" }, height: altura, width: anchura });
		});
		return false;
	});
	$("a").click(function() {
		if (this.href.indexOf(location.hostname) == -1 || $(this).attr("rel")=="external") {
			abreVentana(this.href);
			return false;
		}
    });
	
});

function abreVentana(direccion) {
	if (!(window.open(direccion))) {
		alert("No se ha podido abrir la nueva ventana. Por favor, habilite la apertura de ventanas emergentes en su navegador e inténtelo nuevamente.");
	}
	return false;
}

