 

function wrap_span(id)
{
  $('#'+id+' table.ui-datepicker-calendar td.ui-datepicker-unselectable.ui-state-disabled:not(:has(span))').each(function(i)
  {
    $(this).html('<span>'+$(this).html()+'</span>');
  })
};

function format_datepicker()
{     
  wrap_span('ui-datepicker-div'); 
  $('#ui-datepicker-div').css({'background-color':'white','border':'2px solid #BBC77B'});
  $('#ui-datepicker-div').css({'padding-top':'0px'});
}   


var window_load=true; 

$(function()
{              
    //eventos para o calendário    
    var bindDatepickerEvents=function()
    {
      $('div#hp_calendar table.ui-datepicker-calendar a').hover(function()
          {
            $(this).addClass('ui-state-hover');
          },
          function()
          {
            $(this).removeClass('ui-state-hover');
          });
      
      $('div#hp_calendar a.ui-datepicker-next').hover(function()
          {
            $(this).addClass('ui-state-hover').addClass('ui-datepicker-next-hover');
          },
          function()
          {
            $(this).removeClass('ui-state-hover').removeClass('ui-datepicker-next-hover');
          });
      
      $('div#hp_calendar a.ui-datepicker-prev').hover(function()
          {
            $(this).addClass('ui-state-hover').addClass('ui-datepicker-next-hover');
          },
          function()
          {
            $(this).removeClass('ui-state-hover').removeClass('ui-datepicker-next-hover');
          });
          
      
      //tooltips para o calendário
      $("div#hp_calendar table.ui-datepicker-calendar td.userEvent a, \
        div#hp_calendar table.ui-datepicker-calendar td.dayEvent a").tooltip(
      { 
          bodyHandler: function() 
          { 
              id='#tooltip_'+$(this).attr("id").split('_')[1];//alert(id);
              if($(id).exists())
                return $(id).html();
              else
                return false;             
          }, 
          showURL: false 
      });
    };
    
    bindDatepickerEvents();
    
    var calendar_loading=$('<img id="calendar_loading" src="/media/images/facebox/loading.gif"/>');
    var getMonth=function(month,year)
    {
      req={};
      req.month=month;
      req.year=year; 
      $.ajax(
      {
  			type:'POST',
        url:'/?p=index:getMonth',
  			data:req,
  			beforeSend:function()
        {
          //calendar_loading.appendTo('#hp_calendar');
        },  			
  			success:function(data)
  			{			   			                 
          $('#hp_calendar').html(data); 
          bindDatepickerEvents();   
          pageTracker._trackPageview('/?p=index:getMonth');
        }
      });
    }
    
    $('div#hp_calendar a.ui-datepicker-next').livequery('click',function()
    {
      var month=$(this).attr('id').split('_')[1];
      var year=$(this).attr('id').split('_')[2];
      getMonth(month,year);
      return false;
    });
    
    $('div#hp_calendar a.ui-datepicker-prev').livequery('click',function()
    {
      var month=$(this).attr('id').split('_')[1];
      var year=$(this).attr('id').split('_')[2];
      getMonth(month,year);
      return false;
    });        
    
    //fim dos eventos do calendário
    
    
    
    
    $('.party_item').hover(
              function(){
                $(this).addClass('party_item_over');
              },
              function(){
                $(this).removeClass('party_item_over');
              });
              
    $('.input_submit').hover(
          function()
          {
            $(this).removeClass('input_submit');
            $(this).addClass('input_submit_hover');
          },
          function(){
            $(this).removeClass('input_submit_hover');
            $(this).addClass('input_submit');
          });
    //Pesquisa rápida (start)
    var initial_value=$('#quick_search_keyword').val();
    $('#quick_search_keyword,#advanced_search_keyword').click(function()
    {
      if($(this).val()==initial_value)
        $(this).val('');
    });
    $('#quick_search_keyword,#advanced_search_keyword').blur(function()
    {
      if($(this).val()=='')
        $(this).val(initial_value);
    });
    
    $("#quick_search_form").submit(function()
    {
      if($('#quick_search_keyword').val()==initial_value)
        $('#quick_search_keyword').attr("disabled", true); 
    });
    
    if(gup('search_type')!='') //mostra o formulario correspondente
    {
      $("#quick_search_form input[type=radio]").each(function()
      {
        if($(this).val()==gup('search_type'))
          $(this).attr('checked',true);
        else
          $(this).removeAttr('checked');
      });
    }
    //Pesquisa rápida (end)
});