$(function() {
	// Quitar link de primer nivel del widget de paginas en #sidebar-a
	$(".widget_pages ul li a").not(".widget_pages .children a").attr("href", "");
	$(".widget_pages ul li a").not(".widget_pages .children a").css("cursor", "default"); // Quitamos el cursor de link
	$(".widget_pages ul li a").not(".widget_pages .children a").click(function(evento) {
		evento.preventDefault();
	});

	// Coloreado de links de primer nivel
	var color_index = 0;
	var color_array = ['#1da2d5', '#deb72c', '#98955a', '#588e9b', '#ea7d23', '#27953c'];
	$(".widget_pages ul li a").not(".widget_pages .children a").each(function() {
		$(this).css('background-color', color_array[color_index]);
		color_index = color_index + 1;
	});
	

	// Hacer que los links de segundo nivel con ul dentro se desplieguen
	var template_url = $("#template_url").attr("href").replace("style.css", ""); // Tomamos solo la ruta hacia el template (eliminamos el style.css)
	var dir_imagen_arriba = "url(" + template_url + "img/arriba.gif)";
	var dir_imagen_abajo = "url(" + template_url + "img/abajo.gif)";

	$(".widget_pages .children > li a").each(function() { // Coloca la imagen de la flecha hacia arriba y abajo
		if ($(this).parent().find("ul").length > 0) {
			var css_background_flecha = {"background-image": dir_imagen_abajo, "background-repeat": "no-repeat", "background-position" : "right center"};
			$(this).css(css_background_flecha);
		}
	})

	$(".widget_pages .children li > ul").hide();
	$(".widget_pages .children > li a").click(function(evento) {
		if ($(this).parent().find("ul").length > 0) { // Si el contenedor de este link tambien contiene una ul
			evento.preventDefault();
			$(this).next("ul").toggle("fast");
			// Flechas arriba y abajo en itemes desplegables en #sidebar-a
			if ($(this).css("background-image") == dir_imagen_abajo)
				$(this).css("background-image", dir_imagen_arriba);
			else
				$(this).css("background-image", dir_imagen_abajo);
		}
	});

	// Corregir bugs de IE
	if ($.browser.msie && $.browser.version <= 6) {
		// El #sub-header quedaba 10px abajo del #header
		$("#sub-header").css("margin-top", "-10px");
		// El sidebar tiene margen, misteriosamente
		$(".widget").css({"margin-left":"-40px", "margin-top":"-15px"});
		// Listado de paginas
		$(".widget_pages ul").css("margin", "0px");
		$(".widget_pages ul li").css("margin-bottom", "-20px");
		$(".widget_pages .children").css("margin-bottom", "20px");
		// Listado de categorias
		$(".widget_categories ul").css("margin-left", "0px");
		// Listado de telefonos
		$(".widget_telefonos ul").css("margin-left", "0px");
		$(".widget_telefonos ul div").css("margin-top", "3px");
		// Los menues de #sidebar-b tienen margin-bottom
		$("#sidebar-b ul li").css({"line-height": "16px"});
	}
	

	// Coloreado de filas en tablas
	$(".Grillado tr:even").css("background-color", "#eee");
	$(".GrilladoColumna td:even").css("background-color", "#eee");
	$("#SidebarA .widget_pages h2").hide();

	// Imprime todo lo que este dentro de #TramiteImprimir
	$("#Imprimir").click(function(evento)
	{
		evento.preventDefault();
		var css = "h1 {font-family: arial; font-size: 18px;} h2 {font-family: arial; font-size: 16px;}";
		css += 'p, ul, table {font-size: 12px; font-family: arial;} td {padding-right: 20px;}';
		css += 'table {border-collapse: collapse;} td {border-bottom: 1px solid #CCCCCC;} th {border-bottom: 1px solid #AAAAAA;}';
		var html = '<html><head><style>' + css + '</style></head><body>';
		html += '<img src="wp-content/uploads/2009/12/membrete.png" alt="" />';
		html += "<h1>" + $("#ContenidoPrincipal h1:first").text() + "</h1>" + $("#TramiteImprimir").html();
		html += "</body></html>"
		var ventimp = window.open(' ', 'popimpr');
		ventimp.document.write(html);
		ventimp.document.close();
		ventimp.print();
		ventimp.close();
	});

	// Cuerpo del Honorable Concejo Municipal
	$(".Banca").click(function(evento) {
		evento.preventDefault();
		var id_banca = $(this).attr("href");
		var html = $(id_banca).html();
		$.prompt(html);
	});
});
