$(document).ready(function ()
  {
    $('.calendar a').mouseover(
      function()
      {
        openwagenda(this);
      }
      );
      $('#wcalendarnum').mouseout(function(){
      $('#wcalendar').hide()
      });
  });

function openwagenda(elem)
{
  var pos=$(elem).parent().position();
  $('#wcalendarnum').html($(elem).parent().html());
  var query=$(elem).attr('href');
  query=query.replace('?q=agenda/view','?s=agenda/datos_agenda_json');
  $('#wcalendar').css('top', pos.top).css('left', pos.left);
  $.getJSON(query,function (datos)
  {
    createwagenda(datos);
    $('#wcalendar').css('visibility','visible').show('slow');
  });
}

function createwagenda(datos)
{
  var aux='';
  var ant=-1;
  for (elem in datos)
  {
    if (ant!=-1) aux+='<div class="wasep"></div>';
    ant=elem;
    aux+='<div class="watitle">'+datos[elem].nombre+'</div><div class="wahl"><span class="wahora">'+datos[elem].hora+'</span><br/>'+datos[elem].lugar+'</div>';
  }
  aux+='<div class="clear"></div>';
  $('#wcalendarelements').html(aux);
}

