var enabledComment=false;
var videoTv=false;

$.fn.truncatitle = function(options) {
	//set default options
	var defaults = {
		limit: 50
	};

	//call in the default otions
	var options = $.extend(defaults, options);

	//act upon the element that is passed into the design
	return this.each(function(i) {
		//check length of text to what out maximum is
		if($(this).text().length > defaults.limit) {
	var val0=$(this).html().lastIndexOf(" ",defaults.limit);
			var val1=$(this).html().lastIndexOf(",",defaults.limit);
			var val2=$(this).html().lastIndexOf(";",defaults.limit);
			var val3=$(this).html().lastIndexOf(":",defaults.limit);
var endTruncate=Math.max(val0,val1,val2,val3);
			var splitText = $(this).html().substr(endTruncate);
			var hiddenText = '<span style="display:none">'+splitText+'</span>'
			$(this).html($(this).text().substr(0,endTruncate)).append('&nbsp;<span>&#8230;<span/>'+hiddenText);
			/*var splitText = $(this).html().substr(defaults.limit);
			var hiddenText = '<span style="display:none">'+splitText+'</span>'
			$(this).html($(this).text().substr(0,defaults.limit)).append('<span>&#8230;<span/>'+hiddenText);
			*/
		}
	});
};


$(document).ready(function (){
		/* menu utente registrato*/
		$('#h_log').click(function () {$('#h_mnu').slideToggle("slow");$('#h_log').toggleClass('on');return false;});
		$("#h_mnu li:last").css('border-bottom','none');
		$("#h_mnu li:first").css('border-top','none');
		/*footer*/
		$('#footer dl:last').css('margin-right','0');
		$('#f_wtv dl dd:gt(6)').css('width','280px');
		//gestione grafica voto attivo
		if ($('DIV').is('.rating')) {
			var pos = $('.rating .voto').css('backgroundPosition'); //posizione in cui e' il bkg
			var votato = false;
			$('.voto LI A').mouseover(function(){
				var ulbg = $(this).parent().parent(); //UL in cui cambiare il background
				var lk = $(this); //link
				grafVoto(lk,ulbg);
			}).mouseout(function(){
				var ulbg = $(this).parent().parent(); //UL in cui cambiare il background
				ulbg.attr('style','background-position:'+pos+';');
			}).click(function(){
				var ulbg = $(this).parent().parent(); //UL in cui cambiare il background
				var lk = $(this); //link
				grafVoto(lk,ulbg);
				if (votato===false) {
					$('.rating .info01').html('Grazie per aver votato');
					votato = true;
				} else {
					$('.rating .info01').html('<b>Hai gi&agrave; votato</b>');
				}
			});
		}

	//gestione msg overlay
	if ($('A').is('.aol1')) {
		$('.aol1').colorbox({transition:'none',title:true,initialWidth:'0',initialHeight:'0'});
	}
	//gestione msg overlay LOGIN
	if ($('A').is('.ax1')) {
		$(".ax1").colorbox({transition:'none',title:true,initialWidth:'0',initialHeight:'0'});
	}

	//chiusura footer federato//
	var ftf = '';
	$('.ti-tab a').click(function(){
		$('.ti-collapsable ul').slideToggle();
		if(ftf == ''){
		$(this).html('Aprire');
		$(this).addClass('ti-closed');
		ftf = 'chiuso';
		}else {
			$(this).html('Chiudere');
			$(this).removeClass('ti-closed');
			ftf = '';
		}
		return false;
	})

});

	//equlizza colonne
	function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();

		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
	}

	//fx grafica voto
	function grafVoto(lk,ulbg) {
		if (lk.is('.lk01')) {
			ulbg.attr('style','background-position:-166px -125px;');
		}
		if (lk.is('.lk02')) {
			ulbg.attr('style','background-position:-166px -136px;');
		}
		if (lk.is('.lk03')) {
			ulbg.attr('style','background-position:-166px -147px;');
		}
		if (lk.is('.lk04')) {
			ulbg.attr('style','background-position:-166px -158px;');
		}
		if (lk.is('.lk05')) {
			ulbg.attr('style','background-position:-166px -169px;');
		}
	}


