
sfHover = function() {

		var sfEls = document.getElementById("main_menu").getElementsByTagName("LI");		
		
		sfEls[1].onmouseover=function() {
			this.className = "sfhover";
		}
		sfEls[1].onmouseout=function() {
			this.className = "";
		}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


function switchBox(whichShow, whichName, howMany){			
	for (var i=1;i<=howMany;i++){		
		whichTabHide = whichName + i + 'Tab';
		whichULHide = whichName + i;			
		if(document.getElementById(whichTabHide)!= null) document.getElementById(whichTabHide).className = 'off';
		document.getElementById(whichULHide).style.display = 'none';
	}
			
	whichTabShow = whichName + whichShow + 'Tab';
	whichULShow = whichName + whichShow;		
	document.getElementById(whichTabShow).className = 'on';
	document.getElementById(whichULShow).style.display = 'block';			
}

function switchBoxTab(whichShow, whichName, howMany){			
	for (var i=1;i<=howMany;i++){		
		whichTabHide = whichName + i + 'Tab';
		whichULHide = whichName + i;			
		if(document.getElementById(whichTabHide)!= null) document.getElementById(whichTabHide).className = 'off';
		document.getElementById(whichULHide).style.display = 'none';
	}
			
	whichTabShow = whichName + whichShow + 'Tab';
	whichULShow = whichName + whichShow;		
	document.getElementById(whichTabShow).className = 'on';
	document.getElementById(whichULShow).style.display = 'block';			
}		
		
function switchStaserasusky(which){			
	showTab 	= 'staseraTab' + which;
	showPanel 	= 'staseraPanel' + which;			
	
	for (var i=0;i<=5;i++){				
		hideTab 	= 'staseraTab' + i;
		hidePanel 	= 'staseraPanel' + i;
		
		document.getElementById(hideTab).className = 'off';
		document.getElementById(hidePanel).style.display = 'none';
	}		
		
	document.getElementById(showTab).className = 'on';
	document.getElementById(showPanel).style.display = 'block';	
	
	var key = document.getElementById(showTab).getElementsByTagName("a")[0].innerHTML;
	key = key.replace(/ /g, "");
	var url = "http://guidatv.sky.it/guidatv/HP/questasera/"+key.toLowerCase();
	nielsenRefresh(url);
}
		
		
function showFilter(which){	
	document.getElementById(which).style.display = 'block';
}
		
function closePopup(which){		
	document.getElementById(which).style.display = 'none';
}

var posX = 0;
var posY = 0;

jQuery(document).ready(function(){
	$("#main").click(function(e){	
		posX = e.pageX;
		posY = e.pageY;
	});   
})

function openAlert(which){	
	if (which.indexOf('memotv')>-1){
		myPosX = posX - 147;				
		myPosY = posY + 10;
	}
	
	if (which.indexOf('crearegola')>-1){
		myPosX = posX - 120;				
		myPosY = posY + 10;
	}
	
	if (which.indexOf('modificaregola')>-1){
		myPosX = posX - 229;				
		myPosY = posY + 10;
	}
	
	if(which.indexOf('miaguida')>-1){		
		myPosX = "768";
		myPosY = "30";		
	}
	
	if (which.indexOf('add')>-1){
		myPosX = posX - 97;		
		myPosY = posY + 10;
	} 
	
	if (which.indexOf('rec')>-1){
		if (which == 'rec'){
			myPosX = posX - 286;		
			myPosY = posY + 10;
		}else{
			myPosX = posX - 147;		
			myPosY = posY + 10;
			}
	}
		
	myPosX = myPosX+'px';	
	myPosY = myPosY+'px';
	
	if (document.getElementById(which)!=null) {	
	document.getElementById(which).style.display='block';	
	document.getElementById(which).style.left = myPosX;		
	document.getElementById(which).style.top = myPosY;		
	}
}



function close_layers() {
	if (document.getElementById("memotv")!=null) document.getElementById("memotv").style.display='none';	
	if (document.getElementById("rec")!=null) document.getElementById("rec").style.display='none';
	if (document.getElementById("add")!=null) document.getElementById("add").style.display='none';
	if (document.getElementById("miaguida1")!=null) document.getElementById("miaguida1").style.display='none';
}

function starSort(myStar) {
	if (document.getElementById(myStar).className == "star off") document.getElementById(myStar).className = "star on";
		else document.getElementById(myStar).className = "star off";
}

function isUserLogged(){
	// check the existence of PETERWITT cookie
	return (document.cookie.search("PETERWITT")!=-1);
}

function load_programmazione(idprogramma){

	var html_loader = "<p><img src=\"http://static.sky.it/static/images/sito/epg/loadingAnimationBlack.gif\"/></p>";
	$(".programmazione1").html(html_loader);
	$(".prog").html(html_loader);
  jQuery.ajax({
      url: "/EpgBackend/getprogrammazione.do?idprogramma="+idprogramma,
      dataType : 'json',
      data : {},
      success : function(data, textStatus){
        show_programmazione(data);
      },
      error : function(x, txt, e){
        $("#content2 h3").remove();
        $("#content2 .testo").html('Programmazione non disponibile.');
        $(".programmazione1").html('');
        $(".prog").html("Programmazione non disponibile");
      }
  });
  jQuery.ajax({
      url: "/EpgBackend/getpvodprog.do?idprogramma="+idprogramma,
      dataType : 'html',
      data : {},
      success : function(data, textStatus){
      	if(data=="1")
        	$("#ssel").html("<a href=\"http://guidatv.sky.it/guidatv/skyselection.html\"><img style=\"position: absolute; top: 10px; right: 20px; height: 37px; width: 150px;\" src=\"http://static.sky.it/static/images/sito/epg/pvod_logo_prog.gif\"></a>");
      },
      error : function(x, txt, e){
        $("#content2 h3").remove();
        $("#content2 .testo").html('Programmazione non disponibile.');
        $(".programmazione1").html('');
        $(".prog").html("Programmazione non disponibile");
      }
  });
}

function myswitch(a, b, c, d){
	if(a==1){
			document.getElementById('div_bookmarks').style.display = 'block';
	}
	else{
			document.getElementById('div_bookmarks').style.display = 'none';
	}

	var l = window.location.toString();
	if(a == 2) {
			var i = l.lastIndexOf("/");
			l = l.substring(0,i)+"/programmazione"+l.substring(i);
	}
	else if(a>2)
	{
		if(d=='mor'){
			var i = l.lastIndexOf("/");
			l = l.substring(0,i)+"/morandini"+l.substring(i);
		}
		else
		{
			var i = l.lastIndexOf("/");
			l = l.substring(0,i)+"/colonnasonora"+l.substring(i);
		}
	}

	var url = l.toString().split("?")[0];
	nielsenRefresh(url);

	switchBox(a,b,c);
}

function initSuskyInreteMiaguida(){
	document.getElementById('div_susky_inrete_spalla').innerHTML = document.getElementById('div_susky_inrete_nascosto').innerHTML;
			
	if (document.getElementById('div_spalla_tisuggeriamo')){
		$.ajax({
		  url: "/EpgBackend/wesuggest.do",
		  data: "pid="+pid,
		  cache: true,
		  success: function(html){
			if(html.length!=0){
				document.getElementById('div_spalla_tisuggeriamo').innerHTML = html;
					initialize_baloons();
				}
				else if(!isUserLogged()){
					$('.brickMenu').css({display : 'none'});
					$('.brick').css({display : 'none'});
				}
				else
				{
					$('#brick1').css({display : 'none'});
				}
		  }
		});
	}
	
	if(isUserLogged()){
		if (document.getElementById('div_spalla_miaguida')){
			$.ajax({
			  url: "/EpgBackend/myguide/search.do",
			  data: "by=events",
			  cache: false,
			  success: function(html){
				document.getElementById('div_spalla_miaguida').innerHTML = html;
				document.getElementById('brick2Tab').style.display = 'block';
				//document.getElementById('brick2').style.display = 'block';
			  }
			});
		}
	}
}