function setjCarouselLite() {
	var numberItem = $(".focusLancio ul li").length;
	if(numberItem > 1) {
		$("#LancioPrincipale .focusLancio").jCarouselLite({
			auto:	10000,
			btnNext: "#LancioPrincipale .next",
			btnPrev: "#LancioPrincipale .prev",		
			speed: 1500,
			visible: 1,
			easing: "easeOutBack"
		});
	} else {
		$("#LancioPrincipale .next img").attr("src","/dl/RaiSport/images/btn_lancioprincipale_dx_off.png");
		$("#LancioPrincipale .prev img").attr("src","/dl/RaiSport/images/btn_lancioprincipale_sx_off.png");
		$("#LancioPrincipale .focusLancio").css("visibility","visible");
	}
	
}
function setRollOverNavigator()
{
	var li = $(".sottoSezioneSport li");
	li.click(function() {
		li.removeClass('rollover');
		$(this).addClass('rollover');
	});	
}

function loadVideo(url) {
	$('#Video').html("");
	$('#Video').media({ 
			type: 'wmv',
			width:     384, 
			height:    352, 
			autoplay:  true, 
			src:       url			
	}); 	
}
function apripopup(url,w,h,res,scroll) {
	win = window.open(url,'v','width='+w+',height='+h+',top=40,left=40,toolbar=0,directories=0,menubar=0,status=0,resizable='+res+',location=0,scrollbars='+scroll+',copyhistory=0');
	win.focus();
}

function classifiche () {
	var numberItem = $("#ColonnaDx .ClassificheTR ul li").length;
	if(numberItem > 1) {
		$("#ColonnaDx .ClassificheTR ").jCarouselLite({
			auto:	10000,
			speed: 1500,
			visible: 1
		});
	} else {
		$("#ColonnaDx .ClassificheTR").css("visibility","visible");
	}
}
/**********************************************************************************************************/
function setFoto(el) {
	var old = $(".RolloverFoto");
	$(".listaItem li").removeClass('RolloverFoto');
	$(old).addClass('th');
	$(el).removeClass('th');
	$(el).addClass('RolloverFoto');
	$("#DescrizioneFoto").html($("#descr_"+$(el).text()).text());
	$("#FotoGrande img").attr("src",$("#img_"+$(el).text()).text());
}
function setFotogallery() {
	var numberFoto = $(".listaItem li").length;
	$("#prev").click(function() {
		var idSel = parseInt($("#cont").text());
		if(idSel == 1) {
			$("#cont").html(numberFoto);
			idSel = numberFoto-1;
		}else {
			$("#cont").html(idSel-1);
			idSel = idSel-2;
		}
		setFoto($(".listaItem li:eq("+idSel+")"));
	});	
	$("#next").click(function() {
		var idSel = parseInt($("#cont").text());
		if(idSel == numberFoto) {
			$("#cont").html("1");
			idSel = 0;
		}else {
			$("#cont").html(idSel+1);
			idSel = idSel;
		}			
		setFoto($(".listaItem li:eq("+idSel+")"));			
	});		
	$(".listaItem li").click(function() {
		var idSel = parseInt($("#cont").text());
		$("#cont").html($(this).text());
		setFoto(this);
	});	
	
}		
/**********************************************************************************************************/

