var CONFIG_XML 	= '/res/xml/config.xml';
var FROM = 'mondotv';
var idbox = 1;
var elencoVisualizzato;
var TIMEOUTAPERTURAHP = 7000;
var timerAperturaHP;

/* ~~~~~~~~~~~~Utils functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function tokenReplace(str, tokens) {
	for ( var t in tokens ) {
		str = str.replace('{' + t + '}', tokens[t]);
	}
	return str;
}

function trimDot(str, len) {
	return ( str.length > len ? str.substring(0, len - 3) + '...' : str );
}

var _GET = (function() {
				var get = {};
				var vars = window.location.search.substring(1).split('&');
				for ( var v in vars ) {
					var pair = vars[v].split('=');
					get[ pair[0] ] = pair[1];
				}
				return get;
})();
function getVars() {
	return _GET;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
$(function() {
	var config = {};
	$.ajax({
		url: 		CONFIG_XML,
		dataType: 	'xml',
		error: 		function() {
		},
		success: 	function(xml) {
				$('param', xml).each(function() {
					config[ $(this).attr('key') ] = $(this).text();
				});



				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Carica il contenuto dell'ora in onda nell'header e nelle eventuali box in spalla destra
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if ($('.ultimaora').length > 0){
					var param = $('.ultimaora').attr('id').split("-");
					var divid = '#'+$('.ultimaora').attr('id');
					var network = param[0];
					var timestamp = param[1];
					$(document).trigger('loadOraInOnda',[divid,network,timestamp]);
				}
				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Disegna la data nell'header
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if ($('.dataora').length > 0){
						var param = $('.dataora').attr('id').split("-");
						var divid = '#'+$('.dataora').attr('id');
						var dayweek = DayWeek(param[0]);
						var day = param[1];
						day = (day.substr(0,1) == 0)? day.substr(1,1) : day;
						var month = Month(param[2]);
						var year = param[3];
						var hour = param[4];
						var minute = param[5];
						$(divid)
							.append( $(	'<span>'+dayweek+', '+day+'  '+month+'</span>'));
							//.append( $(	'<span>'+dayweek+' '+day+'  '+month+' '+year+' '+hour+':'+minute+'</span>'));
				}
				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Gestisce l'apertura temporizzata nell'Homepage
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~				
				*/
				if ($('#hptabcont1').length > 0) {
					$('#hptab1').bind('click', function(evt, cycle) {
						if (cycle == undefined) {
							clearTimeout(timerAperturaHP);
							TIMEOUTAPERTURAHP = 0;
						}
					});
					$('#hptab2').bind('click', function(evt, cycle) {
						if (cycle == undefined) {
							clearTimeout(timerAperturaHP);
							TIMEOUTAPERTURAHP = 0;
						}
					});
					setTimeout("$(document).trigger('triggerAperturaHP')", TIMEOUTAPERTURAHP);
				}

				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Usate nella homepage di MONDOTV e nelle home di rete:
					carica i contenuti video nell'oggetto tab
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				//Video Mondo TV
				if ($('#tabvtv_1').length > 0) $(document).trigger('loadTabContent',['#tabvtv_1','inevidenza','mondotv'])
				if ($('#tabvtv_2').length > 0) $(document).trigger('loadTabContent',['#tabvtv_2','visti','mondotv'])
				if ($('#tabvtv_3').length > 0) $(document).trigger('loadTabContent',['#tabvtv_3','ultimi','mondotv']);
				//Video C5
				if ($('#tabvc5_1').length > 0) $(document).trigger('loadTabContent',['#tabvc5_1','visti','canale5']);
				if ($('#tabvc5_2').length > 0) $(document).trigger('loadTabContent',['#tabvc5_2','ultimi','canale5']);
				//Video I1
				if ($('#tabvi1_1').length > 0) $(document).trigger('loadTabContent',['#tabvi1_1','visti','italia1']);
				if ($('#tabvi1_2').length > 0) $(document).trigger('loadTabContent',['#tabvi1_2','ultimi','italia1']);
				//Video R4
				if ($('#tabvr4_1').length > 0) $(document).trigger('loadTabContent',['#tabvr4_1','visti','rete4']);
				if ($('#tabvr4_2').length > 0) $(document).trigger('loadTabContent',['#tabvr4_2','ultimi','rete4']);
				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Disegna le BOX VIDEO del contenuto 'contenitore box'
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if ($('.ajaxboxvideo').length > 0){
					$('.ajaxboxvideo').each(function(i) {
						var param = $(this).attr('id').split("-");
						var boxid = '#'+$(this).attr('id');
						var num = eval(param[1]*2);
						var brand = param[2];
						$(document).trigger('loadVideoBox',[boxid,brand,num]);
					})
				}

				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Disegna le BOX FOTO del contenuto 'contenitore box'
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if ($('.ajaxboxfoto').length > 0){
					$('.ajaxboxfoto').each(function(i) {
						var param = $(this).attr('id').split("-");
						var boxid = '#'+$(this).attr('id');
						var idfotogallery = param[1];
						var num = eval(param[2]*2);
						$(document).trigger('loadFotoBox',[boxid,idfotogallery,num]);
					})
				}

				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Scrive la messa in onda di un programma in una news
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if ($('#txtinonda').length > 0){
					var txtinonda = $('#txtinonda').eq(0);
					var text =  txtinonda.text();
					var classtxt = txtinonda.attr('class');
					if (jQuery.trim(text) == '')
					{
						var param = txtinonda.attr('class').split("-");
						var boxclass = '.'+txtinonda.attr('class');
						var brand = param[1];
						$(document).trigger('loadMessaInOnda',[brand]);
					}
				}
				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Invia ad un amico
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if($('#artinvia').length > 0){
					$(document).trigger('inviaAmico');
				}
				/*	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Stampa Articolo
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/				
				if($('#artstampa').length > 0){
					$(document).trigger('stampaArticolo');
				}
				/*	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					Disegna randomicamente le foto nel widget
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/
				if($('#widget').length > 0){
					$(document).trigger('drawImgWidget');
					if ($('.ajaxwidget').length > 0){
						$('.ajaxwidget').each(function(i) {
							var widget = $(this).attr('id').split("-");
							var id_li = '#'+$(this).attr('id');
							var widgetarray = widget[0]+'_widget';
							var widgetnum = widget[1];
							var widgetsite = widget[2];
							$(document).trigger('drawWidgetItem',[id_li,widgetarray,widgetnum,widgetsite]);
						})
					}
					/* Gestione del widget automatico */
					$('.widget_button').each(function(i) {
						$(this).bind('click', function(e) {
							var itemid = '#'+$(this).parent().attr('id');
							if($(this).hasClass('piu')){
								
								$('.meno').each(function(j){
										$(this).removeClass('meno');
										$(this).addClass('piu');
										var itemidall = '#'+$(this).parent().attr('id');
										$(itemidall+' p').css('display','none');
								})
								$(this).removeClass('widget_button piu');
								$(this).addClass('widget_button meno');
								$(itemid+' p').css('display','block');
							}
							else{
								$(itemid+' p').css('display','none');
								$(this).removeClass('widget_button meno');
								$(this).addClass('widget_button piu');
							}
						});
					});
				}
				/*
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				*/					
		}
	});


	function makeRequest(type, data, callback, err) {
		var url = tokenReplace( ( config[ type ] == undefined ? type : config[ type ] ), data);
		$.ajax({
			cache: 		false,
			url: 		url,
			dataType: 	'xml',
			data: 		data,
			success: 	callback,
			error: 		$.isFunction(err) ? err : function(XMLHttpRequest, textStatus, errorThrown) {
				//alert('Ajax Error: [' + textStatus + '], [' + errorThrown + ']');
			}
		});
	}
	function getVideoURL(videoId, category, from) {
		var p = videoId.split('/');
		var data = {
			sito: 		p[0],
			data: 		p[1] + '/' + p[2] + '/' + p[3],
			id: 		p[4],
			'category': category,
			'from': 	from
		};
		return tokenReplace( config['url_video'], data );
	}


	$(document)
		.bind('triggerAperturaHP', function(evt) {
			if ($('#hptab1').hasClass('active')) {
				$('#hptab2').trigger('click', [true]);
			} else {
				$('#hptab1').trigger('click', [true]);
			}
			if (TIMEOUTAPERTURAHP > 0) {
				timerAperturaHP = setTimeout("$(document).trigger('triggerAperturaHP')", TIMEOUTAPERTURAHP);
			}
		})
		.bind('loadTabContent', function(evt, tabname, type, network) {
			makeRequest('url_xml', { 'type': type, 'network': network } , function(xml) {
			var videos 	= $('category-content > video-summary', xml);
			var videonum = videos.length;
			videos
				.each(function(i) {
					var id = $(this).attr('id');
					var title = $('> title', this).text();
					var program = $('> program', this).text();
					var program_id = $('> program', this).attr('category-id')
					var description = $('> description', this).text();
					var date = $('> date', this).text();
					var image = tokenReplace( config['url_foto'] , { foto: $('> image', this).text() } );
					var link = getVideoURL(id, program_id, FROM);

					if ((i == 0) && (videonum == 3)) {
						$(tabname)
							.append( $('<div class="boxvideo320x130">' +
										 '<div class="boxplay160x120">' +
										   '<a href="' + link + '">' +
											 '<img src="' + image + '">' +
											 '<img src="/res/img/play_video.png" class="playvideo">' +
										   '</a>' +
										  '</div>' +
										  '<img src="/res/img/ico_video.png">' +
										  '<h4>' + program + '</h4>' +
										  '<h3><a href="'+link+'">' + title +'</a></h3>' +
										  '<p>' + description + '</p>' +
										'</div>'));
					 } else {
						$(tabname)
							.append( $('<div class="boxvideo120x130 boxvideo120x130x' + videonum + '">' +
										  '<div class="boxplay120x90">' +
											'<a href="' + link + '">' +
											  '<img src="' + image + '">' +
											  '<img src="/res/img/play_video.png" class="playvideo">' +
											'</a>' +
										  '</div>' +
										  '<h4><a href="' + link + '">' + program + '</a></h4>' +
										  '<p>' + title + '</p>'+
										'</div>'));
					 }
				});
			});
		})
		.bind('loadVideoBox', function(evt, idbox, brand, num) {
			makeRequest('url_xmlvideo', { 'brand': brand } , function(xml) {
			var videos 	= $('category-content > video-summary', xml);
			videos
				.each(function(i) {
					if(i<num){
						var id = $(this).attr('id');
						var title = $('> title', this).text();
						var program = $('> program', this).text();
						var program_id = $('> program', this).attr('category-id')
						var description = $('> description', this).text();
						var date = $('> date', this).text();
						var image = tokenReplace( config['url_foto'] , { foto: $('> image', this).text() } );
						var link = getVideoURL(id, program_id, FROM);
						$(idbox)
							.append( $(	'<div class="box90x130"><div class="boxplay80x60">'+
										'<a href="'+link+'">'+
										'<img src="'+image+'"><img src="/res/img/play_video_s.png" class="playvideo">'+
										'</a></div>'+
										'<h4><a href="'+link+'">'+title+'</a></h4>'+
										'<p>'+trimDot(description, 35)+'</p>'+
										'</div>'));
					}
				});
			});
		})
		.bind('loadMessaInOnda', function(evt, brand) {
			makeRequest('url_messainonda', { 'brand': brand } , function(xml) {
			var messainonda = $('programmazione > messainonda:eq(0)', xml).text();
			$('#txtinonda')
				.append(messainonda);
			})
		})
		.bind('loadFotoBox', function(evt, idbox, idfotogallery, num) {
			makeRequest('url_xmlfoto', { 'idfotogallery': idfotogallery } , function(xml) {
			var fotos 	= $('fotogallery > foto', xml);
			fotos
				.each(function(i) {
					if(i<num){
						var idfoto = $(this).attr('id');
						var descrizione = $('> descrizione', this).text();
						var image = $('> image', this).text();
						var link = tokenReplace( config['url_shtmlfoto'] , { idfotogallery: idfotogallery, idfoto: idfoto } );
						$(idbox)
							.append( $(	'<div class="box90x130bis">'+
										'<a href="'+link+'"><img src="'+image+'"></a>'+
										'<h4><a href="'+link+'">'+trimDot(descrizione,55)+'</a></h4></div>'));
					}
				});
			});
		})
		.bind('drawImgWidget', function() {
			var src_foto1 = mondo_tv_widget['img1'];
			var src_foto2 = mondo_tv_widget['img2'];
			var src_foto3 = mondo_tv_widget['img3'];

			var round1 = Math.round(Math.random() * 100) % 3;
			var round2 = Math.round(Math.random() * 100) % 2;
			var src_foto = '';

			if ( (src_foto1 != '/') && (src_foto2 != '/') && (src_foto3 != '/') )
			{
				if (round1 == 0) 		src_foto=src_foto1;
				else if (round1 == 1)	src_foto=src_foto2;
				else if (round1 == 2)	src_foto=src_foto3;
			}
			else if ( (src_foto1 != '/') && (src_foto2 != '/') && (src_foto3 = '/'))
			{
				if (round2 == 0)		src_foto=src_foto1;
				else if (round2 == 1)	src_foto=src_foto2;
			}
			else	src_foto=src_foto1;

			$('#wmain > div > div > a')
				.append( $(	'<img width="195" height="147" src="'+src_foto+'"></img>'))
		})
		.bind('drawWidgetItem', function(evt, id_li, widgetarray, widgetnum, widgetsite) {
			var logo = (widgetsite=='tgcom'||widgetsite=='sportmediaset')? 'news' : 'video';
			var news = 'news'+widgetnum;
			var occhiello = (widgetsite=='tgcom'||widgetsite=='sportmediaset')? widgetsite+' - '+eval(widgetarray)[news]['sezione'] : eval(widgetarray)[news]['sezione'];
			$(id_li)
				.append( $('<div class=\'widget_button piu\'><span>widget_button</span></div><h4 class=\'uppercase\'>'+occhiello+'</h4><h3 class=\''+logo+'\'><a href="'+eval(widgetarray)[news]['link']+'">'+eval(widgetarray)[news]['titolo']+'</a></h3><p>'+eval(widgetarray)[news]['catenaccio']+'</p>'))
		})
		.bind('inviaAmico', function() {
			var tit = $('#txtspace > h1').text();
			var domaininvia='www.tv.mediaset.it';
			var urlinvia=document.location.href;
			var subjPrefix="Articolo su "+domaininvia+": ";
			var bodyPrefix="\n\n Puoi trovare questo articolo all'indirizzo:\n";
			var subj=escape(subjPrefix+tit);
			var body=escape('Articolo su www.tv.mediaset.it: "'+tit+'"'+bodyPrefix+urlinvia);
			//alert($('#artinvia > a').attr('href'))
			var mail =  'mailto:?subject='+subj+'&body='+body;
			$('#artinvia > a')
				.attr('href', mail);
		})
		.bind('stampaArticolo', function() {
			var id = $('#container').attr('class');
			var urlstampa = 'javascript:anteprima(\''+id+'\')';
			$('#artstampa > a')
				.attr('href', urlstampa);

		})
		.bind('loadOraInOnda', function(evt, divid, network, timestamp) {
			makeRequest('url_palinsesto', '', function(xml) {

			if(network=='C5') network='Canale 5';
			else if(network=='I1') network='Italia 1';
			else if(network=='R4') network='Rete 4';

			var programs = $('programmi > programma', xml);
			var titoloR4 ='';
			var oraR4 = '';
			var titoloI1 ='';
			var oraI1 = '';
			var titoloC5 ='';
			var oraC5 = '';
			var titoloR4next ='';
			var oraR4next = '';
			var titoloI1next ='';
			var oraI1next = '';
			var titoloC5next ='';
			var oraC5next = '';
			programs
				.each(function(i) {
					var time = eval($(this).attr('timestamp'));
						if(timestamp>=time && $(this).attr('idref')=='C5'){
							titoloC5 = $(this).attr('titolo');
							oraC5 = $(this).attr('ora');
						}
						else if($(this).attr('idref')=='C5'){
							titoloC5next = $(this).attr('titolo');
							oraC5next = $(this).attr('ora');
							return false;
						}
				});
			programs
				.each(function(i) {
					var time = eval($(this).attr('timestamp'));
						if(timestamp>=time && $(this).attr('idref')=='I1'){
							titoloI1 = $(this).attr('titolo');
							oraI1 = $(this).attr('ora');
						}
						else if($(this).attr('idref')=='I1'){
							titoloI1next = $(this).attr('titolo');
							oraI1next = $(this).attr('ora');
							return false;
						}
				});
			programs
				.each(function(i) {
					var time = eval($(this).attr('timestamp'));
						if(timestamp>=time && $(this).attr('idref')=='R4'){
							titoloR4 = $(this).attr('titolo');
							oraR4 = $(this).attr('ora');
						}
						else if($(this).attr('idref')=='R4'){
							titoloR4next = $(this).attr('titolo');
							oraR4next = $(this).attr('ora');
							return false;
						}
				});
				$(divid)
					.append( $(	'<div id=\'ultimaora1\'><strong>'+oraC5+' - CANALE 5 -</strong><span>'+titoloC5+'</span></div>'+
								'<div id=\'ultimaora2\'><strong>'+oraI1+' - ITALIA 1 -</strong><span>'+titoloI1+'</span></div>'+
								'<div id=\'ultimaora3\'><strong>'+oraR4+' - RETE 4 -</strong><span>'+titoloR4+'</span></div>'));

				setInterval("rotateUltimaora(idbox++)", 5000);


				if ($('#orainondaC5').length > 0){
					if(titoloC5!=''){
						$('#orainondaC5')
							.append( $(	'<li><span class="txt_Time">Ore '+oraC5+'</span><span class="txt_Title">'+titoloC5+'</span></li>'));
					}
					if(titoloC5next!=''){
						$('#orainondaC5')
							.append( $(	'<li><span class="txt_Time">Ore '+oraC5next+'</span><span class="txt_Title">'+titoloC5next+'</span></li>'));
					}
				}

				if ($('#orainondaI1').length > 0){
					if(titoloI1!=''){
						$('#orainondaI1')
							.append( $(	'<li><span class="txt_Time">Ore '+oraI1+'</span><span class="txt_Title">'+titoloI1+'</span></li>'));
					}
					if(titoloI1next!=''){
						$('#orainondaI1')
							.append( $(	'<li><span class="txt_Time">Ore '+oraI1next+'</span><span class="txt_Title">'+titoloI1next+'</span></li>'));
					}
				}

				if ($('#orainondaR4').length > 0){
					if(titoloR4!=''){
						$('#orainondaR4')
							.append( $(	'<li><span class="txt_Time">Ore '+oraR4+'</span><span class="txt_Title">'+titoloR4+'</span></li>'));
					}
					if(titoloR4next!=''){
						$('#orainondaR4')
							.append( $(	'<li><span class="txt_Time">Ore '+oraR4next+'</span><span class="txt_Title">'+titoloR4next+'</span></li>'));
					}
				}

				if ($('#orainondaTV').length > 0){
					if(titoloC5!=''){
						$('#orainondaTV')
							.append( $(	'<li><span class="txt_Time">Ore '+oraC5+'</span><span class="txt_Title">CANALE 5 - '+titoloC5+'</span></li>'));
					}
					if(titoloI1!=''){
						$('#orainondaTV')
							.append( $(	'<li><span class="txt_Time">Ore '+oraI1+'</span><span class="txt_Title">ITALIA 1 - '+titoloI1+'</span></li>'));
					}
					if(titoloR4!=''){
						$('#orainondaTV')
							.append( $(	'<li><span class="txt_Time">Ore '+oraR4+'</span><span class="txt_Title">RETE 4 - '+titoloR4+'</span></li>'));
					}
				}


			});
		})



});

