
window.currentClient = 'elliot';
window.currentProject = 'identite-visuelle';

function init() {
}

function resizeBackground(resizeOnly) {

  // Trouve la largeur et la hauteur de l'ecran;
  var windowHeight = getWindowHeight();
  var windowWidth = getWindowWidth();
  
  // Trouve la hauteur, la largeur et le ratio de l'image originalement
  var image = $$('#backgroundImageBox img')[0];
  var imageHeight = 1200;
  var imageWidth  = 1600;
  var imageRatio = imageHeight/imageWidth;
  
  // Resize et repositionne l'image en conséquence
  
  var imageBox = $('backgroundImageBox');

  if ( (windowWidth <= 1020) && (windowHeight<=690) ) {
    imageWidth = 1020;
    imageHeight = 1020*imageRatio;
    
  } else {
    
    if ( windowWidth > windowHeight ) {
      imageHeight = windowWidth*imageRatio;
      imageWidth = windowWidth;
      if (imageHeight < windowHeight) {
        imageHeight = windowHeight;
        imageWidth = windowHeight * (1/imageRatio);
      }
    
    } else {
      imageWidth = windowHeight * (1/imageRatio);
      imageHeight = windowHeight;
      if (imageWidth < windowWidth) {
        imageWidth = windowWidth;
        imageHeight = windowWidth * imageRatio;
      }
    }
    
  }

  image.setStyle({width: imageWidth+'px',
                  height: imageHeight+'px'});
  
  imageBox.setStyle({top: '50%', left: '50%',
                     marginLeft: -(imageWidth/2)+'px',
                     marginTop: -(imageHeight/2)+'px',
                     visibility: 'visible'});

  if ( !resizeOnly ) {
    imageBox.setStyle({display: 'none'});
    Event.observe(image, 'load', function () { imageBox.appear({ duration: 0.4 }); });
  }
}

/** *** TOOLS ***** */

function getWindowHeight() {

    var windowHeight = 0;

    if (typeof(window.innerHeight)=='number') {
        windowHeight = window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    
    return windowHeight;
}

function getWindowWidth() {

    var windowWidth = 0;

    if (typeof(window.innerWidth)=='number') {
        windowWidth = window.innerWidth;
    } else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            if (document.body && document.body.clientWidth) {
                windowWidth = document.body.clientWidth;
            }
        }
    }
    
    return windowWidth;
}
