$(document).ready(function(){
	
	// Iluminado de filas
	$("table.listado_anuncios tr").mouseover(function(){
		if($(this).attr("rel") == undefined){
			var color = $(this).css("background-color");
			$(this).attr("rel", color);
			$(this).css("background", "#FFF7C1");
		}
	});
	$("table.listado_anuncios tr").mouseout(function(){
		if($(this).attr("rel") != 'undefined'){
			var color = $(this).attr("rel");
			$(this).css("background", color);
			$(this).removeAttr("rel");
		}
	});
	
	// Gestión estrellas anuncio favorito
	$(".favorito img").mouseover(function(){
		if($(this).attr("rel") != "1")
			$(this).attr("src", "/images/misc.elemento_favorito_hover.gif");
		else
			$(this).attr("src", "/images/misc.elemento_favorito_activo_hover.gif");
	});
	$(".favorito img").mouseout(function(){
		if($(this).attr("rel") != "1")
			$(this).attr("src", "/images/misc.elemento_favorito.gif");
		else
			$(this).attr("src", "/images/misc.elemento_favorito_activo.gif");
	});
	$(".favorito img").click(function(){
		que = $("div.mes_calendario").length > 0 ? "evento" : "anuncio";
		
		if($(this).attr("rel") != "1") {
			$(this).attr("rel", "1");
			$(this).attr("title", "Haz clic para desmarcar el favorito");
			$(this).attr("src", "/images/misc.elemento_favorito_activo_hover.gif");
			$.post("/marcar/favorito", {que: que, id: $(this).parent().parent().attr("id"), accion: 1},
				function(data){
					$("div#caja_favoritos_"+que+" h3").text(data);
					$("div#caja_favoritos_"+que+":hidden").show("normal");
					$("div#caja_favoritos_"+que+" h3").animate({color: "#FFD700"}, 200).animate({color: "#000"}, 200);
				});
		} else {
			$(this).attr("rel", "0");
			$(this).attr("title", "Haz clic para marcar como favorito");
			$(this).attr("src", "/images/misc.elemento_favorito_hover.gif");
			$.post("/marcar/favorito", {que: que, id: $(this).parent().parent().attr("id"), accion: 0},
				function(data){
					if( data == 0 )
						$("div#caja_favoritos_"+que).hide("normal");
					else
					{
						$("div#caja_favoritos_"+que+" h3").text(data);
						$("div#caja_favoritos_"+que+" h3").animate({color: "#FFD700"}, 200).animate({color: "#000"}, 200);
					}
			});
		}
	});
});