function headerLogin(){
	if (isLogged()){
	  var nick = getCookie('nick');

 		$("#head_utn_log").show();
 		$("#head_utn_nlog").hide();
 		$('.logName').html("Benvenuto " + nick);
 		$('.logName').show();
 	} else {
 	  var urlReg = "http://registrazioni.alice.it/ig/cubo/registra/form.do?entryPoint=cubo&urlRitorno=";
			  urlReg += encodeURIComponent("https://buy.cubovision.it/registration/createprofile?urlRegOk=http://"+getBaseUrl()+"&urlRegKo=http://"+getBaseUrl());

    $('.logName').hide();
 		$("#head_utn_nlog").show();//attr('style','visibility:inline');
 		$("#head_utn_log").hide();
 		$('#h_reg').attr('href',urlReg);
 	}

	if (isParentalControl()) {
	 $('#h_pr_cntrl').addClass('pct_on');
	 $('#statuspc').html("ON");
	} else {
   $('#h_pr_cntrl').removeClass('pct_on');
   $('#statuspc').html("OFF");
  }
}


//Paginazione galleri
var pag_counter = 1;
	function numeri(selec,chi,container){
			var MMX = $(selec).length -1;
			$(selec).removeClass('on');
			$(selec).eq(chi).addClass('on');
			pag_counter = $(selec).eq(chi).text();
			if(pag_counter == 1 ){
				$(''+container+' .gal_left').css('display','none');
			}else {
				$(''+container+' .gal_left').css('display','block');
			}
			if( pag_counter >MMX ){
				$(''+container+' .gal_right').css('display','none');
			}else{
				$(''+container+' .gal_right').css('display','block');
			}
}

	function precedente(selec,container){
		$(selec).removeClass('on');
		$(selec).eq(pag_counter - 2).addClass('on');
		$(''+container+' .gal_right').css('display','block');
			if(pag_counter == 2){
				$(''+container+' .gal_left').css('display','none');
			}else{
				$(''+container+' .gal_left').css('display','block');
			}
		pag_counter--
}

	function successiva(selec,container){
		var MMX = $(selec).length -1;
		$(selec).removeClass('on');
		$(selec).eq(pag_counter).addClass('on')
		$(''+container+' .gal_left').css('display','block');
		if(pag_counter == MMX){
			$(''+container+' .gal_right').css('display','none');
		}else{
			$(''+container+' .gal_right').css('display','block');
		}
		pag_counter++
}

function isParentalControl(){
	 return isCookiePresent("CubovisionFF3");
}

function isValidParentalProcess(){
	 return isCookiePresent("CubovisionFF1");
}
function isValidParentalUser(){
	 return isCookiePresent("CubovisionFF");
}

function isLogged() {
  return isCookiePresent("authen");
}

function getBaseUrl() {
  var baseurl;
  var txt=document.URL;//'http://blog.cubovision.it/pippo.html?jsdhgf=asjkdhg';

  var re1='.*?';	// Non-greedy match on filler
  var re2='((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])';	// Fully Qualified Domain Name 1

  var p = new RegExp(re1+re2,["i"]);
  var m = p.exec(txt);
  if (m !== null)
  {
      var tempbaseurl=m[1];
      baseurl = tempbaseurl.replace(/</,"&lt;");
  }

  return baseurl;
}

function inPageLogin() {
  var baseurl = getBaseUrl();

  var username = document.getElementById("username").value;
  var password = document.getElementById("password").value;

  if (username.indexOf('@') == -1) {
    username += "@alice.it";
  }

  var url = "https://aaacsc.alice.it/piattaformaAAA/aapm/amI";
  url += "?a3l=" + encodeURIComponent(username) + "&a3p=" + encodeURIComponent(password)+"&channel=1&totop=false&nototopa3ep=true";
  url += "&a3ep="+encodeURIComponent("https://aaacsc.alice.it/idema/aapm/Forward?serviceid=cubo&channel=1&login="+username+"&password="+password+"&urlOk=http://"+baseurl+"/logOk.html&urlKo=http://"+baseurl+"/logKo.html&isAjax=1");
  url += "&a3afep="+encodeURIComponent("https://aaacsc.alice.it/idema/aapm/Forward?serviceid=cubo&urlKo=http://"+baseurl+"/logKo.html&urlOk=http://"+baseurl+"/logOk.html&channel=1&isAjax=1");

  var theIframe = document.createElement("iframe");
  theIframe.style.visibility = "hidden";
  theIframe.setAttribute('id', 'asynchIF');
  document.body.appendChild(theIframe);

  theIframe.src = url;
}

