var Canvas = {
  initialize: function() {
    this.wrapper      = $('wrapper');
    this.canvas       = $('firstcanvas');
    if ($('secondcanvas')) {
      this.secondcanvas = $('secondcanvas');            
    }
    this.entrance     = $('entrance');
    this.logo         = $('logo');
    this.legal        = $('legal');
    this.shadowRight  = $('fcshadowright');
    this.shadowBottom = $('fcshadowbottom');
    this.resize();
  },
  resize: function() {
    var offsetTopCanvas = this.wrapper.offsetHeight/2 - this.canvas.getHeight()/2;    
    this.canvas.setStyle({'margin-top': offsetTopCanvas+'px'});

    if (this.secondcanvas) {
      var offsetRightFirstCanvas = this.wrapper.offsetWidth/2 - this.canvas.getWidth();
      this.secondcanvas.setStyle({'margin-top': offsetTopCanvas+'px'});
      this.secondcanvas.setStyle({'margin-left': offsetRightFirstCanvas+'px'});      
    }

    this.legal.setStyle({'margin-top': (offsetTopCanvas+518)+'px'});
    this.logo.setStyle({'margin-top': (offsetTopCanvas-53)+'px'});
    
    if(!Site.overflow) {
      this.legal.setStyle({
        'left': Position.cumulativeOffset(this.canvas)[0]+640+'px',
        'position': 'absolute'
      });
      this.logo.setStyle({
        'left': Position.cumulativeOffset(this.canvas)[0]+37+'px'
      });
    }
    this.wrapper.forceRerendering();
  }
}

Event.observe(window, 'load', Canvas.initialize.bind(Canvas));
Event.observe(window, 'resize', Canvas.resize.bind(Canvas));


Position.getPageSize = function() {
  var xScroll, yScroll;

  if (window.scrollMaxX) {  
    xScroll = window.innerWidth  + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else {
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } 

  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  pageHeight = Math.max(windowHeight, yScroll);

  // for small pages with total width less then width of the viewport
  pageWidth = Math.max(windowWidth, xScroll);

  return { page: { width: pageWidth, height: pageHeight }, window: { width: windowWidth, height: windowHeight } };
}

Event.observe(window, 'load', function() {
  var opacity = Prototype.Browser.IE ? 1 : 0.999;
  $('wrapper').setOpacity(opacity);
  $('logo').setOpacity(opacity);
});


 
