//	visualizza div
function display_block(id) {
	document.getElementById(id).style.display = "block";
}
function hide_block(id) {
	document.getElementById(id).style.display = "none";
}

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 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 changeTitle(title) {
	title = title.replace(/&#39;/g, "'");
	document.title = "RaiSport - " +title;
}

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 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;
var widthPlayer = 384;
var heightPlayer = 352;
function playerLoaded(playerObject)
{
	myPlayerObject = playerObject;
	playerObject.Play(videoURL,videoTitolo);
}

function loadVideo(url) {
	$('#Video').html("");
	$('#Video').media({ 
			type: 'wmv',
			width:     widthPlayer, 
			height:    heightPlayer, 
			autoplay:  true, 
			src:       url			
	}); 	
}
function setVideoProgramma() {
	var urlVideo = $("#choicePuntata>option:eq(0)").attr("value");
	loadVideo(urlVideo);
	$("#choicePuntata").change(function () {
          $("#choicePuntata option:selected").each(function () {
				$("#titoloPuntata").html($(this).text());
				loadVideo($(this).attr("value"));
				$("#titoloPuntata").focus();
            });
     }).change();
}	

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  *****************************************************************************/
function setNielsen(url) {
	$("#nielsen img").attr("src","//secure-it.imrworldwide.com/cgi-bin/m?ci=rainet-it&cg=0&si="+url);
}

function applyPngFix()
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
}