function loginOk() {
  $.fn.colorbox.close();
  var theIframe = document.getElementById("asynchIF");
  document.body.removeChild(theIframe);
  $("#head_utn_nlog").hide();
  //$("#head_utn_log").show();
  headerLogin();
}

function loginKo() {
  var theIframe = document.getElementById("asynchIF");
  document.body.removeChild(theIframe);

  //alert("Login Ko");
  $(".alert").show();
  $("#head_utn_nlog").show();
  $("#head_utn_log").hide();
}


function viewLogin() {
//alert("common view login");
  var urlLogin="/common/alert/template_Wlogin.html";
  var urlReg = "http://registrazioni.alice.it/ig/cubo/registra/form.do?entryPoint=cubo&urlRitorno=";
			urlReg += encodeURIComponent("https://buy.cubovision.it/registration/createprofile?urlRegOk=http://"+getBaseUrl()+"&urlRegKo=http://"+getBaseUrl());

	$.fn.colorbox({href:""+urlLogin});
	$(document).bind('cbox_complete', function(){
	  $(".alert").hide();
	  $("#reglink").attr("href", urlReg);
	  $('#lostpwdlink').attr('href', "http://gest.virgilio.it/ryalp/lostpassword");
	});
}

/* Refresh della sessione */
function refreshSession() {
  //var theIframe = document.getElementById("sessionIframe");

  //theIframe.src = "http://aa.cubovision.it/aa/refreshSession";
  callJson("http://aa.cubovision.it/aa/refreshSession","");
}
/* Refresh della sessione ogni 10 minuti */
setTimeout("refreshSession",600000);

function checkLogin() {
    if (!isLogged()){
        viewLogin();
        return false;
    }
    return true;
}

//array contenente le richieste JSON da stoppare
var arrayBlockCall = new Array();

function callJson(request,callBack) {

        if(arrayBlockCall[request]!='STOP'){
          arrayBlockCall[request] = 'STOP';
          setTimeout(function(){arrayBlockCall[request]=null;}, 250);

          if(request.indexOf("?")==-1){
               request += "?";
          }else{
              request += "&";
          }
  	    	request = request + "OUTPUT=json";
  	    	request = request + "&view=json";
  	    	request = request + "&CALLBACK="+callBack;
  	    	request = request + "&callback="+callBack;

  				aObj = new JSONscriptRequest(request);
  				aObj.buildScriptTag();
  		 		aObj.addScriptTag();
		 		}
}

function getLinkAllCat(categorizationCubo){
		var link_array = new Array();
		var link=categorizationCubo;
		link=link.toLowerCase();
		link=link.replace(/ /g,"_");
		link_array=link.split(";");
		link=link_array[0]+"/"+link_array[1] +"/";
		return link;
}

function getLinkAllVodByCat(categorizationCubo){
		var link_array = new Array();
		var link=categorizationCubo;
		link=link.toLowerCase();
		link=link.replace(/ /g,"_");
		link_array=link.split(";");
		link=link_array[0]+"/"+link_array[1] +"/"+link_array[2]+"/";
		return link;
}

function getLinkVod(categorizationCubo){
		var link_array = new Array();
		var link=categorizationCubo;
		link=link.toLowerCase();
		link=link.replace(/ /g,"_");
		link_array=link.split(";");
		link=link_array[0]+"/"+link_array[1] +"/"+link_array[2]+"/"+getCntId()+".html";
		return link;
}


	function getCntAssetid(){
	  return _contentBean.assetId;
	}

	function getCntId(){
		var cntid = _contentBean.contentId;
		if(cntid == 0){
			cntid = getContentIdFromUrl();
		}
		return cntid;
	}

	function getContentIdFromUrl(){
		try{
			var sPath = window.location.pathname;
			var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
			var sContentId = sPage.substring(0, sPage.indexOf('.'));

			return sContentId;
		}catch(e){
			return "";
		}
	}
	function getCntType(){
			var contentType = null;
			if(_contentBean.contentType == undefined){
           contentType = '\'VOD\'';
      }else{
           contentType = _contentBean.contentType;
      }
			return contentType;
	}

	function getCntTitle(){
	  return _contentBean.title;
	}

	function getCntDescription(){
		_contentBean.longDescription;
	}

	function getCntLink(){
		return "http://www.google.it";
	}

	function getCntVideoFileUrl(){
		return _contentBean.videoFileUrl;
	}

	function getCntTrailerFileUrl(){
		return _contentBean.trailerFileUrl;
	}

	function getCntTrailerDuration(){
		return _contentBean.trailerDuration;
	}

	function getCntDuration(){
		return _contentBean.duration;
	}

	function getCntImg(){
		return _contentBean.imageFilePath;
	}

	function getCntCat(){
		return _contentBean.categorization;
	}

	function getCntCategorizationCubo(){
		//return _contentBean.categorization_cubo;
		return "";
	}

 //funzione che torna i minuti a partire dai secondi
	function getMinutesBySeconds(time){

		time=parseInt(time);
		var minute = time / 60;
		var hour = 0;
		var k = 60;
		var str = "";
		if(minute > 0){
				str= Math.round(minute)+" min";

		}else{
			str=time+" sec";

		}
	return str;
}

