function escriu(titol)
{  td = document.getElementById('Que');
   td.innerHTML = titol;
}

var intervalVis = 3000; 
var intervalGlo = 500; 
var intervalOcu = 300; 
var stopNedo = 0;

function mostraNedo(a,b) {
	if (stopNedo == 1)
		setTimeout('mostraNedo(\''+ a +'\',' + b + ')',intervalOcu);
	else {
		oNedo = document.getElementById('nedo');
		switch (a) {	
			case 'v': //nedo visible
				switch (b) {
					case 0:
	        	oNedo.style.top= '30px';
            oNedo.style.left= '30px';
			     	prox = 1;
			   		break;
		     	case 1:
	          oNedo.style.top= '400px';
            oNedo.style.left= '30px';
			     	prox = 2;
			   		break;
		     	case 2:
	          oNedo.style.top= '30px';
            oNedo.style.left= (document.body.clientWidth - 120) + 'px';
			     	prox = 3;
			   		break;
		     	case 3:
	          oNedo.style.top= '400px';
            oNedo.style.left= (document.body.clientWidth - 120) + 'px';
			   		break;
				}
				oNedo.style.visibility = 'visible';
				oNedo.style.display = '';
				setTimeout('mostraNedo(\'g\',' + b + ')',intervalGlo);
      	break;
	  case 'g': //globus visible
	  		switch (b) {
					case 0:
	        	retol = 'Hola!';
		   	   	prox = 1;
			   		break;
		     	case 1:
	          retol = 'Com va?';
		   	   	prox = 2;
			   		break;
		     	case 2:
	          retol = 'Saps qui sóc?';
		   	   	prox = 3;
			   		break;
		     	case 3:
	          retol = 'Endevina-ho!';
		   	   	prox = 0;
			   		break;
				}
				mostraGlobus(retol);
	      setTimeout('mostraNedo(\'n\',' + prox + ')',intervalVis);
	  	break;
	  case 'n': //globus invisible
	    mostraGlobus('');
      setTimeout('mostraNedo(\'i\',' + b + ')',intervalGlo);
	  	break;
	  default:  //nedo invisible
    	oNedo.style.visibility = 'hidden';
      oNedo.style.display = 'none';
		  mostraGlobus('');
      setTimeout('mostraNedo(\'v\',' + b + ')',intervalOcu);
	  	break;
		}
	}
}

function mostraGlobus(retol)
{  oNedo = document.getElementById('nedo');
   oGlobus = document.getElementById('globus');
   oGlobus_retol = document.getElementById('globus_retol');
   oGlobus_retol.innerHTML = retol;
   if (retol != '')
   {  
      if (parseInt(oNedo.style.left) < (parseInt(document.body.clientWidth) / 2))
      {  oGlobus.style.backgroundImage='url(gifs/globus_esq.gif)';
	     oGlobus.style.left = (parseInt(oNedo.style.left) + parseInt(oNedo.style.width)) + 'px';
	  }
	  else
	  {	 oGlobus.style.backgroundImage='url(gifs/globus_dre.gif)';
		 oGlobus.style.left = (parseInt(oNedo.style.left) - parseInt(oGlobus.style.width)) + 'px';
	  }
	  oGlobus.style.top = (parseInt(oNedo.style.top) - 25) + 'px';   
      oGlobus.style.visibility = 'visible';
      oGlobus.style.display = '';      
   } else 
   {   oGlobus.style.visibility = 'hidden';
       oGlobus.style.display = 'none';
   }
}
