var timetables = 
{
  disabledClassName : 'disabled',
  
  /**
   * init
   */
  init : function()
  {
    //set event listeners
    timetables.setEventListeners();
  },
  
  
  /**
   * init eventlisteners
   */
  setEventListeners : function()
  {
    //themes filter checkbox click
    $$('#filters #themes input').each(function(obj) { obj.observe('click', function(){ timetables.resetThemes(); }, false); });
    
    //days filter checkbox click
    $$('#filters #days input').each(function(obj) { obj.observe('click', function(){ timetables.resetDays(); }, false); });
  },
  
  
  /**
   * reset days
   */
  resetDays : function()
  {
    var checkedDays = $$('#filters #days input:checked');
    
    //hide all acts
    var allDays = $$('.filter-day');     
    if(allDays)
      allDays.each(function(obj) { obj.hide(); });
    
    //only display the selected days
    checkedDays.each(function(obj)
    {
      var dayIndex = obj.value;      
      var days = $$('.day-' + dayIndex);
      
      if(days)
        days.each(function(obj) { obj.show(); } );
    });
  },
  
  
  /**
   * reset themes (acts + events)
   */
  resetThemes : function()
  {
    var checkedThemes = $$('#filters #themes input:checked');
    
    //hide all acts and events
    var allActsAndEvents = $$('.filter-act, .filter-event');
    if(allActsAndEvents) allActsAndEvents.each(function(obj)
    {
      obj.addClassName(timetables.disabledClassName);
    });
    
    //only display the acts with the selected themes
    checkedThemes.each(function(obj)
    {
      var themeIndex = obj.value;
      
      if(themeIndex == 'events')
      {
        var events = $$('.theme-event');
        
        if(events)
        {
          events.each(function(obj)
          {
            //obj.show();
            obj.removeClassName(timetables.disabledClassName);
          });
        }
      }
      else
      {
        var acts = $$('.theme-' + themeIndex);
        
        if(acts)
        {
          acts.each(function(obj)
          {
            //obj.show();
            obj.removeClassName(timetables.disabledClassName);
          });
        }
      }
    });
  }
};

//on dom loaded
document.observe('dom:loaded', function() { timetables.init(); }, false);