function printStatistic(num){
	if (num == null || num == undefined || num == 0){
		return 'Mai';
	}
	if (num == 1){
		return '1 volta';
	}
	else{
		return num+' volte';
	}
}

function trunkDate(date){
	var dataF=date.substring(8,10)+"-"+date.substring(5,7)+"-"+date.substring(0,4);
	return dataF;
}

function formatSeconds(seconds){
	var minTotali = Math.floor(seconds / 60);
	var s = seconds % 60;
	var h = Math.floor(minTotali / 60);
	var m = minTotali % 60;
	return h+"h "+m+"m "+s+"s";
}


 function getNavigator(categorization) {
   return categorization;
 }

 function loadVideo() {
 	var streamingServer="";
 		if (videoTv){
 			streamingServer='rtmpt://yalplive.alice.cdn.interbusiness.it:80/live/';
 		} else {
			streamingServer="rtmpt://yalpvod.alice.cdn.interbusiness.it/vod/";
		}

	var path = getPathName();
	var applicazione = path[1];
		if(applicazione == 'contenutipay'){
			playVideo(getCntTrailerFileUrl(), 'true', streamingServer, getCntTrailerDuration(),'0','0','0','0');
		}else{
			playVideo(getCntVideoFileUrl(), 'true', streamingServer, getCntDuration(),'0','0','0','0');
		}

 }

 var loadHtmlScheda=false;
 function loadScheda() {
		//alert("loadScheda _contentBean.contentId "+_contentBean.contentId);
 		/*if(_contentBean.contentId==0){
 			loadHtmlScheda=true;
 		}
		*/
 		//TODO getCntId
		//alert("loadScheda "+getCntId());
		enabledComment=true;
 		doCall_GetData(getCntId(), "viewVoteResponse");

		//doCall_GetData(getCntId(), "caricaValori","getValueScheda()");
 }

  function loadSchedaFruizione() {
		//alert("loadScheda _contentBean.contentId "+_contentBean.contentId);
 		/*if(_contentBean.contentId==0){
 			loadHtmlScheda=true;
 		}
		*/
 		//TODO getCntId
		//alert("loadScheda "+getCntId());
		enabledComment=true;
 		doCall_GetData(getCntId(), "setSchedaContentFruizione");

		//doCall_GetData(getCntId(), "caricaValori","getValueScheda()");
 }

