function Calendar( begin, end )
{
  this.getDateByString = function( string )
  {
    var re = /([0-9]{2})\/([0-9]{2})\/([0-9]{4})/;
    var date = new Date();
    
    date.setFullYear( string.replace( re, "$3" ) );
    date.setMonth( string.replace( re, "$2" ) - 1 );
    date.setDate( string.replace( re, "$1" ) );
    
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    
    return date;
  }
  
  this.begin = this.getDateByString( begin );
  this.end = this.getDateByString( end );
  this.days = new Array();
  this.links = new Array();
  this.today = null;
  this.itensPerPage = 6;
 
  this.setToday = function( date )
  {
    var today = this.getDateByString( date );
    if( today >= this.begin && today <= this.end )
    {
      this.today = today;
    }
    else
    {
      this.today = this.end;
    }
  }

  this.addDay = function( date )
  {
    var day = new Dia( date.getDate(), date.getMonth() + 1 )
    this.days.push( day );
    day.show();
    if( day.link != null )
    {
      this.links[ day.link ] = day;
    }    
  }

  this.setDays = function()
  {
    var date = new Date( this.begin.getTime() );
    
    var end = new Date( this.end.getTime() + 1000*60*60*24 );
    var day = new Object();
    var firstDay = new Date( this.today.getTime() - 1000*60*60*24*this.itensPerPage );
    
    // Monta os dias a partir do dia anterior até o final
    for( date = new Date( firstDay.getTime() ); date.getTime() <= end.getTime(); date.setTime( date.getTime() + 1000*60*60*24 ) )
    {
      this.addDay( date );
    }
    // Monta dias desde o início até 1 dia antes do primeiro dia exibido
    for( date = new Date( this.begin.getTime() ); date.getTime() < firstDay; date.setTime( date.getTime() + 1000*60*60*24 ) )
    {
      this.addDay( date );
    }
  }
  
  this.make = function( todayDate )
  {
    this.setToday( todayDate );
    this.setDays();
  }
}