/* ~~~~~~~~~~~~Gestione della data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function DayWeek(dayweek){
  switch (dayweek) {
  case 'Monday': 	return 'luned&igrave;';
  case 'Tuesday': 	return 'marted&igrave;';
  case 'Wednesday': return 'mercoled&igrave;';
  case 'Thursday':	return 'gioved&igrave;';
  case 'Friday': 	return 'venerd&igrave;';
  case 'Saturday': 	return 'sabato';
  case 'Sunday': 	return 'domenica';
  }
}
function Month(month){
  switch (month) {
  case '01': return 'gennaio';
  case '02': return 'febbraio';
  case '03': return 'marzo';
  case '04': return 'aprile';
  case '05': return 'maggio';
  case '06': return 'giugno';
  case '07': return 'luglio';
  case '08': return 'agosto';
  case '09': return 'settembre';
  case '10': return 'ottobre';
  case '11': return 'novembre';
  case '12': return 'dicembre';
  }
}
/* ~~~~~~~~~Anteprima di stampa~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function anteprima(id){
	var w=705;
	var h=530;
	var settings = 'location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=no,fullscreen=no,top=10,left=10,width='+w+',height='+h;
	var url = document.location.href;
	if(url.match("servizi")=='servizi')
		var popup=window.open('/res/html/stampapopup.shtml?/servizi/stampa/servizio_stampa_'+id+'.shtml','stampa',settings);
	else
	var popup=window.open('/res/html/stampapopup.shtml?/articoli/stampa/articolo_stampa_'+id+'.shtml','stampa',settings);

	if(popup != null)
		popup.focus();
}
/* ~~~~~~~~~Stampa~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function stampa(){
	print();
	window.close ();
}
/* ~~~~~~~~~Ricerca di yahoo: controllo del testo da cercare~~~~~~~~~~~*/

