var isIEBrowser ;
var bExecuteHomePage = "true";
var bRelated = false ;
//var sSearchChannel ;
var Utils = {

    findPos: function(obj) {
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
		    curleft = obj.offsetLeft;
		    curtop = obj.offsetTop;
		    while (obj = obj.offsetParent) {
			    curleft += obj.offsetLeft;
			    curtop += obj.offsetTop;
		    }
	    }
	    return [curleft,curtop];
    },

    getOffX : function(o) {
      var curleft = 0;
      if (o.offsetParent)	{
        while (o.offsetParent) {
          curleft += o.offsetLeft;
          o = o.offsetParent;
        }
      } else if (o.x) {
        curleft += o.x;
      }
      return curleft;
    },

    getOffY : function(o) {
      var curtop = 0;
      if (o.offsetParent) {
        while (o.offsetParent) {
          curtop += o.offsetTop;
          o = o.offsetParent;
        }
      } else if (o.y) {
        curtop += o.y;
      }
      return curtop;
    }
};
function selectAll(objDom)
{
	var textVal=document.getElementById($(objDom).attr("id")) ;
	
	textVal.focus();
	textVal.select();
}
$(document).ready(function(){
	$("#hideimagefacebook").hide();
	$("#hiddenForFacebook").hide() ;
	//$.history.init(WebTV.LoadSezione);
	//$.history.init(WebTV.LoadChannelSezione);
	//$.history.load('#some_anchor');
	
	isIEBrowser = $.browser.msie ;
    if(bExecuteHomePage == "true")WebTV.LoadHomePage();
    WebTV.HidePanels();
   
    
	/*******modifica 01042008****/
    $("#pagebodybig").hide();
    /***********/
	$(".btnApprofondimenti").click(function() {
	    /*hide selectboxes on right panel*/
	    
	    $('#rightDynamicContent select').hide(); 
		/*Open the panel*/ 
	    if(!$("#pnlApprofondimenti")[0].opened)
	    {
            $("#pnlApprofondimenti .innerWrapper").html('');
		    $("#pnlApprofondimenti").animate({width: 'show'}, 'slow',function() {
		        WebTV.LoadApprofondimenti(WebTV.currentContentID);
		        $("#contentFirst .contentFirstInternal .buttons .tools a").addClass("close");
		    });
		    $("#pnlApprofondimenti")[0].opened = true;
	    }
	    else
	    {
		    $("#pnlApprofondimenti")[0].opened = false;
		    $("#pnlApprofondimenti").animate({width: 'hide'}, 'slow',function() {
		        $("#contentFirst .contentFirstInternal .buttons .tools a").removeClass("close");
		    });
	    }
	    
		return false;
	});
	if(bExecuteHomePage == "true") $(".btnApprofondimenti").hide() ;
	
    $('#mainNavigation li a').click(function(){
        $('#mainNavigation li a').removeClass("current");
        $('#header .topMenuContainer ul li a').removeClass("current");
        $('#bottomHeader .buttonsBig a').removeClass("current");
        /**********modifica 01042008*******/
        $('#bottomHeader .rightMenu a').removeClass("current");
        /*****************/
        $('#header .loghi a').removeClass("current");
        $(this).addClass("current");
    });

	/*$('#mainNavigation li a').hover(
		function(){ $(this).addClass("on"); }, 
		function(){ $(this).removeClass("on"); } 
	);*/

    $('#header .topMenuContainer ul li a').click(function(){
       $('#header .topMenuContainer ul li a').removeClass("current");
        $('#mainNavigation li a').removeClass("current");
        $('#bottomHeader .buttonsBig a').removeClass("current");
        /***********modifica 0104*******/
        $('#bottomHeader .rightMenu a').removeClass("current");
        /************/
        $('#header .loghi a').removeClass("current");
        $(this).addClass("current");
    });
	/*
	$('#header .topMenuContainer ul li a').hover(
		function(){ $(this).addClass("on"); }, 
		function(){ $(this).removeClass("on"); } 
	);
	*/
    $('#bottomHeader .buttonsBig a').click(function(){
        $('#header .topMenuContainer ul li a').removeClass("current");
        $('#mainNavigation li a').removeClass("current");
        $('#bottomHeader .buttonsBig a').removeClass("current");
        /***********modifica 0104**********/
         $('#bottomHeader .rightMenu a').removeClass("current");
         /**************/
         $('#header .loghi a').removeClass("current");
        $(this).addClass("current");
    });
    $('#header .loghi a').click(function(){
        $('#header .topMenuContainer ul li a').removeClass("current");
        $('#header .loghi a').removeClass("current");
        $('#mainNavigation li a').removeClass("current");
        $('#bottomHeader .buttonsBig a').removeClass("current");
        /***********modifica 0104**********/
         $('#bottomHeader .rightMenu a').removeClass("current");
         /**************/
        $(this).addClass("current");
    });
	/*
	$('#bottomHeader .buttonsBig a').hover(
		function(){ $(this).addClass("on"); }, 
		function(){ $(this).removeClass("on"); } 
	);   
	*/
	/****************Modifica 0104********/
	 $('#bottomHeader .rightMenu a').click(function(){
        $('#header .topMenuContainer ul li a').removeClass("current");
        $('#mainNavigation li a').removeClass("current");
        $('#bottomHeader .buttonsBig a').removeClass("current");
        $('#bottomHeader .rightMenu a').removeClass("current");
        $('#header .loghi a').removeClass("current");
        $(this).addClass("current");
    });
    /*************/
     
});

/*Tutte le chiamate Ajax usano MakeRequest*/
function MakeRequest(url,objDom,callback) {
	
	if(WebTV.currentSection == "mappa") {
			$("#page").attr("style","height:auto;") ;
			$("#pagebodybig").attr("style","height:auto;") ;
        }
       
	//alert((objDom));
	if(objDom == "#rightDynamicContent .autoriIntervistati .scroll-pane" 
	|| objDom == "#rightDynamicContent .opereMultimediali .opereList" 
	|| objDom == "#rightDynamicContent .contenuto.listaautori .listaNomi" 
	|| objDom == "#rightDynamicContent .contenuto.listaautori .risultati" 
	|| objDom == "#btnrelated"
	|| objDom == "#rightDynamicContent .lettraselezionatacontent")
	{
		url = url ;
	}
	else{
	url = "/site/GetAjaxContent.html?template=RaiUniverso\\" + url ;
	}
	
	if(objDom == "#rightDynamicContent .opereMultimediali .opereList") url = url;
	 $(objDom).css("background-image","url(/images/loadings/loading2.gif)");
	 $(objDom).css("background-repeat","no-repeat");
	 $(objDom).css("background-position","center");
	
	
	
    //var loading = $("#generalLoading").clone();
	$(objDom).html("");
	//$(objDom).append(loading.css("display","block"));
	$.ajax({
	   type: "GET",
	   url: url,
	   dataType: "xml",
	   success: function(Xml) {
	   
			if($(objDom).attr("id") == "mediaplayer")
			{
				$(objDom).css("background-image","none");
				var oPlayer = document.getElementById('mediaplayer') ;
				oPlayer.innerHTML = $("ContentHTML",Xml).text() ;
			}
			else
			{ 
				$(objDom).css("background-image","none");
				$(objDom).html($("ContentHTML",Xml).text());
			}
			
	        //loading.css("display","none");
				if(callback) callback();
		}
	 });
	   
	//  alert	(WebTV.currentSection);

}

