if(typeof(DEBUGRAITV)=='undefined'){
	DEBUGRAITV=false;
};

$(function()
{
	$("UL.elencoTematiche LI>A").click(function() {
		$("UL.elencoTematiche LI").attr("id","");
		var setUrl = $(this).attr("id");
		if (DEBUGRAITV) {alert("cont 0");}
		if($(this).next(".sottoTematica").length!=0) {
			if (DEBUGRAITV) {alert("cont 1");}
			$("UL.sottoTematica").hide();
			$(this).next().show();
			if($(this).parent().attr("class") == "") {
				if (DEBUGRAITV) {alert("cont 1.1");}
				$(this).parent().attr("id","unselectedDown");
				$(this).next().children("LI:visible:first").attr("id","selected");
				setUrl = $(this).next().children("LI:visible:first").children().attr("id").toString();
			} else {
				if (DEBUGRAITV) {alert("cont 1.2");}
				$(this).parent().attr("id","selected");
				$(this).parents(".sottoTematica").parent().attr("id","unselectedDown");
			}
		} else {
			if (DEBUGRAITV) {alert("cont 2");}
			if($(this).parents(".sottoTematica").length == 0) {
				if (DEBUGRAITV) {alert("cont 3");}
				$("UL.sottoTematica").hide();
				$(this).parent().attr("id","selected");
			} else {
				if (DEBUGRAITV) {alert("cont 4");}
				$(this).parents(".sottoTematica").parent().attr("id","unselectedDown");
				$(this).parent().attr("id","selected");
			}
		}
		var url = "/dl/RaiTV/programmi/liste/"+setUrl+".html";
		if(pageVisited == "page") {
			url = "/dl/RaiTV/programmi/liste/"+setUrl+"-"+__TAB+"-0.html";
		}		

		$.ajax({
		  url: url,
		  cache: false,
		  success: function(html){
			$("#mediaList").html(html);
			setView();
			$("#mediaList").fadeIn("slow", function () {
				setReflection(".reflect");
				pagination();
				applyPngFix();
				login();				
			});
			setNielsen(url);
		  },
		  error: function(html){
			$.ajax({
			  url: PATH_NO_CONTENT,
			  cache: false,
			  success: function(html){
				$("#mediaList").html(html);
				setView();
				$("#mediaList").fadeIn("slow", function () {
					setReflection(".reflect");
				});
				setNielsen(url);
			  }
			});
		  } 
		});
	  return false;
	});
});
