  	function setjCarouselLite() {
		$(".focusSmall .face").jCarouselLite({
			btnNext: ".focusSmall .next",
			btnPrev: ".focusSmall .prev",
			auto:	10000,			
			speed: 700,
			visible: 1,
			easing: "easeOutBack"
		});
	}
	
	function setSpallaDX(){
	    var ul = $(".mobile ul"), li = $(".mobile");
	    ul.hide();
	    li.click(function() {
			//ul.is(":visible");
			var id = $(this).attr('id');
			$(".mobile:not(#"+id+") ul").slideUp();
			$('#'+id+' ul').slideToggle("slow");
	    });
	}
	
	function setEdizioniTG(){	
		var li = $(".ora li");
	    li.click(function() {
			//var url = location.href.substring(0,location.href.indexOf(".html")+5);
			var url = location.href;
			$("#nielsen img").attr("src","//secure-it.imrworldwide.com/cgi-bin/m?ci=rainet-it&cg=0&si="+url);
			li.removeClass('big');
	        var id = $(this).attr('id');
			showDiv(id);
			var linkVideo = $('#video_'+id).text();
			loadVideo(linkVideo);
	    });
		// var linkVideo = $('#video_'+$(li[0]).attr('id')).text();
		// $('#video img').click(function() {
		// 	loadVideo(linkVideo);
		// });
	}
	
	function setFirstTG(){
		showDiv("1");
	    var img = $("#video img");
	    img.click(function() {
			var linkVideo = $('#video_1').text();
			if(linkVideo != "")
				loadVideo(linkVideo);
	    });	
		
	}
	
var skipNextNielsen = false;
var setNielsen = function(url) {
	if (skipNextNielsen) {
		skipNextNielsen = false;
		return false;
	}

	if (url == undefined){url = location.href};
	if (url.match("^/dl")){url = "http://www.tg2.rai.it"+url};
	if (url.match("www.rai.tv")){url = url.replace(/www\.rai\.tv/gi, 'www.tg2.rai.it')};
	url = encodeURIComponent(url);
	// Zozzata richiesta da nielsen
	url = url.replace(/%2F/g,'/');
	var rnd = (new Date()).getTime();
	$("#nielsen img").attr("src","//secure-it.imrworldwide.com/cgi-bin/m?ci=rainet-it&cg=0&si="+url+"&rnd="+rnd);
};

	function loadVideo(url) {
		var elem = $('#video');
		if (elem.length == 0) {
			elem = $('#Video');
		}
		elem = elem[0];
		setNielsen(document.location+'#video='+url);
		
		var initParams = 'videoPath='+ url +',aspect=43,auto=true';
		
		if (/\.html$/gi.test(url)) {
			url = url.replace(/\.html$/gi, '.xml');
		}
		if (/\.xml$/gi.test(url)) {
			initParams = 'xmlPath='+ url +',aspect=43,auto=true';
		}
		
		Silverlight.createObject(
			"/dl/portale/silverlight/Vod/Lettore_Rai_VOD.xap",
			elem,
			'silverlightControl',
			{
				width: '319',
				height: '274',
				inplaceInstallPrompt: false,
				background: 'transparent',
				windowless: true,
				framerate: '25',
				version: '2.0'
			},
			{
				onError: onSilverlightError
			},
			initParams,
			{
				mediaName: 'me' // mediaelement's name in our xaml
			}
		);
	}
	function onSilverlightError(sender, args) {

		var appSource = "";
		if (sender != null && sender != 0) {
			appSource = sender.getHost().Source;
		}
		var errorType = args.ErrorType;
		var iErrorCode = args.ErrorCode;

		var errMsg = "Unhandled Error in Silverlight 2 Application " +  appSource + "\n" ;

		errMsg += "Code: "+ iErrorCode + "    \n";
		errMsg += "Category: " + errorType + "       \n";
		errMsg += "Message: " + args.ErrorMessage + "     \n";

		if (errorType == "ParserError")
		{
			errMsg += "File: " + args.xamlFile + "     \n";
			errMsg += "Line: " + args.lineNumber + "     \n";
			errMsg += "Position: " + args.charPosition + "     \n";
		}
		else if (errorType == "RuntimeError")
		{
			if (args.lineNumber != 0)
			{
				errMsg += "Line: " + args.lineNumber + "     \n";
				errMsg += "Position: " +  args.charPosition + "     \n";
			}
			errMsg += "MethodName: " + args.methodName + "     \n";
		}

		throw new Error(errMsg);
	}
	function WMV_loadVideo(url) {
		$('#video').html("");
		$('#video').media({ 
				type: 'wmv',
			    width:     319, 
			    height:    274, 
				autoplay:  true, 
			    src:       url			
		}); 	
	}
	
	function showDiv(idObj){
		var div = $(".testi");
		div.hide();
		$('div[@id^="popvideo_"]').hide();
		$('#popvideo_'+idObj).show();
		$('#testi_'+idObj).show();
		$('#'+idObj).addClass('big');
	}
	
$(function() {	
	if ($('#Classifiche h1').length > 0) {
		// $('#Classifiche ul').html('');
		$('#Classifiche').remove();
	}
});