function MakeRequest2(url,objDom,callback) {
	var objHeight ;
	
	
    var loading = $("#generalLoading").clone();
	$(objDom).html("");
	$(objDom).append(loading.css("display","block"));
	$.ajax({
	   type: "GET",
	   url: url,
	   dataType: "xml",
	   success: function(Xml) {
            $(objDom).html($("ContentHTML",Xml).text());
	        loading.css("display","none");
	        if(callback) callback();
	        
	         
		}
	   
	   });
	  
}


var WebTV = {

    /*Indica la sezione corrente*/
    sSearchChannel				: null,
    sSearchGenereVideo			: null,
    sSearchPageParam			: null,
    sAuthorSearch				: null,
    sRegistiSearch				: null,
    sTitoloSearch				: null,
    sParolaSearch				: null,
	sAnnoSearch					: null,
    lastBg						: null,
    currentSection				: null,
    sOptDomSelected				: null,
    currentContentID			: 0 ,
    currentSolutionContentID	: 0 ,
    currentChannelID			: 0 ,
    channelFilosofia			: 186,
    channelStoria				: 187,
    channelLetteratura			: 188,
    channelArte					: 189,
    channelPsicologia			: 190,
    channelEconomia				: 191,
    channelPolitica				: 192,
    channelMedicina				: 193,
    channelScienze				: 194,
    channelComunicazione		: 195,
    channelMatematica			: 196,
    channelBiologia				: 197,
    channelFisica				: 198,    
    
    HidePanels : function() {
   
	    $("#pnlApprofondimenti").hide();
	    $("#pnlContenutoApprofondimenti").hide();
	    $("#topPanel").hide();
	    $("#topPanelBig").hide();
	    try
	    {
			$("#pnlApprofondimenti")[0].opened = false;
	    }
	    catch(e){}
	
    },

	GetSeconds : function (asTime) {
		var iHours = parseInt(asTime[0]);
		var iMinutes = parseInt(asTime[1]);
		var iSeconds = parseInt(asTime[2]);
		var iTotSeconds = (3600*iHours) + (60*iMinutes) + iSeconds;
		return iTotSeconds;
	}, 
	
    /*Carica il video del mediaplayer*/
    LoadVideo : function(template) {
		$(".fullScreen").show();
		bRelated = false ;
        if(template!="")
		{  
			var url = template;
			MakeRequest(url + "&videotype=flash",
					$("#mediaplayer"),
					function() {
						var sVideoBeginTime = $('#videoClipBegin').text();
						var sVideoEndTime = $('#videoClipEnd').text();
						var asVideoBeginTime = sVideoBeginTime.split(':');
						var asVideoEndTime = sVideoEndTime.split(':');
						var iVideoBeginTime = WebTV.GetSeconds(asVideoBeginTime);
						var iVideoEndTime = WebTV.GetSeconds(asVideoEndTime);
						iVideoBeginTime = 50.0;
						iVideoEndTime = 70.0;
						//alert("Begin: " + iVideoBeginTime + " End: " + iVideoEndTime);
						// Flowplayer
						flowplayer("player", "/flowplayer/flowplayer.commercial-3.2.2.swf", {
								contextMenu: [
									'Video Player Universo della Conoscenza',

									{ 'Link al Sito': function() {
										location.href = 'http://www.conoscenza.rai.it';
									}}
								],
								key: '#$c2f3e0d63cf9a0455c2',
								clip: {
									//start:iVideoBeginTime,
									//duration:iVideoEndTime-iVideoBeginTime,
									provider: 'rtmp',
									onFinish: function() {
										if(WebTV.currentSection == "questioni")
										{
											$(".titoloQuestione").show();
											$("#caption").html('<P class=captionScelta><A class=scelta onclick="WebTV.LoadRelatedQuestione();return false;" href="#">Sulla base delle tue convinzioni e conoscenze, <u>clicca qui</u> per scegliere fra le opzioni proposte.<br />Scoprirai a quale filosofo o corrente di pensiero si ispira la tua scelta. <img src="/images/btn_caption.jpg" /></A></P>') ;
											$("#caption").show() ;
										}
										else
										{
											if(!bRelated) $(".infoContainer").show() ;
											else $(".infoContainer").hide() ;
											$(".titoloQuestione").hide();
											$("#caption").hide();
										}
									}
								},
								
								play : {
									replayLabel: 'Guarda di nuovo'
								},
								
								plugins: {
									rtmp: {
										url: '/flowplayer/flowplayer.rtmp-3.2.1.swf',
		   								netConnectionUrl: 'rtmp://194.183.7.130/vod'
									},
									
									// change default skin to "tube"
									controls: {
										//url: 'flowplayer.controls-tube-3.2.1.swf'
									}		
								} 
							});
						
					}); 
			}
    },
    setCaption : function(objdom){
	
	$("#btnrelated").html("") ;
	var sTitleCaption = $(objdom).text();
    var sBody = $(objdom).parent().parent().find(".abstract").text();
    var sDurationCaption = $(objdom).parent().parent().find(".durationHidden").val(); 
    
		$(".infoContainer").fadeOut(500,function(){
			$("#btnrelated").append("<br /><p>Durata video: "+ sDurationCaption +"<br /><br /><strong>" + sTitleCaption +"</strong><br />" + sBody + "</p>") ;
			$("#btnrelated").fadeIn(500) ;
		}) ;
		bRelated = true ;
    },
    
    LoadVideoQuestioni : function(guid, contentID, objDom) {
		$(objDom).addClass("selected") ;   
        if(guid!="")
       {  
           var url = "ContentPlayer&WebTVContentID=" + guid + "&WebTVOnDemandChannelID=" + contentID + "&videotype=flash";
           //alert(url) ;
           MakeRequest(url,
                $("#mediaplayer"),
                function() {
                }); 
        }
	
    },
    
    LoadApprofondimenti2 : function () {
		$("#btnApp").css('display','block') ;
		
		//WebTV.LoadApprofondimenti(icontentid) ;
		
	},
	UnloadApprofondimenti : function(){
		$("#btnApp").hide() ;
	},
    
    /*Carica la caption del video corrente*/
    LoadVideoCaption : function(template) {
   
        if(template!="")
       {  
           var url = "/data/video/caption/"+template;
           MakeRequest(url,
                $("#caption"),
                function() {
                }); 
        }
	
    },

	fullScreen : function() {
		var oPlayer = document.getElementById("WinMediaPlayer");
		if ( oPlayer.playState == 3 ) oPlayer.fullScreen = true;
	},
	
    /*Inizializza l'effetto rollover sulle immagini degli autori nell'home page*/
    LoadTooltipAutori : function() {
        /*tooltip immagini*/
	    var tooltipOpened;
	    var objDOmToolTip = document.createElement("div");
	    objDOmToolTip.className = "tooltip_autori";
		
	    $(".autoriIntervistati .autore img").mouseover(function(){
			//alert(isIEBrowser) ;
			$(objDOmToolTip).empty();
		    //var objcont = document.createElement("div");
		    //objcont.className = "image";
		    //var image = this.cloneNode(true);
		    //alert($(this).attr("src")) ;
		    var imgUrl = $(this).attr("src").replace("?Width=40&Height=39","") ;
		    var functionClick = $(this).parent().parent().parent().find("a").attr("onclick") ;
		    //var idElement = $(this).parent().parent().parent().find("a").attr("id") + "_" ;
		    //var objApp = "onclick='" +functionClick + "" ;
		    //alert(functionClick) ;
		    //alert(imgUrl);
		   // alert(objApp) ;
		   // $(image).attr("width","80");
		    //$(objcont).append(image);
		    //$(objcont).append("<div class='image'><img alt='' src=''/></div>");
		    //$(objcont).append("<div class='image'><img alt='' src='"+ imgUrl +"?width=80' width='80'/></div>") ;
		    $(objDOmToolTip).append("<div class='image'><a href='#'><img alt='' src='"+ imgUrl +"?Width=80&Height=78' width='80'/></div></a>");
		    if(isIEBrowser){
				$(objDOmToolTip).find("a").click(function(){
					$(objDOmToolTip).find("a").attr("onclick",functionClick);	
				}) ;
		    }
		    else{
				$(objDOmToolTip).find("a").attr("onclick",functionClick);
		    }
		  
		    
		    
		    $(objDOmToolTip).append($("span",this.parentNode.parentNode.parentNode).clone());
		    
		    $(this).parent().parent().parent().append(objDOmToolTip);
		    $(objDOmToolTip).css("position","absolute");
		    var x = Utils.getOffX(this.parentNode)-Utils.getOffX(this.parentNode.parentNode.parentNode.parentNode)-50;
    		var y = Utils.getOffY(this.parentNode)-Utils.getOffY(this.parentNode.parentNode.parentNode.parentNode)-20;
    		//alert("x position:" + x + ", y position:" + y) ;
    		
    		if( x < 0)
    		{
    			x = 7 ;
    		}
    		if( y < 0)
    		{
    			y = 0 ;
    		}
    		
    		/*if(x == -11 || x == -31 || x == -22)
    		{
    			x = 0;
    		}
    		if(y == -20 || y == -10)
    		{
    			y = 0;
    		}*/
    		
		    $(objDOmToolTip).css("left",x);
		    $(objDOmToolTip).css("top",y);
    		//alert("x position:" + x + ", y position:" + y) ;
		    if(!tooltipOpened)
		    {
			    tooltipOpened = true;
			    $(objDOmToolTip).fadeIn(300,function() {
				    tooltipOpened = false;
			    });
		    }
		    else{
				 tooltipOpened = false;
				$(objDOmToolTip).fadeOut(300,function() {
				   
					$(".tooltip_autori").remove();	    
			    });
		    }
	    });
	   
	   /* $(objDOmToolTip).mouseout(function(){
		    $(objDOmToolTip).remove();
		});*/
    	
    },
    
    /*Carica il pannelllo approfondimenti
    Il contenuto può essere cambiato in base al video che sta andando in onda ma al momento 
    carica sempre lo stesso contenuto*/
    LoadApprofondimenti : function(contentid) {
       MakeRequest("Correlati&WebTVContentid=" +contentid,
            $("#pnlApprofondimenti .innerWrapper"),
            function() {
	            $('#pnlApprofondimenti .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8, scrollbarMargin:10}); 
	            $("#pnlApprofondimenti .btn_closePnlApprof").click(function() {
		            $("#pnlApprofondimenti").animate({width: 'toggle'}, 'slow',function(){
        		        $("#contentFirst .contentFirstInternal .buttons .tools a").removeClass("close");
		            });
		            $("#pnlApprofondimenti")[0].opened = false;
            	    $('#rightDynamicContent select').show(); 
		            return false;
	            });
	            $("#pnlApprofondimenti dl.menu dt a").click(function() {
					
		            $($(this).parent().next()[0]).animate({height: 'toggle'}, 'medium');
		            $(this.parentNode).toggleClass('closed');
		            return false;
	            });
            }); 
    },
    
    /*Carica l'approfondimento selezionato in un pannello a destra che copre il contenuto sottostante*/
    /*LoadContenutoApprofondimenti : function(template) {
        if(template!="")
       {  
           var url = "/data/toppanel/"+template;
          
           $("#pnlContenutoApprofondimenti").fadeIn(300,null); 
           $("#pnlApprofondimenti").animate({width: 'hide'}, 'slow');
            $("#pnlApprofondimenti")[0].opened = false;
            $('#rightDynamicContent select').hide(); 
           MakeRequest2(url,
                $("#pnlContenutoApprofondimenti"),
                function() {
	                $('#pnlContenutoApprofondimenti .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8, scrollbarMargin:10}); 
	                $("#pnlContenutoApprofondimenti .btnClose").click(function() {
		                $("#pnlContenutoApprofondimenti .testointervista").fadeOut(300,null);
		                return false;
	                });
                }); 
        }
    },*/
   
    /*Carica Il pannello in alto sulla destra, di solito è il sommario*/
    LoadContenutoTopPanel : function(template,contentGuid,duration) {
        
        var image ;
        if( WebTV.currentSection == "Maestri del Novecento" || WebTV.currentSection == "Protagonisti della cultura" || WebTV.currentSection == "questioni" ) image = "general";
        else image = WebTV.currentSection ; 
        if(contentGuid!= "")
		{  
			//alert(WebTV.currentSection) ;
			var url = template +"&WebTVContentID=" + contentGuid;
           $('#rightDynamicContent select').hide(); 
           $("#topPanel").animate({height: 'toggle'}, 'slow');
           $("#topPanel")[0].className="";
		
           MakeRequest(url,
                $("#topPanel"),
                function() {
                    $("#topPanel").addClass(WebTV.currentSection);
                    if($(".durata span").text() != "")$(".getDuration").text($(".durata span").text()) ;
					else $(".getDuration").text(duration) ;
					
					if(image == "general") $(".schedaDesc .title").addClass("general") ;
                    $("#topPanel .btnClose").html("<img src='/images/btn_close_scheda_"+ image +".gif' alt='close' />") ;
                    
	                $("#topPanel .btnClose").click(function() {
		                $("#topPanel").animate({height: 'toggle'}, 'slow');
                        $('#rightDynamicContent select').show();
                        
		                return false;
	                });
                }); 
        }
    },
    
    LoadContenutoTopPanelBig : function(idContent) {
        if( idContent != "" )
       {  
			WebTV.currentSolutionContentID = idContent;
			$("#pnlApprofondimenti").animate({width: 'hide'}, 'slow');
            $("#pnlApprofondimenti")[0].opened = false;
            
            $('#rightDynamicContent select').hide(); 
           
           $("#topPanelBig").animate({height: 'toggle'}, 'slow', function(){
           });
           $("#topPanelBig")[0].className="";
           //var url = "/data/toppanel/"+template;
           var url = "RelatedSoluzioni&WebTvContentID=" + WebTV.currentContentID + "&ContentID=" + idContent ;
           MakeRequest(url,
                $("#topPanelBig"),
                function() {
                    $('#topPanelBig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    $("#topPanelBig").addClass(WebTV.currentSection);
                   
                    WebTV.LoadRelatedApprofondimenti(idContent);
	                $("#topPanelBig .goToBack").click(function() {
		                $("#topPanelBig").animate({height: 'toggle'}, 'slow');
                        //$('#rightDynamicContent select').show();
                        
                        //$("#pnlApprofondimenti").animate({width: 'show'}, 'slow');
						$("#pnlApprofondimenti")[0].opened = true;
		                
		                return false;
	                });
                }); 
        }
    },
    LoadPanelApp : function(url, type) {
    /*alert(WebTV.currentSection) ;
		var filter ;
		switch (WebTV.currentSection)
		{
			case "Maestri del pensiero":
				filter = "general" ;
				break;
			case "Protagonisti della cultura":
				filter = "general" ;
				break;
			case "Protagonisti della cultura":
				filter = "general" ;
				break;
		}*/
       if( url != "" )
       {  
			//WebTV.currentSolutionContentID = idContent;
			$("#pnlApprofondimenti").animate({width: 'hide'}, 'slow');
            $("#pnlApprofondimenti")[0].opened = false;
            
            $('#rightDynamicContent select').hide(); 
           
           $("#topPanelBig").animate({height: 'toggle'}, 'slow', function(){
           });
           $("#topPanelBig")[0].className="";
           //var url = "/data/toppanel/"+template;
           //var url = "RelatedSoluzioni&WebTvContentID=" + WebTV.currentContentID + "&ContentID=" + idContent ;
           MakeRequest(url,
                $("#topPanelBig"),
                function() {
                    $('#topPanelBig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    $("#topPanelBig").addClass(WebTV.currentSection);
                   if(WebTV.currentSection == "Maestri del Novecento" || WebTV.currentSection == "Protagonisti della cultura") $("h3.title").addClass("general");
                   // WebTV.LoadRelatedApprofondimenti(idContent);
                    $("#topPanelBig .btnClose").html("<img src='/images/btn_close_scheda_"+ WebTV.currentSection +".gif' alt='close' />") ;
	                $("#topPanelBig .btnClose").click(function() {
		                $("#pnlApprofondimenti").animate({width: 'toggle'}, 'slow');
		                 $("#topPanelBig").animate({height: 'toggle'}, 'slow');
                        //$('#rightDynamicContent select').show();
                        
                        $("#pnlApprofondimenti").animate({width: 'show'}, 'slow');
						$("#pnlApprofondimenti")[0].opened = true;
		                
		                return false;
	                });
                }); 
        }
    },
    LoadTestoOriginale : function(contentid,relatedid,texttype) {
    /*alert(WebTV.currentSection) ;
		var filter ;
		switch (WebTV.currentSection)
		{
			case "Maestri del pensiero":
				filter = "general" ;
				break;
			case "Protagonisti della cultura":
				filter = "general" ;
				break;
			case "Protagonisti della cultura":
				filter = "general" ;
				break;
		}*/
       	//WebTV.currentSolutionContentID = idContent;
			$("#pnlApprofondimenti").animate({width: 'hide'}, 'slow');
            $("#pnlApprofondimenti")[0].opened = false;
            
            $('#rightDynamicContent select').hide(); 
           $("#topPanelBig").animate({height: 'toggle'}, 'slow');
           $("#topPanelBig").animate({height: 'toggle'}, 'slow', function(){
           });
           $("#topPanelBig")[0].className="";
        
           MakeRequest("Relatedintervista&WebTVContentid="+ contentid +"&RelatedID="+ relatedid + "&text="+ texttype,
                $("#topPanelBig"),
                function() {
                    $('#topPanelBig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    $("#topPanelBig").addClass(WebTV.currentSection);
                   if(WebTV.currentSection == "Maestri del Novecento" || WebTV.currentSection == "Protagonisti della cultura") $("h3.title").addClass("general");
                   // WebTV.LoadRelatedApprofondimenti(idContent);
                    $("#topPanelBig .btnClose").html("<img src='/images/btn_close_scheda_"+ WebTV.currentSection +".gif' alt='close' />") ;
	                $("#topPanelBig .btnClose").click(function() {
		                $("#pnlApprofondimenti").animate({width: 'toggle'}, 'slow');
		                 $("#topPanelBig").animate({height: 'toggle'}, 'slow');
                        //$('#rightDynamicContent select').show();
                        
                        $("#pnlApprofondimenti").animate({width: 'show'}, 'slow');
						$("#pnlApprofondimenti")[0].opened = true;
		                
		                return false;
	                });
                }); 
     
    },
    Print : function(contentid,relatedid,texttype) {
    var style = "top=10, left=10, width=503, height=535, status=no, menubar=no, toolbar=no scrollbar=yes" ;
    
    var url= "/site/it-IT/PrintPreview.html?contentid=" + contentid +"&relatedid="+relatedid+"&texttype=" + texttype ;
    
		window.open(url,"",style) ;
    },
    LoadSezione : function(template,nomeSezione,callback) {
		
		WebTV.currentSection = nomeSezione;
        WebTV.HidePanels();
		try 
		{
			$("#pagebody").show();
			$("#pagebodybig").hide();
		}
		catch (e) {}
        if(template!="")
        {  
          //var url = "/data/sezioni/"+template;
          //if(template == "home.xml") var url = "/data/sezioni/"+template;
          //else var url = "ChannelList&WebTVParentChannelID=" + template ;
          var url = template ;
           MakeRequest(url,$("#rightDynamicContent"),
                function() {
					$(".contenuto").addClass(nomeSezione) ;
                    $("#pagebody").removeClass("home");
						
						$("#rightDynamicContent dl.menu").accordion({ 
							header: "dt",
							active: false,     
							alwaysOpen: false, 
							autoheight: false,
							animated: false 

							//callback:function(){alert();}
						});
						
						
                    $("#rightDynamicContent dl.menu dd ul li a").click(function(){
                        $('#rightDynamicContent dl.menu dd ul li a').removeClass('selected');
                        $(this).addClass('selected');
                        WebTV.LoadRightCol();
                    });
	                $('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    if(callback) callback();
                }); 
        }
    },
   
    LoadHomePage : function() {
		
       WebTV.currentSection = "home";
       WebTV.HidePanels();
       //WebTV.LoadSezione("home.xml",
       WebTV.LoadSezione("home",
            'home',
            function() {
	            /*Inizializza tutte le scroll box*/
	            WebTV.LoadTipoAutori("maestri_pensiero") ;
	           // WebTV.LoadTooltipAutori(); //La funzione è stata spostata in LoadTipoAutori
                //WebTV.LoadVideo("video1.xml");
                //WebTV.LoadVideo("ContentPlayer&WebTVSelectedChannelID=183");
                
                $("#pagebody").addClass("home"); 
                WebTV.LoadOpereMultimediali() ;
				WebTV.LoadInPrimoPiano() ; 
				$(".autoriIntervistati .tab ul li:first").css("margin-left","70px");            
				$(".autoriIntervistati .tab ul li:last").css("margin-left","100px");           
            });
            
    },
    
    LoadRightCol : function(channelID, contentID){
		//var url = "/data/operedettagli/1.xml";
		var url = "ContentListVideo&WebTVSelectedChannelID=" + channelID + "&ContentID=" +contentID;

		MakeRequest(url,
			$("#rightDynamicContent .contenuto .rightCol"),
			function() {
				$('#rightDynamicContent .rightCol .tools .btnScheda').click(function(){
					$(this).addClass("selected");
					//WebTV.LoadContenutoTopPanel('sommario.xml');
				});
				$('#rightDynamicContent .rightCol .tools .avvia a').click(function(){
					$(this).addClass("selected");
					//WebTV.LoadContenutoTopPanelBig('testoIntervista.xml');
				});
				
			}); 
    },
    LoadOpereMultimediali: function () {
		var url = "/site/it-IT/OpereMultimediali.html";
		MakeRequest(url,"#rightDynamicContent .opereMultimediali .opereList", function(){
			$('.opereList').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
		}) ;
		
    },
    LoadInPrimoPiano : function (){
		var url = "ContentList&WebTVSelectedChannelID=206";
		MakeRequest(url,"#rightDynamicContent .primoPiano", function(){
			$('#rightDynamicContent .primoPiano .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
		}) ;
	},
    
    LoadTipoAutori : function(authorType) {
		var url = "/site/it-IT/TipoAutori.html?Auth=" + authorType ;
		MakeRequest(url,"#rightDynamicContent .autoriIntervistati .scroll-pane",function(){
			 $('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
			WebTV.LoadTooltipAutori();
		}) ;
    },
    
    LoadChannelSezione : function (channelID, callback) {
		$("#videoList_" + channelID).css("height","23px");
	
		MakeRequest("ContentListSezione&WebTVSelectedChannelID=" + channelID, "#videoList_" + channelID, function(){
			//alert($("#videoList_" + channelID ).html()) ;
				$("#videoList_" + channelID ).show() ;
				/*$('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});*/
				$("#videoList_" + channelID).css("height","");
				$('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
				if(callback) callback();
		});
    },
    setFavorites : function (guid) {
		MakeRequest("LocalPlaylist&WebTVLocalPlaylistAction=add&WebTVContentID=" + guid, "#sto", null);
	},
	
    closeAutori : function() {
    	    $(".scroll-pane .tooltip_autori").remove();
	},
	
	 LoadListaAutori : function(url,nomesezione,callback) {
		
		
		$(".btn_mappa a").removeClass("current") ;
		
		var bground ;
		
		WebTV.currentSection = nomesezione;
		WebTV.HidePanels();
		
		if(nomesezione == "Maestri del Novecento") bground = "bgMaestri" ;
		else if(nomesezione == "Protagonisti della cultura") bground = "bgProtagonisti";
		
		MakeRequest(url,
            $("#rightDynamicContent"),
            function() {
            	$("#pagebody").show();
            	$("#rightDynamicContent .listaautori h3.title").text(nomesezione) ;
            	$("#pagebodybig").hide();
            	
            	if(WebTV.lastBg)$('#rightDynamicContent .risultati').removeClass(WebTV.lastBg) ;
                $('#rightDynamicContent .risultati').addClass(bground) ;
                WebTV.lastBg = bground ;
                    
                  
            	/*Seseziona la prima lettera dell'alfabeto*/
            	$('#rightDynamicContent .listaautori .alfabeto a').click(function(){
                    $('#rightDynamicContent .listaautori .alfabeto a').removeClass("selected");
                    $(this).addClass("selected");
                });
                //WebTV.LoadAutoriNomi("empty");
                //WebTV.LoadAutoriRisultati("nome1");
            }); 
            if(callback) callback();
    },

    LoadAutoriNomi : function(lettera, callback) {
		var authFilter ;
		
		switch (WebTV.currentSection)
		{
			case "Maestri del Novecento":
				authFilter = "&Auth=maestri_pensiero" ;
				break;
			case "Protagonisti della cultura":
				authFilter = "&Auth=protagonisti_cultura" ;
				break;
		}
		//alert(lettera) ;
		//alert(authFilter) ;
		var url = "/site/it-IT/MaestriDelPensiero.html?Letter="+lettera+authFilter;
       MakeRequest(url,
           "#rightDynamicContent .contenuto.listaautori .listaNomi",
            function() {
	            //Inizializza le scroll box
	            $('#rightDynamicContent .contenuto.listaautori .listaNomi .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8,scrollbarMargin:10});
	            $("#"+lettera).addClass("selected");
	            /*Carica le schede relative all'autore scelto */
                /*$('#rightDynamicContent .listaautori .listaNomi a').click(function(){
                
					$('#rightDynamicContent .listaautori .risultati').removeClass("bgMaestri") ;
					$('#rightDynamicContent .listaautori .risultati').removeClass("bgProtagonisti") ;
                    $('#rightDynamicContent .listaautori .listaNomi a').parent().removeClass("selected");
                    $(this).parent().addClass("selected");
                });*/
                //$('#rightDynamicContent .listaautori .listaNomi a:first').click();
                /*************************************************/
                
                //WebTV.LoadAutoriRisultati();
                
            }); 
       if(callback) callback();
    },
   
    LoadAutoriRisultati : function(ContentID) {
       var url = "/site/it-IT/RelatedContentAutori.html?contentid=" + ContentID;
       
       if(ContentID)
       {
       
           MakeRequest(url,"#rightDynamicContent .contenuto.listaautori .risultati",function() {
                    var lastClick; 
                    $('#rightDynamicContent .listaautori .risultati').removeClass("bgMaestri") ;
					$('#rightDynamicContent .listaautori .risultati').removeClass("bgProtagonisti") ;
	                //Inizializza le scroll box
	                $('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8,scrollbarMargin:10});
	                $('#rightDynamicContent .listaautori .rightTools a').click(function(){
	                    if(lastClick)
	                        $("img",lastClick).attr("src","/images/bg_arrow_right.gif");
	                    $("img",this).attr("src","/images/bg_arrow_right_on.gif");
	                    lastClick=this;
	                    $('#rightDynamicContent .listaautori .rightTools a').removeClass("selected");
	                    $(this).addClass("selected");
	                });
                }); 
        } 
        else
        {
            $("#rightDynamicContent .contenuto.listaautori .risultati").html("<h5 style='text-align:center;width:480px'>Seleziona un nome</h5>");
        }
    },

    LoadAreaSito2 : function(template,nomeArea,callback) {
		$("#mediaplayer").html("") ;
		$("#mediaplayer").append("<img src=\"/images/videoHome.jpg\">") ;
        WebTV.currentSection = nomeArea;
        
        if(nomeArea== "credits" || nomeArea== "Guida" || nomeArea== "Mappa") {
			$("#page").attr("style","height:auto;") ;
			$("#pagebodybig").attr("style","height:auto;") ;
        }
        else{
			$("#page").attr("style","") ;
			$("#pagebodybig").attr("style","") ;
         }
        WebTV.HidePanels();
		
        if(template!="")
        {  
           var url = "/data/areesito/"+template;
           MakeRequest2(url,
                $("#pagebodybig"),
                function() {
                    $("#pagebody").removeClass("home");
                    $("#pagebody").hide();
                    $("#pagebodybig").show();
	                $('#pagebodybig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    if(callback) callback();
                    
                }); 
        }
       
    },
     LoadAreaSito : function(template,nomeArea,callback) {
		$("#mediaplayer").html("") ;
		$("#mediaplayer").append("<img src=\"/images/videoHome.jpg\">") ;
        WebTV.currentSection = nomeArea;
        WebTV.HidePanels();
		var lastChecked ;
        if(template!="")
        {  
           var url = template;
           MakeRequest(url,
                $("#pagebodybig"),
                function() {
                    $("#pagebody").removeClass("home");
                    $("#pagebody").hide();
                    $("#pagebodybig").show();
	                $('#pagebodybig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
					/*if(nomeArea == "ricerca")
					{
						$(".centerside input").click(function(val){
							$(".centerside input[checked]").attr("checked",false) ;
							
							if(lastChecked == $(this).attr("id")) 
							{
								$(this).attr("checked",false) ;
								lastChecked = "";
							}
							else 
							{
								$(this).attr("checked",true) ;
								lastChecked = $(this).attr("id") ;
							}
							
							
						});
					}*/  
                    if(callback) callback();
                }); 
        }
    },
    setAllChannel : function(idcontainer,classContainer,idelement){
		//document.getElementById(idelement);
		var checkInput = $("."+ classContainer +" dd :checkbox") ;
		
		if(document.getElementById(idelement).checked){
			$(checkInput).attr("checked",true) ;
			$(checkInput).click(function(){
				$("#"+ idcontainer +" :input").attr("checked",false) ;
			})
		}
		else{
			$(checkInput).attr("checked",false) ;
		}	
	},
    
    setTextArea : function(dom){
    
		WebTV.sOptDomSelected = "";
		
		$("#contDescrizione input").each(function(i){
				if($(this).is(":checked"))
				{
					if($(this).attr("id") == "ckbDescrizione")
						WebTV.sOptDomSelected += "DescrizioneVideo:" ;
					if($(this).attr("id") == "ckbAbstract")
						WebTV.sOptDomSelected += "Abstract:" ;
				}
			}
		) ;
		
		WebTV.sOptDomSelected = WebTV.sOptDomSelected.substring(0,(WebTV.sOptDomSelected.length -1)) ;
		//alert(WebTV.sOptDomSelected) ;
		
		
    },
    
    LoadSearchResult : function() {

		WebTV.currentSection = "ricerca";
		WebTV.HidePanels();
		
		WebTV.sSearchChannel = "" ;
		WebTV.sSearchGenereVideo = "" ;
		var arrayInput = $(".leftside dd :checkbox") ;
		var arrayInputGenere = $(".centerside dd :checkbox") ;
		var exclusionChannel = 0 ;
		var sSearchGenere = "";
		var txtAutore = $("#contAutore :input").val() ;
		var txtTitolo = "" ;
		var txtAutoriVideo = "" ;
		var txtTestoSchedaDescrittiva = "";
		var txtAnnoPorduzione = "";
		var bIncludeChannel = false ;
		
		var sCharSeparator = "" ;
		
		if(!$("#ckbDescrizione").is(":checked") && !$("#ckbAbstract").is(":checked"))
		{
			 WebTV.sOptDomSelected = "DescrizioneVideo:Abstract";
		}
		
		
		if($("#contAutore :input").val() != "")
		{
			txtAutore = "Intervistati:LIKE:" + $("#contAutore :input").val() ;
		}
		
		if($("#contTitolo :input").val() != "")
		{
			if($("#contAutore :input").val() != "") txtTitolo = "|Titolo:LIKE:" + $("#contTitolo :input").val() + ":AND" ;
			else txtTitolo = "Titolo:LIKE:" + $("#contTitolo :input").val() ;
		}
		
		
		if($("#contTesto :input").val() != "")
		{
			
				txtTestoSchedaDescrittiva = WebTV.sOptDomSelected ;
				txtTestoSchedaDescrittiva += "|" + $("#contTesto :input").val()  ;
				
				
		}
		
		 if($("#contData :input").val() != "")
		{
			if($("#contAutore :input").val() != "" || $("#contTitolo :input").val() != "" || $("#contTesto :input").val() != "")
			txtAnnoPorduzione = "|Data:LIKE:" +$("#contData :input").val() + ":AND" ;
			else
			txtAnnoPorduzione = "Data:LIKE:" +$("#contData :input").val() ;
		}
		
		if($("#contAutoriVideo :input").val() != "")
		{
			if($("#contAutore :input").val() != "" || $("#contTitolo :input").val() != "" || $("#contTesto :input").val() != "" || $("#contData :input").val() != "")
			txtAutoriVideo = "|Autori:LIKE:" + $("#contAutoriVideo :input").val() + ":AND" ;
			else
			txtAutoriVideo = "Autori:LIKE:" + $("#contAutoriVideo :input").val() ;
		} 
		
		
		for (i=0; i<arrayInput.length; i++) 
		{
			if(!$(arrayInput[i]).attr("checked")) 
			{	
				exclusionChannel += "|" + $(arrayInput[i]).attr("id");
			}
			else
			{
				bIncludeChannel = true ;
				WebTV.sSearchChannel += "<div>" + $(arrayInput[i]).next().text() + "</div>" ;
			}
		}
		
		/*if(document.getElementById('chkDisciplina').checked)
		{
			WebTV.sSearchChannel ="<div>Tutte le discipline</div>"; 	
		}*/
		
		
		if(!bIncludeChannel)
		{
			exclusionChannel = 0;
			WebTV.sSearchChannel ="<div>Tutte le discipline</div>"; 	
		}
		//if(txtAutore != "" || txtTitolo != "" || txtTestoSchedaDescrittiva!= "") 
		sCharSeparator = "|" ;
		var iCounters = 0 ;
		for (i=0; i<arrayInputGenere.length; i++) 
		{
			if($(arrayInputGenere[i]).attr("checked")) 
			{	
				sSearchGenere += $(arrayInputGenere[i]).next().text() + ":";
				
				WebTV.sSearchGenereVideo += "<div>" + $(arrayInputGenere[i]).next().text() + "</div>" ;
				iCounters ++ ;
			}
			
		}
			sAuthorSearch			= $("#contAutore :input").val() ;
			WebTV.sRegistiSearch	= $("#contAutoriVideo :input").val() ;
			WebTV.sTitoloSearch		= $("#contTitolo :input").val() ;
			WebTV.sParolaSearch		= $("#contTesto :input").val() ;
			WebTV.sAnnoSearch		= $("#contData :input").val() ;
			
			
			sSearchGenere = sSearchGenere.substring(0,(sSearchGenere.length -1)) ;
			
		//sSearchPageParam = "RicercaResult&exclusion=206|242|234|235|236|237|238|239|240|"+exclusionChannel+"&extrainfofilter=" + txtAutore + txtTitolo + txtAnnoPorduzione + txtAutoriVideo + "&Genere=" + sSearchGenere + "&Testo=" + WebTV.sOptDomSelected + txtTestoSchedaDescrittiva;
		sSearchPageParam = "RicercaResult&exclusion=206|242|234|235|236|237|238|239|240|"+exclusionChannel+"&extrainfofilter=" + txtAutore + txtTitolo + txtAnnoPorduzione + txtAutoriVideo + "&Genere=" + sSearchGenere + "&Testo=" + txtTestoSchedaDescrittiva ;
		var url = "RicercaResult&exclusion=206|242|234|235|236|237|238|239|240|"+exclusionChannel+"&extrainfofilter=" + txtAutore + txtTitolo + txtAnnoPorduzione + txtAutoriVideo + "&Genere=" + sSearchGenere + "&Testo=" + txtTestoSchedaDescrittiva ;
        MakeRequest(url,
			$("#pagebodybig"),
				function() {
					$("#pagebody").removeClass("home");
                    $("#pagebody").hide();
                    $("#pagebodybig").show('fast',function(){
						$(".inDisciplina").html(WebTV.sSearchChannel) ;
						$(".inGenere").html(WebTV.sSearchGenereVideo) ;
						$(".inAutore span").html(sAuthorSearch) ;
						$(".inRegisti span").html(WebTV.sRegistiSearch) ;
						$(".inTitolo span").html(WebTV.sTitoloSearch) ;
						$(".inParola span").html(WebTV.sParolaSearch) ;
						$(".inAnno span").html(WebTV.sAnnoSearch) ;
						
                    });
	                $('#pagebodybig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
	        }); 
	        
	    
    },
    
    RicercaResultPage : function (page,newparam) {
		//var sSplitParam = sSearchPageParam.substring(sSearchPageParam.indexOf("=") +1 ,sSearchPageParam.lastIndexOf("&extrainfofilter")) ;
	    //alert(sSearchPageParam.replace(sSplitParam,newparam) ) ;
		MakeRequest(sSearchPageParam + "&page=" + page ,$("#pagebodybig"), 
		
		function() {
					$("#pagebody").removeClass("home");
                    $("#pagebody").hide();
                    $("#pagebodybig").show('fast',function(){
						$(".inDisciplina").html(WebTV.sSearchChannel) ;
						$(".inGenere").html(WebTV.sSearchGenereVideo) ;
						$(".inAutore span").html(sAuthorSearch) ;
						$(".inRegisti span").html(WebTV.sRegistiSearch) ;
						$(".inTitolo span").html(WebTV.sTitoloSearch) ;
						$(".inParola span").html(WebTV.sParolaSearch) ;
						$(".inAnno span").html(WebTV.sAnnoSearch) ;
						
                    });
	                $('#pagebodybig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
	        }); 
		//$("#bodyRicercaRight").show() ;
		//alert(sSearchPageParam +" , "+page) ;
	},
	
    LoadSezioneSearch : function(guid,contentid) {
		//alert(channelid) ;
		/*var url = "/site/it-IT/getParentChannel.html?channelid=" + channelid ;
		//document.location.href = url ;
		var iParentChannelID = 0 ;
		var sParentChannelName = "" ;
		var sSwitchParentChannelName ;
		$.ajax({
			type: "GET",
			url: url,
			dataType: "xml",
			success: function(Xml) {
					//$(objDom).html($("ContentHTML",Xml).text());
					iParentChannelID = $("channel",Xml).attr("id") ; 
					sParentChannelName = $("channel",Xml).text() ;
					
					WebTV.LoadSezione("ChannelList&WebTVParentChannelID=" + iParentChannelID + "",""+ sParentChannelName.toLowerCase() +"",function(){
						WebTV.LoadRightCol(channelid,contentid);
					}) ;
					
					//WebTV.LoadRightCol(channelid,contentid) ;
			}
		});*/
		//WebTV.LoadSezione("ChannelList&WebTVParentChannelID=" + iParentChannelID +",'" + sParentChannelName + "'") ;
		document.location.href = "/site/it-IT/?ContentID="+contentid+"&Guid="+guid ;
		
    },
    
    
    LoadMappa : function(nomeArea,callback) {

        WebTV.currentSection = nomeArea;
        WebTV.HidePanels();

           var url = "mappa&WebTVParentChannelID=184";
           MakeRequest(url,
                $("#pagebodybig"),
                function() {
                    $("#pagebody").removeClass("home");
                    $("#pagebody").hide();
                    $("#pagebodybig").show();
	                $('#pagebodybig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    if(callback) callback();
                }); 
    },
    
    LoadIndiceNomi : function(url,nomeSezione,callback) {
   
        WebTV.currentSection = nomeSezione;
        WebTV.HidePanels();
		
		MakeRequest(url,
            $("#rightDynamicContent"),
            function() {
                $("#pagebody").removeClass("home");
                $("#pagebody").show();
                $("#pagebodybig").hide();
                WebTV.LoadIndiceLettera();
                $('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                if(callback) callback();
            }); 
    },
   
    LoadIndiceLettera : function(btn,lettera) {
		
		var url = "/site/it-IT/IndiceDeiNomi.html?Auth=All&Letter="+lettera;
		
       if(lettera)
       {
           MakeRequest(url,
                "#rightDynamicContent .lettraselezionatacontent",
                function() {
                }); 
	        $('#rightDynamicContent .indicenomi .lettere a').removeClass("selected");
	        $(btn).addClass("selected");
        } 
        else
        {
            //$("#rightDynamicContent .lettraselezionatacontent").html("<h5 style='text-align:center;width:480px'>Seleziona una lettera</h5>");
        }
    },
       LoadResultIndice : function(authType,lastname,contentid){
       
		var sLetter = $(".lettraselezionatacontent h4").text() ;
		//alert($(".lettraselezionatacontent h4").text() ) ;
		if(sLetter == "") sLetter = lastname.substr(0,1).toLowerCase() ;
		if(sLetter == "tutti") sLetter = lastname.substr(0,1).toLowerCase() ;
		//alert(lastname) ;
		var idSelected ;
		var sectionName ;
       
		switch (authType)
		{
			case "maestri_pensiero":
				idSelected = "#maestri" ;
				sectionName = "Maestri del Novecento" ;
				break;
			case "protagonisti_cultura":
				idSelected = "#protagonisti" ;
				sectionName = "Protagonisti della cultura" ;
				break;
		}
		$("#bottomHeader .rightMenu #indice").removeClass("current");
		$("#bottomHeader .rightMenu "+idSelected).addClass("current");
		
		WebTV.LoadListaAutori('ContentLetter',sectionName,function(){
			WebTV.LoadAutoriNomi(sLetter,function(){
				WebTV.LoadAutoriRisultati(contentid);
				if(sLetter != "tutti")
				$("#rightDynamicContent #" + sLetter).addClass("selected") ;
			}) ;
		}) ;
       
    },
    
    LoadLaMiaLista : function(callback) {
		$("#mediaplayer").html("") ;
		$("#mediaplayer").append("<img src=\"/images/videoHome.jpg\">") ;
        WebTV.currentSection = 'la mia lista';
        WebTV.HidePanels();

       //var url = "/data/areesito/lamialista.xml";
       var url = "LocalPlaylist" ;
       MakeRequest(url,
            $("#pagebodybig"),
            function() {
                $("#pagebody").removeClass("home");
                $("#pagebody").hide();
                $("#pagebodybig").show();
                $('#pagebodybig .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                if(callback) callback();
            }); 

    },
    LoadQuestioni : function(url,callback) {

       WebTV.currentSection = "questioni";
       WebTV.HidePanels();
       MakeRequest(url,
            $("#rightDynamicContent"),
            function() {
            	$("#pagebody").show();
            	$("#pagebodybig").hide();
                $('#rightDynamicContent .questioni .box a').click(function(){
                    $('#rightDynamicContent .questioni .box div').removeClass("selected");
                    $(this).parent().addClass("selected");
                });
                if(callback){
                $("#rightDynamicContent #" + WebTV.currentChannelID).addClass("selected") ;
					WebTV.LoadQuestioneRisultati(WebTV.currentChannelID);
                }
            }); 
            
            
    },
    LoadQuestioneRisultati : function(idquestione) {
		WebTV.currentChannelID = idquestione ;
		if(idquestione)
		{
			$('#rightDynamicContent .risultati').removeClass("bgQuestioni") ;
			MakeRequest("ContentListQuestioni&WebTVSelectedChannelID="+idquestione,
				$("#rightDynamicContent .contenuto.questioni .risultati"),
				function() {
					var lastClick; 
	                //Inizializza le scroll box
					$('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8,scrollbarMargin:10});
	                $('#rightDynamicContent .questioni .rightTools a').click(function(){
	                 
						if(lastClick) $("img",lastClick).attr("src","/images/bg_arrow_right.gif");
	                 
						$("img",this).attr("src","/images/bg_arrow_right_on.gif");
						lastClick=this;
						$('#rightDynamicContent .questioni .rightTools a').removeClass("selected");
						$(this).addClass("selected");
					});
			}); 
        }
        else
        {
            $("#rightDynamicContent .contenuto.questioni .risultati").html("<h5 style='text-align:center;width:480px'>Seleziona una questione</h5>");
        }
    },
    
   LoadRelatedQuestione : function() {
		//Viene associata nel bottone avvia video di ContentListQuestioni.ascx
		var iContentID = WebTV.currentContentID ;
		
   		MakeRequest("RelatedQuestioni&WebTVContentID=" + iContentID,
		$("#rightDynamicContent .contenuto.questioni"),
		function() {
			var lastClick; 
					//Inizializza le scroll box
			$('#rightDynamicContent .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 8,scrollbarMargin:10});
	        $('#rightDynamicContent .questioni .rightTools a').click(function(){
	                 
			if(lastClick) $("img",lastClick).attr("src","/images/bg_arrow_right.gif");
	                 
			$("img",this).attr("src","/images/bg_arrow_right_on.gif");
			lastClick=this;
			$('#rightDynamicContent .questioni .rightTools a').removeClass("selected");
			$(this).addClass("selected");
		});
	});
	//WebTV.LoadContenutoTopPanelBig("RelatedQuestioni&WebTVContentID=233") ;		
   },
   LoadRelatedApprofondimenti :function(idrelated){
		var url="RelatedTesti&WebTVContentID="+idrelated ;
		MakeRequest(url, ".boxApp", function(){
			  $('.testi .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
		}) ;
	},
   
    LoadContenutoApprofondimenti : function(idContent) {
    
        if( idContent != "" )
       {  
			$("#pnlApprofondimenti").animate({width: 'hide'}, 'slow');
            $("#pnlApprofondimenti")[0].opened = false;
            
            $('#rightDynamicContent select').hide(); 
           
           $("#topPanelApp").animate({height: 'toggle'}, 'slow', function(){
           });
           $("#topPanelApp")[0].className="";
           //var url = "/data/toppanel/"+template;
           var url = "RelatedApprofondimenti&WebTvContentID=" + WebTV.currentSolutionContentID + "&ContentID=" + idContent ;
           MakeRequest(url,
                $("#topPanelApp"),
                function() {
                    $('#topPanelApp .scroll-pane').jScrollPane({showArrows:true, scrollbarWidth: 7,scrollbarMargin:10});
                    $("#topPanelApp").addClass(WebTV.currentSection);
                    $("#topPanelApp .btnClose").html("<img src='/images/btn_close_scheda_general.gif' alt='close' />") ;
                    
	               $("#topPanelApp .btnClose").click(function() {
		                $("#topPanelApp").animate({height: 'toggle'}, 'slow');
                        $('#rightDynamicContent select').show();
                        
		                return false;
	                });
                }); 
        }
    },
   LoadContenutoSchedaApprofondimeto : function(contentGuid) {
        
        if(contentGuid!= "")
		{  
			//alert(WebTV.currentSection) ;
			//var url = template +"&WebTVContentID=" + contentGuid;
           $('#rightDynamicContent select').hide(); 
           $("#topPanelSoluzione").animate({height: 'toggle'}, 'slow');
           $("#topPanelSoluzione")[0].className="";
         
           MakeRequest("ExtraInfoSoluzione&WebTVContentID=" + contentGuid,
                $("#topPanelSoluzione"),
                function() {
                    $("#topPanelSoluzione").addClass(WebTV.currentSection);
                    //if(image == "general") $(".schedaDesc .title").addClass("general") ;
                    $("#topPanelSoluzione .btnClose").html("<img src='/images/btn_close_scheda_general.gif' alt='close' />") ;
	                $("#topPanelSoluzione .btnClose").click(function() {
		                $("#topPanelSoluzione").animate({height: 'toggle'}, 'slow');
                        $('#rightDynamicContent select').show();
                        
		                return false;
	                });
                }); 
        }
    },
    
	/* sezione per i preferiti */
	
	// serve a richiamare la lista dei preferiti per essere presentata in basso a dx
	makeFavorites : function() {
		MakeRequest('LocalPlaylist', '#contenutoBoxpreferiti', "favoriti") ;
	},
	
	// serve ad aggiungere i preferiti alla propria lista
	setFavorites : function(guid){
		//aggiungo i video ai favoriti
		MakeRequest('LocalPlaylist&WebTVLocalPlaylistAction=add&WebTVContentID=' + guid, '#null',function () {}) ;
	},
	
	// serve a togliere dalla lista dei preferiti in base all'index che si è selezionato
	removeFavorites : function (index) {
		MakeRequest('LocalPlaylist&WebTVLocalPlaylistAction=remove&WebTVLocalPlaylistIndex=' + index, '#null',function () {
			WebTV.LoadLaMiaLista();
		}) ;
	},
	
	// serve a recuperare il conteggio dei preferiti
	countFavorites : function (Xml) {
		try
		{
			var LocalPlayList_node = Xml.getElementsByTagName('PlayList')[0] ;
			if (LocalPlayList_node != null)
			{
				var ContentList_node = LocalPlayList_node.firstChild ;
				var iCountContentList = ContentList_node.getAttribute('count') ;
				if(isNaN(iCountContentList) || Number(iCountContentList)<=0)
				{
					$("#counter").html("0") ;
				}
				else
				{
					$("#counter").html(iCountContentList) ;
				}
			} 
		}
		catch (e) {}	
	},
	/* sezione per i preferiti */
   goBack: function(){
		WebTV.LoadQuestioni('ChannelListQuestioni&WebTVParentChannelID=234',function(){});
		//WebTV.LoadQuestioneRisultati(WebTV.currentChannelID);
		
	},
	/*Mostra il pulsante approfondisci questo video*/
	showBtnRelated: function(contentid){
		$(".infoContainer").fadeOut(500, function(){
			$("#btnrelated").fadeIn(500,function(){
				MakeRequest('/site/it-IT/RelatedContentVideo.html?webtvContentid=' + contentid, '#btnrelated',function () {});	
			}) ;
		}) ;
		bRelated = true ;
	},
	
	/*Manda al canale del video correlato*/
	getRelatedContentVideo : function(parentchannelid, channelid, contentid){
		
		WebTV.LoadApprofondimenti2();
		//alert(parentchannelid + "\n" + channelid + "\n" + contentid + "\n") ;
		WebTV.currentContentID = contentid;
		var channelName ;
		if( $("#btn_" + parentchannelid + " a").attr("title") == "politicaediritto" )
		{
			channelName = "poldir"
		}
		else
		{
			channelName = $("#btn_" + parentchannelid + " a").attr("title") ;
		}
		
		WebTV.LoadSezione('ChannelList&WebTVParentChannelID='+parentchannelid ,channelName, function(){
			WebTV.LoadChannelSezione(channelid,function(){
				WebTV.LoadRightCol(channelid,contentid);
			});
		});	
		
		$(".rightMenu a").removeClass("current");
		$("#mainNavigation a").removeClass("current");
		$("#btnApp").removeClass("close") ;
		$("#btn_" + parentchannelid + " a").addClass("current") ;
		
		$("#btnrelated").fadeOut(500, function(){
			$(".infoContainer").fadeIn(500,function(){
			}) ;
		}) ;
		
	}
}

