var prefixDevil = "";
if(location.href.indexOf("/live/dl/") != -1) {
	prefixDevil = "/live";
}

if(typeof(DEBUGRAITV)=='undefined'){
	DEBUGRAITV=false;
};

$(function()
{
	$("UL.elencoTematiche LI>A").click(function() {
		$("UL.elencoTematiche LI").attr("id","");
		var setUrl = $(this).attr("id");
		if(__TAB == "W") {
			//alert(staticUrl.replace(/#action#/,setUrl));
			url = staticUrl.replace(/#action#/,setUrl);			
			$(this).parent().attr("id","selected");			
			//setNielsen(prefixDevil+"/dl/RaiTV/programmi/liste/"+urlSet+"-"+__TAB__URL+"-0.html");
		} else {
			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 = prefixDevil+"/dl/RaiTV/programmi/liste/"+setUrl+".html";
			if(pageVisited == "page") {
				url = prefixDevil+"/dl/RaiTV/programmi/liste/"+setUrl+"-"+__TAB+"-0.html";
			}
		}

		$.ajax({
		  url: url,
		  cache: false,
		  success: function(html){
			if (html.indexOf('<title>')<0) {
				$("#mediaList").html(html);
				setView();
				$("#mediaList").fadeIn("slow", function () {
					setReflection(".reflect");
					pagination();
					rewriteHREF();
					applyPngFix();
				});
				setNielsen(url);
			} else {
				$.ajax({
				  url: PATH_NO_CONTENT,
				  cache: false,
				  success: function(html){
					$("#mediaList").html(html);
					setView();
					$("#mediaList").fadeIn("slow", function () {
						setReflection(".reflect");
					});
					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;
	});
});