function setSchedaContentFruizione(contentBean){

	document.getElementById("id_title1").innerHTML='<img src="http://images.yalp.alice.it/'+contentBean.imageFilePath+'"/> '+ contentBean.title;
	document.getElementById("id_categorization").innerHTML=contentBean.categorization;
	document.getElementById("id_title2").innerHTML=contentBean.title;
	document.getElementById("id_provider").innerHTML='da '+contentBean.providerName;
	document.getElementById("id_longdescription").innerHTML=contentBean.longDescription;
	document.getElementById("id_aggiunto").innerHTML=trunkDate(contentBean.startDate);
	document.getElementById("id_durata").innerHTML=getMinutesBySeconds(contentBean.duration);
	document.getElementById("id_visto").innerHTML=contentBean.viewCounter;
	document.getElementById("id_commentato").innerHTML=printStatistic(contentBean.commentCounter);
	document.getElementById("id_fonte").innerHTML=contentBean.providerName;
	document.getElementById("id_categoria2").innerHTML=contentBean.categorization;
	document.getElementById("id_lingua").innerHTML=contentBean.language;

	//Gestisco che keywords sia null, e se non lo fosse replico il tag <p>
	var keywords = contentBean.keywords;
	try{
		if(keywords.toString()!='[object Object]'){
			keywords = replaceAll(keywords,"<p>"," ");
			keywords = replaceAll(keywords,"</p>","");
		}else{
			keywords = "";
		}
	}catch(ex){
		keywords = "";
	}


	if(keywords != ""){
		var keys = keywords.split(',');
		var id_key="";
		for(i=0;i<keys.length;i++){
			id_key = id_key+'<li>'+keys[i];+'</li>';
		}
		document.getElementById("id_key").innerHTML=id_key;
	}else{
		document.getElementById("id_key").innerHTML=keywords;
	}

	var path = getPathName();
	var applicazione = path[1];

	var lnk="http://webtv.cubovision.it/"+path[1]+"/"+path[2]+"/"+path[3]+"/aa/"+contentBean.contentId+".html";
	document.getElementById("id_disponibilita").innerHTML='<span>Disponibile fino al </span>'+trunkDate(contentBean.stopDate);
	document.getElementById("id_regia").innerHTML=contentBean.directorList;
	var actor = replaceAll(contentBean.actorList,"#",", ");
	actor = replaceAll(actor,"<p>"," ");
	actor = replaceAll(actor,"</p>","");

	document.getElementById("id_cast").innerHTML=actor;
	document.getElementById("id_anno").innerHTML=contentBean.year;
	document.getElementById("id_genre").innerHTML=contentBean.genre;

	/*playVideo(contentBean.videoFileUrl, 'true', 'rtmpt://yalpvod.alice.cdn.interbusiness.it/vod/', contentBean.duration,'0','0','0','0');
	getRatingVoto("vote_"+contentBean.contentId, contentBean.voteTotal,contentBean.voteCountet);
	loadCommenti(getCntId(),0,contentBean.title,contentBean.longDescription,getCntLink());
	*/

	_contentBean=contentBean;
			//loadVideo();
			if (enabledComment){
				LivestatsClient.sendView(getCntId());
				loadCommenti(getCntId(),0,getCntTitle(),getCntDescription(),getCntLink());
			}

		getRatingVoto("vote_"+contentBean.contentId, contentBean.voteTotal,contentBean.voteCounter);
		try {
				document.getElementById("n_voti_scheda").innerHTML="("+contentBean.voteTotal+")";
				document.getElementById("n_mipiace_scheda").innerHTML=contentBean.likeCounter;
				document.getElementById("n_commenti_scheda").innerHTML=contentBean.commentCounter;
		} catch(ex){}
}

function viewVoteResponse(contentBean){

	if (_contentBean.contentId==0){
		//alert("viewVoteResponse: "+contentBean);
		setSchedaContent(contentBean);
	}
		var videoFileUrl;
		if (videoTv){
			contentBean.videoFileUrl=_contentBean.videoFileUrl
			//alert(_contentBean.videoFileUrl);
		}
	_contentBean=contentBean;
		loadVideo();
		if (enabledComment){
			LivestatsClient.sendView(getCntId());
			loadCommenti(getCntId(),0,getCntTitle(),getCntDescription(),getCntLink());
		}

	getRatingVoto("vote_"+contentBean.contentId, contentBean.voteTotal,contentBean.voteCounter);
	try {
			document.getElementById("n_voti_scheda").innerHTML="("+contentBean.voteTotal+")";
			document.getElementById("n_mipiace_scheda").innerHTML=contentBean.likeCounter;
			document.getElementById("n_commenti_scheda").innerHTML=contentBean.commentCounter;
	} catch(ex){}
}

function getPathName() {
	var url = window.location;
	var urlparts = url.pathname.split('/');
	return urlparts;
	//alert(urlparts[1] +url.pathname);
	//var host = url.host;
	//alert(host);
}