function cerca() {
		obj = document.ricercayahoo;
		var val = obj.p.value;
		if(val.length>0){
			return true;
		} else {
			alert('Inserire il testo da cercare'); 	return false;
		}
}

/* ~~~~~~~~~Rotazione della programmazione negli header~~~~~~~~~~~~~~~~*/
function rotateUltimaora(idbox){
	var id = (idbox % 3);
	if(id==0) id=3;

	document.getElementById("ultimaora1").style.display='none';
	document.getElementById("ultimaora2").style.display='none';
	document.getElementById("ultimaora3").style.display='none';
	var current = document.getElementById("ultimaora"+id);
	current.style.display='block';
}


/* ~~~~~~~~~Paginazione programmi GuidaTV~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function showElencoProgrammi(n){
	if(elencoVisualizzato != undefined){
		var elencoDaNascondere = 'elencoProgrammi_' + elencoVisualizzato;
		document.getElementById(elencoDaNascondere).style.display = 'none';;
	}
	var elencoDaMostrare = 'elencoProgrammi_' + n;
	var indiceDaMostrare = 'linkProgrammi_' + n;
	document.getElementById(elencoDaMostrare).style.display = 'block';
	$('#paggs > li > a').each(function() {
		$(this).removeClass('active');
	});
	if($('#paggs > li > a').length > 1)
		$('#' + indiceDaMostrare + ' > a').addClass('active');
	elencoVisualizzato = n;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

