var abierto = false;
document.observe('lightview:opened', function(event)
{
  abierto = true;
  var ns = $('ns');
  new Ajax.Request('jugando/'+ns.innerHTML+'.html', {
    method: 'post',       
    parameters: 'j=1',
  onSuccess: function(r) {
		$('publi_juego').hide();
		$('contenido_publi').hide();
  }
}); 
});

document.observe('lightview:hidden', function(event)
{
  abierto = false;  
  var ns = $('ns');
  new Ajax.Request('jugando/'+ns.innerHTML+'.html', {
    method: 'post',
    asynchronous: false,
    parameters: 'j=0',
  onSuccess: function(r) {
		$('publi_juego').show();
		$('contenido_publi').show();	
  }
});  
});

/*starb*/
function starClicked(element, info) {
  var indicator = element.down('.indicator');
  var restore = indicator.innerHTML;
  indicator.update('Gracias por votar');
  window.setTimeout(function() { indicator.update(restore) }, 2000);
  new Effect.Highlight(indicator);
  
  var ns = $('ns');
  new Ajax.Request('vota/'+ns.innerHTML+'.html', {
    method: 'post',    
    parameters: 'n='+info.rated.toFixed(2),
  onSuccess: function(r) {
  }
});
}

function tal(h,c,f)
{
	w1 = new UI.Window({theme: 'bluelighting', resizable: true, draggable: false, width: 600, height:10, top:10, left:10 }).show();
	w1.setHeader('<h1>'+h+'</h1>');
	w1.setContent('<p>'+c+'</p>');
	w1.setFooter(f);
	w1.adapt.bind(w1).delay(0);
	w1.center({auto: true});	
}
   
function fav(acc)
{
	var ns = $('ns');
	var fav = $('fav');

	var m = 'Juego agregado a Favoritos';
	new Effect.Highlight(fav);

	if (acc=='e'){m='Juego borrado de Favoritos';}
	fav.innerHTML = m;
  new Ajax.Request('favorito/'+ns.innerHTML+'.html', {
    method: 'post',    
    parameters: 'a='+acc,
  onSuccess: function(r) {
  }
});
}

function comentar()
{
	var ns = $('ns');
	var com = $F('comentario_txt');
	
	if (com.empty())
	{
		alert("Chico, escribe algo");
	}
	else
	{
		var nuevo = $('nuevo_com');
    new Ajax.Request('comentar/'+ns.innerHTML+'.html', {
      method: 'post',    
      parameters: 'c='+com,
			onCreate: function() {			 
       $('titulo_comentario', 'comentario_txt', 'btn_comentar').invoke('hide'); 
			 Element.show('loading');
        },
    onSuccess: function(r) {
			new Effect.Highlight(nuevo);
			Element.hide('loading');
      nuevo.innerHTML = r.responseText;
    }
    });
	}
}

window.onload = pestanas;
function pestanas()
{
	var a1 = $('a1');
	var a2 = $('a2');
	var a3 = $('a3');
	a1.onclick = function ()
	{
		cambiaPestana(1);
		return false;
	}
	a2.onclick = function ()
  {
    cambiaPestana(2);
    return false;
  }
	a3.onclick = function ()
  {
    cambiaPestana(3);
    return false;
  }
}

function cambiaPestana(p)
{
	var l1 = $('l1');
	var l2 = $('l2');
	var l3 = $('l3');
	var d1 = $('d1');
	var d2 = $('d2');
	var d3 = $('d3');	
	var a1 = $('a1');
  var a2 = $('a2');
  var a3 = $('a3'); 
	
	switch (p)
	{
		case 1:
		  l1.className = "recordsActivo";
			l2.className = "comentariosPasivo";
			l3.className = "otrosJuegosPasivo";
			d1.className = "";
			d2.className = "invisible";
			d3.className = "invisible";		
			
		  break;
		case 2:
		  l1.className = "recordsPasivo";
			l2.className = "comentariosActivo";
      l3.className = "otrosJuegosPasivo";
      d1.className = "invisible";
      d2.className = "";
      d3.className = "invisible";			
		  break;
		case 3:
		  l1.className = "recordsPasivo";
			l2.className = "comentariosPasivo";
      l3.className = "otrosJuegosActivo";
      d1.className = "invisible";
      d2.className = "invisible";
      d3.className = "";						
		  break;
	}
}

function pagerPuntuaciones(pagina)
{

  var ns = $('ns'); 
  var listaPuntuaciones = $('listaPuntuaciones');
  var paginas = $('paginas');
  new Effect.Highlight(listaPuntuaciones);  
  new Ajax.Request('/juegos/puntuaciones/'+ns.innerHTML+'/'+pagina+'.html', {
    method: 'post',
  onSuccess: function(r) {
      listaPuntuaciones.innerHTML = r.responseText;
  }
});
}