function setSchedaContent(contentBean){

	document.getElementById("id_categorization").innerHTML=contentBean.categorization;
	document.getElementById("id_title2").innerHTML=contentBean.title;
	document.getElementById("id_provider").innerHTML='da '+contentBean.providerName;
	document.getElementById("id_longdescription").innerHTML=contentBean.longDescription;
	document.getElementById("id_aggiunto").innerHTML=trunkDate(contentBean.startDate);
	document.getElementById("id_durata").innerHTML=getMinutesBySeconds(contentBean.duration);
	document.getElementById("id_visto").innerHTML=contentBean.viewCounter;
	document.getElementById("id_commentato").innerHTML=printStatistic(contentBean.commentCounter);
	document.getElementById("id_fonte").innerHTML=contentBean.providerName;
	document.getElementById("id_categoria2").innerHTML=contentBean.categorization;
	document.getElementById("id_lingua").innerHTML=contentBean.language;

	//Gestisco che keywords sia null, e se non lo fosse replico il tag <p>
	var keywords = contentBean.keywords;
	try{
		if(keywords.toString()!='[object Object]'){
			keywords = replaceAll(keywords,"<p>"," ");
			keywords = replaceAll(keywords,"</p>","");
		}else{
			keywords = "";
		}
	}catch(ex){
		keywords = "";
	}

	if(keywords != ""){
		var keys = keywords.split(',');
		var id_key="";
		for(i=0;i<keys.length;i++){
			id_key = id_key+'<li>'+keys[i];+'</li>';
		}
		document.getElementById("id_key").innerHTML=id_key;
	}else{
		document.getElementById("id_key").innerHTML=keywords;
	}


	var path = getPathName();
	var applicazione = path[1];

	if(applicazione == 'contenutipay'){
		document.getElementById("id_title1").innerHTML='<img src="http://images.yalp.alice.it/'+contentBean.imageFilePath+'"/> '+ contentBean.title;

		var lnk="http://webtv.cubovision.it/"+path[1]+"/"+path[2]+"/"+path[3]+"/aa/"+contentBean.contentId+".html";
		var fornitore_stat = '<a href="#" title="Nome Utente">';
		fornitore_stat = fornitore_stat + '<span class="foto"></span><img src="http://images.yalp.alice.it/'+contentBean.imageFilePath+'"/>';
		fornitore_stat = fornitore_stat + '<span>'+contentBean.major+'</script></a> <span>'+contentBean.categorization+'</span>';
		fornitore_stat = fornitore_stat + '<a href="#" title="www.urlcanale.com" class="urlc"></a> <p>Scritta Scritta Scritta Scritta Scritta</p>';
		fornitore_stat = fornitore_stat + '<div class="isc"><a href="'+lnk+'" class="pulsante" title="Compra"><span>Compra</span></a><strong>&euro; '+contentBean.defaultPrice+'</strong> PAY PER VIEW</div>';

		document.getElementById("fornitore_stat").innerHTML=fornitore_stat;
		document.getElementById("id_disponibilita").innerHTML='<span>Disponibile fino al </span>'+trunkDate(contentBean.stopDate);
		document.getElementById("id_video_prezzo").innerHTML='&euro; '+contentBean.defaultPrice+'<b>PAY PER VIEW</b><a href="'+lnk+'" class="pulsante" title="Compra"><span>Compra</span></a>';
		document.getElementById("id_regia").innerHTML=contentBean.directorList;
		var actor = replaceAll(contentBean.actorList,"#",", ");
		actor = replaceAll(actor,"<p>"," ");
		actor = replaceAll(actor,"</p>","");

		document.getElementById("id_cast").innerHTML=actor;
		document.getElementById("id_anno").innerHTML=contentBean.year;
		document.getElementById("id_genre").innerHTML=contentBean.genre;
	}else{
		document.getElementById("id_title1").innerHTML=contentBean.title;

		var id_utente_stat = 	'<a href="#" onclick=javascript:document.location.href="http://webtv.cubovision.it/'+getLinkVod(contentBean.categorizationra)+'" title="Nome Utente">';
			id_utente_stat = id_utente_stat + '<span class="foto"></span><img src="http://images.yalp.alice.it/'+contentBean.imageFilePath+'"/>';
			id_utente_stat = id_utente_stat + '<span>'+contentBean.title+'</script></a><span>'+contentBean.categorization+'</span>';
			id_utente_stat = id_utente_stat + '<a href="#" title="www.urlcanale.com" class="urlc"></a> <p></p>';
			id_utente_stat = id_utente_stat + '<div class="isc"><a href="#" class="pulsante" title="Iscriviti"><span>Iscriviti</span></a><strong>1234567 Iscritti</strong></div>';
			document.getElementById("utente_stat").innerHTML=id_utente_stat;
	}

	/*playVideo(contentBean.videoFileUrl, 'true', 'rtmpt://yalpvod.alice.cdn.interbusiness.it/vod/', contentBean.duration,'0','0','0','0');
	getRatingVoto("vote_"+contentBean.contentId, contentBean.voteTotal,contentBean.voteCountet);
	loadCommenti(getCntId(),0,contentBean.title,contentBean.longDescription,getCntLink());
	*/
}

