/**
 * Klasa Page musi zapewnić obsługę danej witryny, chcemy tutaj zawrzeć całą charakterystykę zmian zachodzących na stronie
 * Docelowa witryna powinna stworzyć swoją klasę rozszerzającą klasę Page, utworzyć jej instancję i podać do PageUpdater'a
 */
var Page = new Class(
{
  indicatorElement: null,
  injectIndicator: function()
  {
    this.indicatorElement = new Element( 'p',
                      { 'id': 'indicator',
                        'html': '<br />Wczytuję treść...'
                      });
    (new Element( 'img', { src: '/images/nggear_indicator.gif' } )).inject( this.indicatorElement, 'top');

    var colTwo = document.id( 'colTwo' );
    this.indicatorElement.inject( colTwo, 'top' );
  },
  showIndicator: function()
  {
    document.id( 'colTwo' ).getElement( 'div.content' ).empty();
    this.indicatorElement.setStyle( 'display', 'block' );
  },
  hideIndicator: function()
  {
    this.indicatorElement.setStyle( 'display', 'none');
  },
  update: function( data )
  {
    if( data.threeCol )
      this.switchToThreeCols();
    else
      this.switchToTwoCols();

    this.updateSlots( data.content );
  },
  updateSlots: function( slotsContent )
  {
    document.id( 'menu' ).setProperty( 'html', slotsContent.menu );
    document.id( 'colTwo' ).getElement( 'div.content' ).setProperty( 'html', slotsContent.content );
    document.id( 'colOne' ).setProperty( 'html', slotsContent.colOne );
    var colThree = document.id( 'colThree' );
    if( colThree )
      colThree.setProperty( 'html', slotsContent.threeCol );
  },
  switchToThreeCols: function()
  {
    var colTwo = document.id( 'colTwo' );
    colTwo.removeClass( 'onlyTwo' );
    document.id( 'pagewrap' ).removeClass( 'onlyTwo' );

    if( !document.id( 'colThree' ) )
      new Element( 'div',{ 'id': 'colThree' } ).injectAfter( colTwo );
  },
  switchToTwoCols: function()
  {
    var colThree = document.id( 'colThree' );
    if( colThree )
      colThree.destroy();
    document.id( 'colTwo' ).addClass( 'onlyTwo' );
    document.id( 'pagewrap' ).addClass( 'onlyTwo' );
  }
});
