new Event.observe(window, 'load', init);

var freakngallery;
var inputOver = false;
var version = 0;
function init() {
  freakngallery = new freaknGallery();
  replaceInput();
  replaceAnchor();
  fixPngTransparency();
  
  version = deconcept.SWFObjectUtil.getPlayerVersion();
  
  if (typeof initLayoutFlash == 'function') initLayoutFlash();
  if (typeof initFlash == 'function') initFlash();
  if (typeof initExtraFlash == 'function') initExtraFlash();
}

function loadFlash(so, element) {
  if (version['major'] < 8) {
    $(element).update('<center>Votre navigateur ne possède pas le lecteur Flash ou sa dernière version, pour l\'installer, rendez-vous à la page de téléchargement en cliquant <a href=\"http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash&Lang=French\" title=\"Télécharger Flash\">ici</a></center>');
  } else {
    so.write(element);
  } 
}

function replaceAnchor() {
  $$('a[href*="#"]').each(function(anchor){
    if (anchor.className == 'anchor') {
      new Event.observe(anchor, 'click', function(event) {
        var scrollingDiv = window;
        var div          = this.href.split('#')[1];
        var pageAnchor   = $(div);
        var delta        = pageAnchor.offsetTop - scrollingDiv.scrollTop;
        var updateUrl    = function() { location.href = this.href }.bind(this);
  
        new Effect.ScrollTo(div, { y: delta, afterFinish: updateUrl, duration: 0.3 });
        Event.stop(event);
      });
    }
  });
}

function replaceInput() {
  $$('input[type*="text"]', 'textarea').each(function(input){
    if (input.getStyle('backgroundColor') == "rgb(250, 231, 217)") {
      new Event.observe(input, 'mouseover', function(event) {
        input.setStyle({backgroundColor: "rgb(255, 218, 191)"}); inputOver = true;
      });
      new Event.observe(input, 'mouseout', function(event) {
        input.setStyle({backgroundColor: "rgb(250, 231, 217)"}); inputOver = false;
      });
      new Event.observe(input, 'focus', function(event) {
        input.setStyle({backgroundColor: "rgb(255, 218, 191)"}); inputOver = true;
      });
      new Event.observe(input, 'blur', function(event) {
        input.setStyle({backgroundColor: "rgb(250, 231, 217)"}); inputOver = false;
      });
    }
  });
}