function loadSchedaTV() {
		//alert(getCntVideoFileUrl());
		playVideo(getCntVideoFileUrl(), 'true', 'rtmpt://yalplive.alice.cdn.interbusiness.it:80/live/', '0','0','0','0','0');
		if (_contentBean.enabledComment){
			loadCommenti(getCntId(),0,getCntTitle(),getCntDescription(),getCntLink());
		}
 }

 function loadVideoHP() {
		loadVideo();
		doCall_GetData(getCntId(), "viewVoteResponse",getCntId());
 }

var fullPlaylist;
function loadVideoHPCommunity() {
		try{
			var lenCnt=cntCommunity.length;
			//alert(cntCommunity);
			for (var iCnt = 0; iCnt < lenCnt; iCnt++){
				if (iCnt==0){
					doCall_GetData(cntCommunity[iCnt], "viewCommunityResponse");
				} else {
					doCall_GetData(cntCommunity[iCnt], "viewCommunityResponseThumb");
				}
			}
		} catch(ex){}
		//loadVideo();
		//doCall_GetData(getCntId(), "viewVoteResponse",getCntId());
 }

function viewCommunityResponseThumb(contentBean) {
	document.getElementById("titolo_"+contentBean.contentId).innerHTML=contentBean.title;
	document.getElementById("categoria_"+contentBean.contentId).innerHTML=contentBean.categorization;
	document.getElementById("img_"+contentBean.contentId).src="http://images.yalp.alice.it"+contentBean.imageFilePath;
	getRatingVoto("vote_"+contentBean.contentId, contentBean.voteTotal,contentBean.voteCountet);
	//if (fullPlaylist){
 	//
 	//}
}

function viewCommunityResponse(contentBean){
 	document.getElementById("titolo_"+contentBean.contentId).innerHTML=contentBean.title;
 	try {
 		document.getElementById("descrizione_"+contentBean.contentId).innerHTML=contentBean.longDescription;
 	} catch(ex){}
 	//document.getElementById("n_mipiace_"+contentBean.contentId).innerHTML=contentBean.likeCounter;
 	document.getElementById("n_mipiace_scheda").innerHTML=contentBean.likeCounter;
 	//document.getElementById("n_voti_"+contentBean.contentId).innerHTML="(" +contentBean.voteTotal +")";
 	document.getElementById("n_voti_scheda").innerHTML="(" +contentBean.voteTotal +")";
 	getRatingVoto("vote_"+contentBean.contentId, contentBean.voteTotal,contentBean.voteCountet);
 	playVideo(contentBean.videoFileUrl, 'true', 'rtmpt://yalpvod.alice.cdn.interbusiness.it/vod/', contentBean.duration,'0','0','0','0');
 	if (fullPlaylist){
		 document.getElementById("duration").innerHTML=getMinutesBySeconds(contentBean.duration);
		 document.getElementById("viewCounter").innerHTML=contentBean.viewCounter;
		 document.getElementById("commentCounter").innerHTML=contentBean.commentCounter;
		 document.getElementById("categorization").innerHTML=contentBean.categorization;
		 document.getElementById("providerName").innerHTML=contentBean.providerName;
		 document.getElementById("keywords").innerHTML=contentBean.keywords;
		 document.getElementById("language").innerHTML=contentBean.language;
		 document.getElementById("startDate").innerHTML=trunkDate(contentBean.startDate);
		 document.getElementById("img_"+contentBean.contentId).src="http://images.yalp.alice.it"+contentBean.imageFilePath;
		 document.getElementById("categoria_"+contentBean.contentId).innerHTML=contentBean.categorization;
		 document.getElementById("titolo").innerHTML=contentBean.title;
 	} else {
 		document.getElementById("comment_"+contentBean.contentId).innerHTML="("+contentBean.commentCounter+")";
 	}
}

function loadVideoContenuto(){
    for(var i=0; i<cntCommunity.length; i++){
        var contentId = cntCommunity[i];
        doCall_GetData(contentId, "viewVideoContenuto");
    }
}