function videoCorrelati (){
	$(".VideoCorrelati .ImgLancio").bind("mouseenter mouseleave", function(E){
        $(".DescrizioneVideo:eq("+$(".VideoCorrelati .ImgLancio").index(this)+")").slideToggle();
    });
	$(".VideoCorrelatiSmall .ImgLancio").bind("mouseenter mouseleave", function(E){
       $(".DescrizioneVideo:eq("+$(".VideoCorrelati .ImgLancio").index(this)+")").slideToggle();
    });
}
/***********************   COOKIES  --- INIZIO ********************************************************************************/
var HOST = '';
function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}
function setCookie (name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
function deleteCookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
/***********************  COOKIES  --- FINE ***********************************************************************************/
/***********************  SILVERLIGHT  --- INIZIO  *****************************************************************************/
function InizializzaSilverlight() 
{
	//Create our install experience html
	var installExperienceHTML = '<div class="SL_container">'; 
	installExperienceHTML += '<div class="SL_info">';
	installExperienceHTML += '<a href="javascript:removeSilverlight();">Se vuoi utilizzare il nuovo player installa Microsoft Silverlight, altrimenti click qui per continuare a navigare utilizzando Windows Media Player</a>';
	installExperienceHTML += '</div><div style="font-size:18px;"><div id="InstallPromptDiv"> </div></div>';
	installExperienceHTML += '<div id="PostInstallGuidance" class="SL_PostInstallGuidance">&nbsp;</div></div>';
		
	Silverlight.InstallAndCreateSilverlight('1.0',document.getElementById('Video'),installExperienceHTML,'InstallPromptDiv',createSilverlight);

	var PostInstallGuidance = document.getElementById('PostInstallGuidance');
	if ( document.getElementById("PostInstallGuidance"))
	{
		if ( Silverlight.ua.Browser == "MSIE")
		{
				if ( Silverlight.available ) 
					PostInstallGuidance.innerHTML="Quando l'installazione e' completata, occorre riavviare il browser.";
				else 
					PostInstallGuidance.innerHTML= "";
		 } else if ( Silverlight.ua.Browser == "Firefox" || Silverlight.ua.Browser == "Safari")  {
			PostInstallGuidance.innerHTML="Il tuo Browser e' "+ Silverlight.ua.Browser + ". Quando l'installazione e' completata,<br /> occorre riavviare il browser.";
		 }  else {	        
			PostInstallGuidance.innerHTML="Il tuo browser potrebbe non supportare Microsoft Silverlight.<br />Per ulteriori informazioni http://www.microsoft.com/silverlight/system-requirements.aspx ";
		 }
	 }
}

var myPlayerObject = null;
function playerLoaded(playerObject)
{
	myPlayerObject = playerObject;
	playerObject.Play(videoURL,videoTitolo);
}
	
function setVideo(url) {
	if(url!= "")
		videoURL = url;

	if (!getCookie("silverlight")) 
	{
		if ( myPlayerObject == null)
			InizializzaSilverlight();
		else
			myPlayerObject.Play(videoURL,videoTitolo);
	}
	else removeSilverlight();
	
	//$('<span id="ChoicePlayerRollOver"></span>').appendTo("#ChoicePlayer").hide();
	$('#ChoicePlayerRollOver').hide();
	
	$("#ChoicePlayer img").bind("mouseenter mouseleave", function(E){
		if($(this).attr('id') == "choice_wmp")
			mess = "Visualizza con Windows Media Player";
		if($(this).attr('id') == "choice_sl") 
			mess = "Visualizza con SilverLight";	
			
		$("#ChoicePlayer span").html(mess).toggle();
    });
	
	$("#ChoicePlayer img").click(function() {
		if($(this).attr('id') == "choice_wmp")
			setCookie("silverlight",'y','','/',HOST,'');
				
		if($(this).attr('id') == "choice_sl") 
			deleteCookie("silverlight",'/',HOST);
		
		location.reload();
	});	
}
	
function removeSilverlight() {
	setCookie("silverlight",'y','','/',HOST,'');
	loadVideo(videoURL);
}
/***********************  SILVERLIGHT  --- FINE  *****************************************************************************/

/***********************  NAVIGATOR   --- INIZIO  ***************************************************************************/
function setNavigatorMenu() {
	var uniquename = $('#urlUniquename').text();
	var submenu = $('#'+uniquename+'_sub').html();
	$('#'+uniquename+' div').css("background", "#f76020");
	if(submenu != null) {
		  $(".categorie").each(function (i) {
			var id = $(this).attr("id");
			if(id == uniquename)
				indice = i;
		});
		var riga = parseInt(indice/4);
		$(".subMenu:eq("+riga+")").html('<div>'+submenu+'</div>');
	}
}
/***********************  NAVIGATOR  --- FINE  *****************************************************************************/
