// -----------------------------------------------------------------------------
// Class: DateBlock
// Description: Essentially, a group of EventBlocks underneith a date banner
// -----------------------------------------------------------------------------
var DateBlock = Class.create();
DateBlock.prototype = {
  
  EVEN_ODD_CLASSES: ['even', 'odd'],
  
  // -------------------------------------------------------------- initialize
  initialize: function(datestamp, events)
  {
    
    this.even_odd_index = 1;
    
    this.events = [];
    this.event_objects = events;
    this.count  = events.length;
    this.setDateStamp( datestamp ); 
    datestamp = new String( datestamp ); 
    var year = datestamp.substring(0,4);
    var month = datestamp.substring(4,6);
    var day = datestamp.substring(6);
    var date       = new Date( year, month - 1, day );
    this.title     = WEEKDAYS[date.getDay()]+', '+MONTHS[date.getMonth()]+' '+ day +', ' + year;
    
    this.block  = this.getBlock();
  },
  // -------------------------------------------------------------- setDateStamp
  setDateStamp: function(d)
  {
    this.datestamp = d;
  },
  // -------------------------------------------------------------- getDateStamp
  getDateStamp: function( )
  {
    return this.datestamp;
  },
  // -------------------------------------------------------------------------
  // CONSTRUCTOR METHODS -----------------------------------------------------
  // ---------------------------------------------------------------- getBlock
  getBlock: function()
  {
    var div = $C('div');
    div.addClassName('date_block');
    div.addClassName('clearfix');
    div.appendChild( this.getHeader() );
    
    for (var i = 0; i < this.count; i++)
    {
      this.events[i] = new EventBlock(this, this.event_objects[i]);
      div.appendChild( this.events[i].block );
    }
    
    return div;
  },
  
  // --------------------------------------------------------------- getHeader
  getHeader: function()
  {
    var div = $C('div');
    div.addClassName('date_header');
    
    div.appendChild( $T(this.title) );
    return div;
  },
  // --------------------------------------------------------------- getRowClass
  getRowClass: function()
  {
    this.even_odd_index = (this.even_odd_index+1)%this.EVEN_ODD_CLASSES.length
    return this.EVEN_ODD_CLASSES[this.even_odd_index];
  }
  
};
