/***********************  SILVERLIGHT  OLIMPIADI  --- INIZIO  ******************************************************************/
function setLiveBeijing(url) {
	if(url!= "")
		videoURL = url;

	if (!getCookie("silverlight")) 
	{
		//location.href = "/dl/silverlight/olimpiadi2008/Default.html";
		location.href= "/dl/RaiSport/PublishingBlock-b4e0c005-45c3-4562-870c-9cff574c184d.html";
	}
	else removeSilverlight();
	
	//$('<span id="ChoicePlayerStreamRollOver"></span>').appendTo("#ChoicePlayerStream").hide();
	$('#ChoicePlayerStreamRollOver').hide();
	
	$("#ChoicePlayerStream 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";	
			
		//$("#ChoicePlayerStream span").html(mess).toggle();
    });
	
	$("#ChoicePlayerStream img").click(function() {
		if($(this).attr('id') == "choice_wmp") {
			setCookie("silverlight",'y','','/',HOST,'');
		}
				
		if($(this).attr('id') == "choice_sl") {
			deleteCookie("silverlight",'/',HOST);
			location.href = "/dl/RaiSport/PublishingBlock-b4e0c005-45c3-4562-870c-9cff574c184d.html";			
		}
	});	
}
function redirectToWmp() {
	setCookie("silverlight",'y','','/',HOST,'');
	location.href = "/dl/RaiSport/PublishingBlock-b2510b60-fd81-4f11-9574-6987db14158f.html";
}
function redirectToSpeciale() {
	location.href = "http://www.pechino2008.rai.it";
}
/***********************  SILVERLIGHT  OLIMPIADI  --- FINE  *********************************************************************/
/***********************  WMP  OLIMPIADI  --- INIZIO  *********************************************************************/

function getIP(){
	return $.ajax({
	  url: "/dl/RaiSport/getip.shtml",
	  async: false
	}).responseText;
}
function setPlayBeijing() {
	$('.SpanPlay').click(function() {
		setNielsen(location.href);
		var index = $(".SpanPlay").index(this);
		setVideo($(".StreamingFull li:eq("+index+")").text());
		$("#PlayerTitle").html($(".liveTitle:eq("+index+")").text());
	});
}

function setPreviewBeijing() {
	$('.SpanPreview').click(function() {
		if ($(this).text() == "Preview Off") {
			$(this).text("Preview On");
			$(this).css("color","#666");
			var index = $(".SpanPreview").index(this);
			$(".StreamingFullTagP:eq("+index+")").html("");
			$(".StreamingFullTagP:eq("+index+")").html('<a href="#"><img src="/dl/RaiSport/images/mask_stream16-9.gif" width="136" height="78"></a>');
		} else {
			if ($(".SpanPreview:contains('Preview Off')").length < maxPreviewVideo) {
				$(this).text("Preview Off");
				$(this).css("color","#35B64F");
				var index = $(".SpanPreview").index(this);
				drawPlayer($(".StreamingFullTagP:eq("+index+")"),$(".StreamingPreview li:eq("+index+")").text());
			} else
				alert("Possono essere attivati al massimo " + maxPreviewVideo + " video in preview contemporanea.");
		}
	});
}

function setAllPreview() {
	$("#allPreview").toggle(
	  function () {
			$(".SpanPreview").text("Preview Off");
			$(".SpanPreview").css("color","#35B64F");
			$(this).text("VIDEO OFF");
			$(this).css("color","#35B64F");
			$(".SpanPreview").each(function(index){
				drawPlayer($(".StreamingFullTagP:eq("+index+")"),$(".StreamingPreview li:eq("+index+")").text());
			});
			
	  },
	  function () {
			$(".SpanPreview").text("Preview On");
			$(".SpanPreview").css("color","#666");
			$(this).text("VIDEO ON");
			$(this).css("color","#666");
			$(".SpanPreview").each(function(index){
				$(".StreamingFullTagP:eq("+index+")").html("");
				$(".StreamingFullTagP:eq("+index+")").html('<a href="#"><img src="/dl/RaiSport/images/mask_stream16-9.gif" width="136" height="78"></a>');
			});				
		}
	);			
}

function drawPlayer(el,url) {
	var html = '<object classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"'
			+' codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"'
			+' type="application/x-oleobject"  width="132"  height="80" align="middle"  standby="Loading Microsoft Windows Media Player components..."'
			+' id="mediaPlayer"><param name="URL" value="'+url+'" /><param name="animationatStart" value="true" />'
			+' <param name="transparentatStart" value="true" /><param name="autoStart" value="true" /><param name="uiMode" value="none" />'
			+' <embed src="'+url+'" width="132"  height="80"  autostart="0" align="middle" type="application/x-mplayer2" '
			+'pluginspage = "http://www.microsoft.com/windows/mediaPlayer/" showcontrols="0"></embed></object>';
	$(el).html("");
	$(el).html(html);
}
/***********************  WMP  OLIMPIADI  --- FINE  *********************************************************************/	
var ipAddress = getIP();
//var keyBeijing = funzione(ipAddress);