function viewVideoContenuto(contentBean){
     $("#titolo_"+contentBean.contentId).each(function(){
          $(this).html(contentBean.title);
     });

     $("#duration_"+contentBean.contentId).each(function(){
          $(this).html(formatOra(contentBean.duration));
     });

     $("#lastmodtime_"+contentBean.contentId).each(function(){
          $(this).html(formatDate(contentBean.lastModTime));
     });

     $("#img_src_"+contentBean.contentId+" img").each(function(){
          $(this).attr("src","http://images.yalp.alice.it"+contentBean.imageFilePath);
          $(this).attr("alt",contentBean.title);
     });

     $("#img_src_"+contentBean.contentId+" > a").each(function(){
          $(this).attr("href","http://www.cubovision.it/video/informazione/news/"+contentBean.contentId+".html");
     });

     $("#voto_"+contentBean.contentId).each(function(){
          getRatingVoto("voto_"+contentBean.contentId,contentBean.voteTotal,contentBean.voteCounter);
     });

     $("#titolo_sort_"+contentBean.contentId).each(function(){
          $(this).val(contentBean.title);
     });

     $("#duration_sort_"+contentBean.contentId).each(function(){
          var duration = contentBean.duration;
          while(duration.length<6){
              duration = "0"+duration;
          }
          $(this).val(duration);
     });

     $("#lastmodtime_sort_"+contentBean.contentId).each(function(){
          $(this).val(contentBean.lastModTime);
     });

     $("#href_"+contentBean.contentId).each(function(){
          var href = "http://webtv.cubovision.it/"

          //var hrefDir = contentBean.categorizationra.replace(/;/g,"/");

          var hrefDirArray = contentBean.categorizationra.split(";", 3);

          var hrefDir = "";
          for(var i=0; i<hrefDirArray.length; i++){
                hrefDir += hrefDirArray[i]+"/";
          }

          hrefDir = hrefDir.replace(/ /g,"_");

          href += hrefDir+contentBean.contentId+".html";

          href = href.toLowerCase();
          $(this).attr("href",href);
     });
}

var mapMesi = new Array();
mapMesi["01"] = "Gennaio";
mapMesi["02"] = "Febbraio";
mapMesi["03"] = "Marzo";
mapMesi["04"] = "Aprile";
mapMesi["05"] = "Maggio";
mapMesi["06"] = "Giugno";
mapMesi["07"] = "Luglio";
mapMesi["08"] = "Agosto";
mapMesi["09"] = "Settembre";
mapMesi["10"] = "Ottobre";
mapMesi["11"] = "Novembre";
mapMesi["12"] = "Dicembre";

function formatOra(stringOra){
    var ore = Math.floor(stringOra/60);
    var minuti = stringOra%60;
    if(minuti < 10){
        minuti = "0"+minuti;
    }
    return ore+":"+minuti+" min";
}

function formatDate(stringDate){
    var anno =  stringDate.substr(0 , 4);
    var mese = stringDate.substr(5 , 2);
    var giorno = stringDate.substr(8 , 2);

    return giorno+" "+mapMesi[mese]+" "+anno;
}

function getEventInfo(epgTV) {
            var plugin = document.getElementById("plugin");
            var json=eval("(" + epgTV+ ")");
            document.getElementById("titleVideo").innerHTML=json.Title;
            var desc=json.LongDescription;
            document.getElementById("descVideo").innerHTML=desc;
			$('#descVideo').truncatitle({limit:60});

}

//=================== CONDIVIDI CONTENUTO ==================//
$(document).ready(function() {
  if (($.browser.msie)) { //ie
			$('.intCond LABEL').click(function() {
				var lab = $(this);
				var inp = $(this).children('INPUT');
				if(!inp.is(':checked')){
					lab.css('background-position','-504px -55px');
					inp.attr('checked','checked'); //attivazione checkbox
				} else {
					lab.css('background-position','-504px -75px');
					inp.attr('checked',''); //disattivazione checkbox
				}

					condividiContenuto(	$(this).children('INPUT').val());
			});
		} else { //tutti gli altri browser
			$('.intCond LABEL').click(function() {
				var lab = $(this);
				var inp = $(this).children('INPUT').is(':checked');
				if(inp){
					lab.css('background-position','-504px -55px');
				} else {
					lab.css('background-position','-504px -75px');
				}

					condividiContenuto(	$(this).children('INPUT').val());
			});
		}

});
//=========================================================//
