// 25.01.10 suppr transparence car : var carOpacity = [1-(self.dark*0.25),1-self.light]; etc  ??????????
// modification flocons ?????????
// pause neige si anim personnages dans "car"
// liaison travailmenu

var taille;
// if (window.location.href.indexOf('maxilampe=1')!=-1) {taille = 'gm'}
if ( (window.location.href.indexOf('maxilampe=1')!=-1) || ( (window.location.href.indexOf('maxilampe=9')!=-1) && (theWidth >1060) && (theHeight >=570) ) ) {taille = 'gm'};

var tempetedeneige = 0;
var pauseneige;
var travailmenu = false;

var EncoursHiver = 0;
var EncoursEte = 0;
var EncoursInterieur = 0;
var EncoursIntcheminee = 0;

// **********************************************************************

var $ = function(sID) {return document.getElementById(sID);}

function SCHILLMANIA() {

var nAV = navigator.appVersion.toLowerCase();
var nUA = navigator.userAgent.toLowerCase();
var nP = navigator.platform.toLowerCase();
var isIE = nAV.match(/msie/i);
var isOldIE = nAV.match(/msie [4,5]/i);
var isNewerIE = (isIE && !isOldIE);
var isFirefox = nUA.match(/firefox/i);
var isFirefox3 = (nUA.match(/firefox\/[3,4]/i)||nUA.match(/minefield\/[3,4]/i));
var isOpera = nUA.match(/opera/i);
var isSafari = nUA.match(/safari/i);
var isSafari3 = (isSafari && nUA.match(/version\/[3,4]/i));
var isWin32 = nP.match(/win/i);
var isMac = nP.match(/mac/i);
var isiPhone = (nUA.match(/iPhone/i));
var urlBase = urlRoot+'lumieres/';
if (isOpera) {
  isIE = false;
  isOldIE = false;
}
var IS_FAST_BROWSER = ((isSafari3 || isFirefox3 || isNewerIE) && !isiPhone);
var IS_SLOW = true;
var FULL_SCREEN = !IS_SLOW;
var IS_MOON_COMPUTER = (window.location.href.indexOf('moon')!=-1);

var animDuration = 0.66;

function removeChildNodes(o) {
  var nodes = o.childNodes;
  if (!nodes || !o) {
    writeDebug('removeChildNodes('+(o||'null')+'): no nodes to remove.');
    return false;
  }
  for (var i=nodes.length-1; i>=0; i--) {
    o.removeChild(nodes[i]);
  }
}

if (typeof YAHOO.util.BgPosAnim == 'undefined') {

(function() {
    YAHOO.util.BgPosAnim = function(el, attributes, duration,  method) {
        YAHOO.util.BgPosAnim.superclass.constructor.apply(this, arguments);
    };
    
    YAHOO.extend(YAHOO.util.BgPosAnim, YAHOO.util.Anim);
    var Y = YAHOO.util;
    var superclass = Y.BgPosAnim.superclass;
    var proto = Y.BgPosAnim.prototype;
    
    proto.toString = function() {
        var el = this.getEl();
        var id = el.id || el.tagName;
        return ("BgPosAnim " + id);
    };

    proto.patterns.bgPos = /^backgroundPosition|background-position$/i;
    
    proto.setAttribute = function(attr, val, unit) {
        if ( this.patterns.bgPos.test(attr) ) {
            val = val[0] + unit[0] + ' ' + val[1] + unit[1];
            YAHOO.util.Dom.setStyle(this.getEl(), attr, val);
        } else {
            superclass.setAttribute.apply(this, arguments);
        }
    },                        

    proto.doMethod = function(attr, start, end) {
        var val;
    
        if ( this.patterns.bgPos.test(attr) ) {
            val = [];
            for (var i = 0, len = start.length; i < len; ++i) {
                val[i] = superclass.doMethod.call(this, attr, start[i], end[i]);
            }
        }
        else {
            val = superclass.doMethod.apply(this, arguments);
        }

        return val;
    };

})();
}

var Y = {
 A: YAHOO.util.Anim,
 D: YAHOO.util.Dom,
 E: YAHOO.util.Event,
 UE: YAHOO.util.Easing,
 CA: YAHOO.util.ColorAnim,
 BG: YAHOO.util.BgPosAnim
}

function setActiveStyleSheet(title) {
  var i, a;
  var ss = APP_XHTML?document.styleSheets:document.getElementsByTagName('head')[0].getElementsByTagName('link');
  for (i=ss.length; i--;) {
    a = ss[i];
    if (!APP_XHTML) {
      if (a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')) {
        if (a.title == 'light' || a.title == 'dark') {
          a.disabled = true;
          if (a.getAttribute('title') == title) a.disabled = false;
        }
      }
    } else {
      if (a.href.indexOf('light')!=-1 || a.href.indexOf('dark')!=-1) {
        a.disabled = true;
        if (a.href.indexOf(title)!=-1) a.disabled = false;
      }
    }
  }
}

function doInit() {

  doWindowOnload();
  if (typeof XLSF2007 != 'undefined' && !isOldIE && ((window.location.href.indexOf('maxilampe=1')!=-1) || (window.location.href.indexOf('maxilampe=0')!=-1)  || (window.location.href.indexOf('maxilampe=9')!=-1)) ) {
    self.xlsf = new XLSF2007($('nav'));
  }
}

var fakeHour = new Date().getHours();

function Light() {
  var self = this;
  this.oSky = $('header');
  this.oShadeLight = $('sky-shade-light');
  this.oShadeDark = $('sky-shade-dark');
  var d = new Date();
  this.data = {
    hour: d.getHours(),
    minute: d.getMinutes(),
    light: 0,
    dark:0
  }
  this.lastState = null;

  this.colors = {
    c0: [187,221,255],
    c1: [227,171,99],
    c2: [161,191,220],
    c3: [204,204,204]
  }

  this.color = this.colors.c3;

  this.refreshTime = function(nHour) {
    var d = new Date();
    self.data.hour = d.getHours();
    self.data.minute = d.getMinutes();
    if (typeof nHour != 'undefined') {
      if (nHour>0 && nHour<24) self.data.hour = nHour;
    }
  }

  this.refreshLight = function() {
    var hour = (self.data.hour>11?self.data.hour-12:self.data.hour);
    var pm = (self.data.hour>11);
    var nLight = Math.round((hour/11)*100)/100;
    if (pm) nLight = Math.round((1-nLight)*100)/100;
    self.setLight(nLight);
  }

  this.setLight = function(n) {
    self.light = n;
    self.dark = (1-n);
  }
  
  this.applyNavColor = function(sLinkColor) {
    var oLinks = $('nav').getElementsByTagName('a');
    var oLinks2 = $('theme-options').getElementsByTagName('a');
    for (var i = oLinks.length; i--;) {
      oLinks[i].style.color = sLinkColor;
    }
    $('theme-options').style.color = sLinkColor;
    for (i = oLinks2.length; i--;) {
      oLinks2[i].style.color = sLinkColor;
    }
  }

  this.applyNavColor = function(sLinkColor) {
  
    var oLinks = $('nav').getElementsByTagName('a');
    var oLinks2 = $('theme-options').getElementsByTagName('a');
    for (var i = oLinks.length; i--;) {
      oLinks[i].style.color = sLinkColor;
    }
    $('theme-options').style.color = sLinkColor;
    for (i = oLinks2.length; i--;) {
      oLinks2[i].style.color = sLinkColor;
    }
  }

  this.applyLight = function() {
    var c = [parseInt(self.color[0]*self.light),parseInt(self.color[1]*self.light),parseInt(self.color[2]*self.light)];
    var borderColor = parseInt(102+(self.light*102));
    var bodyColor = parseInt(self.light*255);
    var bodyColorRGB = '#'+dec2hexArray([bodyColor,bodyColor,bodyColor]).join('');

    var skyShades = [
     [0,0,0],
     [0,51,204],
     [255,153,204],
     [204,204,153],
     [153,204,255],
     [255,255,255]
    ];

    var skyShadeDiffs = [];
    for (var i=0; i<skyShades.length-1; i++) {
      skyShadeDiffs[i] = [
        skyShades[i+1][0]-skyShades[i][0],
	skyShades[i+1][1]-skyShades[i][1],
	skyShades[i+1][2]-skyShades[i][2],
      ];
    }

    var iShade = Math.floor(self.light*(skyShades.length-2));
    var shade1 = skyShades[iShade];
    var shade2 = skyShades[iShade+1];
    var nSegments = skyShades.length-2;
    var currentSegment = self.light*nSegments;
    var segRemainder = currentSegment%1;
    var shadeDiffRatio = segRemainder;
    var sRatio = shadeDiffRatio;
    var shadeDiff = [parseInt(skyShadeDiffs[iShade][0]*sRatio),parseInt(skyShadeDiffs[iShade][1]*sRatio),parseInt(skyShadeDiffs[iShade][2]*sRatio)];
    var resultShade = [shade1[0]+shadeDiff[0],shade1[1]+shadeDiff[1],shade1[2]+shadeDiff[2]];
    resultShade = [parseInt(Math.min(255,Math.max(0,resultShade[0]))),parseInt(Math.min(255,Math.max(0,resultShade[1]))),parseInt(Math.min(255,Math.max(0,resultShade[2])))];
    var skyShade = dec2hexArray(resultShade).join('');
    var h = dec2hexArray(c);
    var h2 = dec2hexArray([borderColor,borderColor,borderColor]);
    var h3 = dec2hexArray([bodyColor,bodyColor,bodyColor]);
    self.oSky.style.backgroundColor = 'transparent';
    var oAnim = new Y.CA($('sky'),{backgroundColor:{to:'#'+skyShade}},animDuration);
    var oAnim1 = null;
    var oAnim1_1 = new Y.A($('sky'),{opacity:{to:Math.min(1,Math.max(0.33,self.light))}},animDuration,Y.UE.easeNone);

    if (FULL_SCREEN) {
      $('page-content').style.backgroundColor = 'transparent';
      var oTopStripBG = new Y.CA($('top-strip'),{backgroundColor:{to:bodyColorRGB}},animDuration);
      oTopStripBG.animate();
    }

    var oAnim2 = new Y.A(self.oShadeLight,{opacity:{to:self.light}},animDuration,Y.UE.easeNone);
    var oAnim3 = new Y.A(self.oShadeDark,{opacity:{to:self.dark}},animDuration*2,Y.UE.easeNone);
    var oAnim55 = new Y.A($('stars'),{opacity:{to:self.dark*0.65}},animDuration,Y.UE.easeNone);

    var oAnim6 = new Y.CA($('top-strip'),{backgroundColor:{to:'#'+h.join('')}},animDuration);
    var oAnim7 = new Y.A($('top-strip-dark'),{opacity:{to:self.dark}},animDuration*2,Y.UE.easeNone);

    var oAnim8 = new Y.A($('top-strip-light'),{opacity:{to:self.light}},animDuration*2,Y.UE.easeNone);
/*
    if (!isOldIE) {
      var carOpacity = [1-(self.dark*0.25),1-self.light];
      Y.D.setStyle($('whip'),'opacity',carOpacity[0]);
    }
*/
    function setBorderColor() {

      var rgbString = this.getAttribute('color');
      rgbString = rgbString.substring(4,rgbString.indexOf(','));
      var rgb = dec2hex(rgbString).toString();
      var rgbResult = ('#'+rgb+rgb+rgb);

      var nLight = parseInt(rgbString)/255;
      var adjustedRGB = dec2hex(parseInt(51+(nLight*153)));
      rgb = adjustedRGB;

      $('header').style.borderColor = rgbResult;

      if (FULL_SCREEN) {
        rgbString = this.getAttribute('backgroundColor');
        document.documentElement.style.backgroundColor = rgbString;
        $('page-content').style.borderColor = rgbResult;
      }

    }

	if (backdrop.canFade && typeof backdrop.opacityRange != 'undefined') {
	  var oR = backdrop.opacityRange;
	  var oStart = oR[0];
	  var oDiff = oR[1]-oR[0];
          var toOpacity = (oStart+(oDiff*self.light));
	  var oOpacityAnim = new Y.A($('backdrop'),{opacity:{to:toOpacity}},animDuration,Y.UE.easeNone);
          oOpacityAnim.animate();
	}

    function setNavColor() {
      if (isOpera) return false;
      var rgbString = this.getAttribute('color');
      rgbString = rgbString.substring(4,rgbString.indexOf(','));
      var rgb = dec2hex(rgbString).toString();
      var linkColor = ('#'+rgb+rgb+rgb);
      self.applyNavColor(linkColor);
    }

    var color_threshold = 0.6;

    if (self.light<color_threshold) {
      if (self.lastState != 'dark') {
        self.lastState = 'dark';
        var oT = $('theme-options');
        Y.D.removeClass(oT,'light');
        Y.D.addClass(oT,self.lastState);
        $('content').className = self.lastState;
        self.updateNavClass();  
      }
    } else if (self.lastState != 'light') {
      self.lastState = 'light';
      var oT = $('theme-options');
      Y.D.removeClass(oT,'dark');
      Y.D.addClass(oT,self.lastState);
      $('content').className = self.lastState;
      self.updateNavClass();
    }

    if (FULL_SCREEN && $('col2').className != self.lastState) {
      $('col2').className = self.lastState;
    } else if (!FULL_SCREEN && $('col2').className != 'light') {
      $('col2').className = '';
    }

    var pageColor = (self.light<color_threshold?(dec2hex(153+(self.light/(color_threshold-self.light)*102))):dec2hex(51+((1-self.light)*51)));
    pageColor = [pageColor,pageColor,pageColor];

    var oAnim11 = null;
    if (FULL_SCREEN) {
      oAnim11 = new Y.CA($('page-content'),{color:{to:'#'+pageColor.join('')}},animDuration);
    } else {
      $('page-content').style.color = '#333';
      $('page-content').style.borderColor = '#ccc';
    }

    var oAnim12 = null;

    if (backdrop.highContrast != 1) {
      oAnim12 = new Y.CA($('nav'),{color:{to:'#'+pageColor.join('')}},animDuration);
      oAnim12.onTween.subscribe(setNavColor);
    } else {
      var linkColor = (self.lastState=='dark'?'#fff':'#000');
      $('nav').style.color = linkColor;
      self.applyNavColor(linkColor);
    }

    var oAnim13 = null;
    var oAnim14 = null;

    var opacities = (self.light<color_threshold?[0,1]:[1,0]);
	if (!isIE) {
      oAnim13 = new Y.CA($('logo').getElementsByTagName('a')[0],{opacity:{to:opacities[0]}},animDuration);
      oAnim14 = new Y.CA($('logo').getElementsByTagName('div')[0],{opacity:{to:opacities[1]}},animDuration);
    }

    if (isOpera) {
      var oLinks = $('nav').getElementsByTagName('a');
      var linkColor = '#'+pageColor.join('');
      for (var i=oLinks.length; i--;) {
        oLinks[i].style.color = linkColor;
      }
    }

    var oAnim10 = new Y.CA($('meaningless'),{color:{to:'#'+h.join('')},backgroundColor:{to:'#'+h3.join('')}},animDuration);
    var oAnim15 = null;

    oAnim10.onTween.subscribe(setBorderColor);

    oAnim.animate();

    if (FULL_SCREEN) {
      oAnim1_1.animate();
    } else {
      Y.D.setStyle($('sky'),0.33);
    }

    if (oAnim1) oAnim1.animate();

    if (oAnim15) oAnim15.animate();

    if (!isIE) {
      if (FULL_SCREEN) setTimeout(function(){oAnim2.animate()},animDuration*1000*1.1);
      if (FULL_SCREEN) oAnim3.animate();
    }

function animatePhase2() {

    if (!IS_SLOW) oAnim6.animate();

if (FULL_SCREEN) {
    oAnim7.animate();
    oAnim8.animate();
    if (!isIE) oAnim55.animate();
}
    oAnim10.animate();

    if (oAnim11) oAnim11.animate();
    if (oAnim12) oAnim12.animate();
    if (oAnim13) oAnim13.animate();
    if (oAnim14) oAnim14.animate();
}
    animatePhase2();
  }

  this.updateNavClass = function() {
    if (isIE) {
      $('nav').className = self.lastState;
      return false;
    }
        var oS = $('stub');
        var oSHeight = parseInt(oS.offsetHeight);

	function oComplete() {
          $('nav').className = self.lastState;
          oS.style.backgroundImage = 'url('+urlBase+(self.lastState == 'dark'?'image/black-50.png':'image/white-50.png')+')';
          oS.style.backgroundPosition = ('0px -'+(oSHeight+'px'));
	  o2.animate();
	}

	var o = new Y.A(oS,{opacity:{to:0}},0.5,Y.UE.easeNone);
	var o2 = new Y.A(oS,{opacity:{to:1}},0.5,Y.UE.easeNone);

        o.onComplete.subscribe(oComplete);
	o.animate();
  }

  this.refresh = function(nOverride) {
    self.refreshTime(nOverride);
    self.refreshLight();
    self.applyLight();
  }
}

function dec2hex(cval) {
  if (cval > 255) cval = 255;
  var hexascii = "0123456789ABCDEF";
  var cval0 = Math.floor(cval/16);
  var cval1 = cval-(cval0*16);
  var c1 = hexascii.charAt(cval0);
  var c2 = hexascii.charAt(cval1);
  return (c1+c2);
}

function hex2dec(cval) {
  cval = cval.toUpperCase();
  var tval = 0;
  var hexascii = "0123456789ABCDEF";
  var mychar, ch;
  for (var c=0; c<cval.length; c++) {
    mychar = cval.charAt(c);
    for (ch=0; ch<16; ch++) {
      if (mychar == hexascii.charAt(ch)) {
        tval += ch;
	if (c<cval.length-1) tval *= 16;
      }
    }
  }
  return tval;
}

function hex2decArray(hArray) {
  var result = [];
  for (var i=0,j=hArray.length; i<j; i++) {
    result[i] = hex2dec(hArray[i]);
  }
  return result;
}

function dec2hexArray(dArray) {
  var result = [];
  for (var i=0,j=dArray.length; i<j; i++) {
    result[i] = dec2hex(dArray[i]);
  }
  return result;
}

var neigetil;
function mailanimstart() {
if ((travailmenu == false) && (pauseneige == 'sec')) {neigetil = 'rien'} else {neigetil = 'peutet'}
}

function car() {
  if (!IS_SLOW) {
    var myAnim = new Y.A('car',{left:{from:-100,to:1280}},7.2,Y.UE.easeNone);
//    myAnim.onComplete.subscribe(function(){setTimeout(car,10000+parseInt(Math.random()*7000));});

//    myAnim.onStart.subscribe(function(){if (Y.D.hasClass(document.body,'vueHiver'))stopsnow()});
//    myAnim.onComplete.subscribe(function(){if ((Y.D.hasClass(document.body,'vueHiver')) && (travailmenu == false) ){startsnow()};setTimeout(car,10000+parseInt(Math.random()*7000));});

    myAnim.onStart.subscribe(function(){mailanimstart(); if (Y.D.hasClass(document.body,'vueHiver'))stopsnow()});
    myAnim.onComplete.subscribe(function(){if ((Y.D.hasClass(document.body,'vueHiver')) && (neigetil == 'peutet') && (travailmenu == false) ){startsnow()};setTimeout(car,10000+parseInt(Math.random()*7000));});

  if (Y.D.hasClass(document.body,'vueHiver')) {
    setTimeout(function(){if(EncoursHiver == 1) {randomImageHiver()}; EncoursHiver= 1},100);
    } else {EncoursHiver = 0}
  if (Y.D.hasClass(document.body,'vueEte')) {
    setTimeout(function(){if(EncoursEte == 1) {randomImageEte()}; EncoursEte = 1},100);
    } else {EncoursEte = 0}
  if (Y.D.hasClass(document.body,'vueInterieur')) {
    setTimeout(function(){if(EncoursInterieur == 1) {randomImageHotel()}; EncoursInterieur = 1},100);
    } else {EncoursInterieur = 0}
  if (Y.D.hasClass(document.body,'vueIntcheminee')) {
    setTimeout(function(){if(EncoursIntcheminee == 1) {randomImageHotel()}; EncoursIntcheminee = 1},100);
    } else {EncoursIntcheminee = 0}
       
  if ( Y.D.hasClass(document.body,'vueHiver') || Y.D.hasClass(document.body,'vueEte') || Y.D.hasClass(document.body,'vueInterieur') || Y.D.hasClass(document.body,'vueIntcheminee')) {
    setTimeout(function(){myAnim.animate();},1300);
    }
    
    
  if ( !Y.D.hasClass(document.body,'vueHiver') && !Y.D.hasClass(document.body,'vueEte') && !Y.D.hasClass(document.body,'vueInterieur') && !Y.D.hasClass(document.body,'vueIntcheminee'))
  { setTimeout(car,10000+Math.random()*10000);}

  } else { setTimeout(car,10000+Math.random()*23000);}
}

var frame = 0;

var fliesFrame = -1;
var fliesTimer = null;

function add2007Link() {
  var o = document.createElement('a');
  o.href = '?maxilampe=0';
  o.innerHTML = 'mini-lumières';
  o.className = 'minilampe';
  o.title = 'Switch avec mini-lumières';
  $('col2-content').appendChild(o);
  if((window.location.href.indexOf('?maxilampe=0')!=-1) || ((window.location.href.indexOf('?maxilampe=9')!=-1) && (taille != 'gm')) ){Y.D.addClass(o,'orange');}
}

function add2008Link() {
  var o = document.createElement('a');
  o.href = '?lampes=0';
  o.innerHTML = 'sans';
  o.className = 'sanslampe';
  o.title = 'Switch sans lumières';
  $('col2-content').appendChild(o);
  if(window.location.href.indexOf('?lampes=0')!=-1){Y.D.addClass(o,'orange');}
}

function add2009Link() {
  var o = document.createElement('a');
  o.href = '?maxilampe=1';
  o.innerHTML = 'maxi-lumières';
  o.className = 'maxilampe';
  o.title = 'Switch maxi-lumières';
  $('col2-content').appendChild(o);
  if((window.location.href.indexOf('?maxilampe=1')!=-1) || ((window.location.href.indexOf('?maxilampe=9')!=-1) && (taille == 'gm')) ){Y.D.addClass(o,'orange');}
}

function startStuff() {
  if (isOldIE) {
    return false;
  }
  light = new Light();
  setTimeout(function(){light.refresh();},20);
  setTimeout(car,3000+Math.random()*6000);
  sliderInit();
}

function doWindowOnload() {
  if (!IS_FAST_BROWSER && !IS_MOON_COMPUTER) {
    $('slow').checked = false;
  } else {
    $('slow').checked = true;
    setTimeout(function(){toggleSlow.apply($('slow'));},1500);
  }
  startStuff();
}

function toggleSlow() {
  if (isOldIE) return false;
  IS_SLOW = this.checked?false:true;
  FULL_SCREEN = !IS_SLOW;
  Y.D[(IS_SLOW?'addClass':'removeClass')]($('body'),'slow');
  Y.D[(IS_SLOW?'removeClass':'addClass')]($('body'),'fast');
  light.applyLight();
  applySpeedSetting();
}

function applySpeedSetting() {
  if (!DID_ENHANCED) {
    DID_ENHANCED = 1;
  }
  if (!IS_SLOW) {
  } else {
    $('top-strip').style.backgroundColor = '#ddd';
  }
}

function sliderUpdate(nOffset) {
  sliderUpdateCount++;
  if (sliderUpdateCount < 2) return;
  var oS = $('sliderthumb-tip');
  if (oS) {
    oS.style.top = $('sliderthumb').offsetTop+'px';
    oS.style.visibility = 'visible';
  }
  var hour = 12-(nOffset/sliderHeight*12);
  var nLight = Math.round((hour/12)*100)/100;
  if (sliderUpdateTimer) window.clearTimeout(sliderUpdateTimer);
  sliderUpdateTimer = window.setTimeout(function(){removeSliderTooltip();light.setLight(nLight);light.applyLight(nLight)},500);

slider.subscribe("slideEnd", function() {synchro($('sliderthumb').offsetTop);});
}

dxniv = function(xniv) {slider.setValue(xniv, false)}
 
function removeSliderTooltip() {
  var oS = $('sliderthumb-tip');
  if (oS) {
    var oSAnim = new Y.A($('sliderthumb-tip'),{marginLeft:{from:0,to:32},opacity:{from:1,to:0.01}},animDuration,Y.UE.easeBothStrong);
    oSAnim.onComplete.subscribe(function(){if (oS) oS.parentNode.removeChild(oS);})
    oSAnim.animate();
  }
}

var sliderHeight = 0;

function sliderDown() {
  $('slider').className = 'active';
  var o = new Y.BG($('sliderlegend'),{backgroundPosition:{from:[-32,8],to:[0,8],unit:['px','px']}},0.33,Y.UE.easeBothStrong);
  var oS = $('sliderthumb-tip');
  if (oS) oS.style.visibility = 'visible';
  o.animate();
  document.onmouseup = sliderUp;
}

function sliderUp() {
  $('slider').className = '';
  var o = new Y.BG($('sliderlegend'),{backgroundPosition:{from:[0,8],to:[-32,8],unit:['px','px']}},0.33,Y.UE.easeBothStrong);
  o.animate();
  document.onmouseup = null;
}

function sliderInit() {
  var oThumb = $('sliderthumb');
  oThumb.title = "Monter ou descendre pour modifier l'environnement lumineux."+(!IS_FAST_BROWSER?' (See top checkbox for enhanced FX)':'');
  sliderHeight = parseInt($('slider').offsetHeight)-16;
  slider = YAHOO.widget.Slider.getVertSlider($('sliderbg'),$('sliderthumb'),0,sliderHeight);
  slider.subscribe('change', sliderUpdate);
  var hour = (light.data.hour>11?light.data.hour-12:light.data.hour);
  var pm = (light.data.hour>11);
  var lightValue = Math.round((hour/11)*100)/100;
  if (pm) lightValue = Math.round((1-lightValue)*100)/100;

  slider.subscribe('slideStart',function(){if ($('sliderthumb-tip')) $('sliderthumb-tip').style.visibility = 'hidden';});
  slider.subscribe('slideEnd',function(){if ($('sliderthumb-tip')) $('sliderthumb-tip').style.visibility = 'visible';});

  slider.setValue(sliderHeight-(sliderHeight*lightValue),true,false);
  
  slider.subscribe("slideEnd", function() {synchro($('sliderthumb').offsetTop);});

  $('sliderthumb-tip').style.top = (sliderHeight-(sliderHeight*lightValue)-1)+'px';

  var stAnim = new Y.A($('sliderthumb-tip'),{marginLeft:{from:32,to:0},opacity:{from:0.01,to:1}},animDuration,Y.UE.easeBothStrong);

  setTimeout(function(){stAnim.animate();},5000);

  Y.E.addListener(oThumb,'mousedown',sliderDown,oThumb);
}

function getScrollY1() {
  return window.scrollY;
}

function getScrollY2() {
  return ((document.documentElement && document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)||0);
}

var getScrollY = isSafari?getScrollY1:getScrollY2;

  var backgrounds = [];

var rootimg;
if ((theWidth >1060) && (theHeight >=570)) {rootimg = 'bghaut'} else {rootimg = 'image'};

  var bgData = {
    // premier opacity = light

    Morillon_Palladior: {
      className: 'vueHiver',
      background: 'transparent url('+rootimg+'/bg-morillon.jpg) bottom left no-repeat',
      description: "La Résidence Palladior à Morillon en hiver",
      opacity: 0,
      highContrast: 0,
      opacityRange: [0.9,0.6]//[1,0.5]origine
    },
    
    Palladior_Reception: {
      className: 'vueIntcheminee',
      background: 'transparent url('+rootimg+'/bg-morillon2.jpg) bottom left no-repeat',
      description: "Salons et réception de la Résidence Palladior à Morillon",
      opacity: 0,
      highContrast: 1,
      opacityRange: [0.9,0.7]//[0.7,0.5]
    },

    Palladior_Piscine: {
      className: 'vuePiscine',
      background: 'transparent url('+rootimg+'/bg-morillon3.jpg) no-repeat 0px 0px',
      description: "Espace forme et piscine couverte de la Résidence",
      opacity: 0,
      highContrast: 0,
      opacityRange: [0.9,0.75]//[0.9,1]
    },

    Morillon_Station: {
      className: 'vuePaysage',
      background: 'transparent url('+rootimg+'/bg-morillon4.jpg) no-repeat 0px 0px',
      description: "Morillon l'hiver : une authentique station village de Haute-Savoie",
      opacity: 0,
      highContrast: 0,
      opacityRange: [0.9,0.75]//[1,0.9]
    },

    Palladior_Suites: {
      className: 'vueInterieur',
      background: 'transparent url('+rootimg+'/bg-suites-best-western.jpg) no-repeat 0px 0px',
      description: "Exemples d'amenagement d'une suite Best Western",
      opacity: 0,
      highContrast: 0,
      opacityRange: [1,0.6] // [0.1,0.65]
    },

    Lac_Morillon: {
      className: 'vueEte',
      background: 'transparent url('+rootimg+'/bg-lac-bleu.jpg) no-repeat left bottom',
      description: "Vue sur le lac bleu de Morillon à proximité de la Résidence",
      opacity: 0,
      highContrast: 0,
      opacityRange: [0.9,0.75] // [0.7,0.7]
    }

  }
  void function(){
    var temp;
    for (temp in bgData) {
      bgData[temp].canFade = (!isIE || (isIE && typeof bgData[temp].bgURL == 'undefined'));
      backgrounds.push(temp);
    }
  }();
  
  var backdrop = null;
  var lastBackdrop = null;

var backdropIndex = 0;

function setBackdrop(n) {
  if (lastBackdrop) removeBackdrop(lastBackdrop);
  if (isNaN(n)) {
    backdrop = bgData[n];
  } else {
    var i = (typeof n != 'undefined'?n:++backdropIndex);
    if (i >= backgrounds.length) {
      i = 0;
    } else if (i < 0) {
      i = backgrounds.length-1;
    }
    backdropIndex = i;
    backdrop = bgData[backgrounds[i]];
    fade('legendes');
    
    setTimeout(function(){$('legendes').innerHTML = bgData[backgrounds[i]].description},150);
	gifload();

if (tempetedeneige == 1){
	if (Y.D.hasClass(backdrop, 'vueHiver')) { startsnow(); rstation();}
}

if (Y.D.hasClass(backdrop, 'vueHiver')) { randomImageHiver(); Y.D.setStyle($('whip').style.visibility='visible');}
if (Y.D.hasClass(backdrop, 'vueInterieur')) { rstation(); randomImageHotel(); Y.D.setStyle($('whip').style.visibility='visible');}
if (Y.D.hasClass(backdrop, 'vueIntcheminee')) { rstation(); randomImageHotel(); Y.D.setStyle($('whip').style.visibility='visible');}
if (Y.D.hasClass(backdrop, 'vueEte')) { rstation(); randomImageEte(); Y.D.setStyle($('whip').style.visibility='visible');} 
if (Y.D.hasClass(backdrop, 'vueEteNoanim') || Y.D.hasClass(backdrop, 'vuePiscine')) { rstation();} 

if ((Y.D.hasClass(backdrop, 'vueIntcheminee')) || (Y.D.hasClass(backdrop, 'vueInterieur')) || (Y.D.hasClass(backdrop, 'vueInterieurNoanim')) ) { stopsnow();
    Y.D.addClass('wn','rouge');
    } else {Y.D.removeClass('wn','rouge');}
    
if ((Y.D.hasClass(backdrop, 'vueEte')) || (Y.D.hasClass(backdrop, 'vueEteNoanim')) ) { stopsnow();
    Y.D.addClass('wn','standard');
    } else {Y.D.removeClass('wn','standard');}

if (Y.D.hasClass(backdrop, 'vuePaysage')) { startsnow();
    Y.D.addClass('wn','stars'); Y.D.setStyle($('whip').style.visibility='hidden'); sstation();
    } else {Y.D.removeClass('wn','stars');}

if (Y.D.hasClass(backdrop, 'vuePiscine')) { stopsnow();
    Y.D.addClass('wn','swim'); Y.D.setStyle($('whip').style.visibility='hidden');
    } else {Y.D.removeClass('wn','swim');}

  }
  applyBackdrop(backdrop);
  lastBackdrop = backdrop;
}

function applyBackdrop(oBackdrop) {
  if (typeof oBackdrop.className != 'undefined') Y.D.addClass($('body'),oBackdrop.className);
  var oBD = $('backdrop');
  var isPNG = oBackdrop.background.match(/.png/);
  if (typeof oBackdrop.background != 'undefined') {
    if (isOldIE && isPNG) {
      oBD.style.background = 'transparent';
      oBD.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+urlRoot+oBackdrop.bgURL+'",sizingMethod="crop")';
    } else {
      if (isOldIE) oBD.style.filter = '';
      var sBG = oBackdrop.background.replace('url(','url('+urlBase);
      oBD.style.background = sBG;
    }
  }
  if ((!isPNG || (isPNG && !isIE)) && typeof oBackdrop.opacity != 'undefined') {
    Y.D.setStyle(oBD,'opacity',oBackdrop.opacity);
  } else if (isIE && !isOldIE) {
    Y.D.setStyle(oBD,'opacity',1); // LAISSER CE COMMENTAIRE  *********   force 100% opacity for new IE
  }
}

function removeBackdrop(oBackdrop) {
  if (typeof oBackdrop.className != 'undefined') Y.D.removeClass($('body'),oBackdrop.className);
}

var themeOptionState = false;

function setThemeOptions(bOpen) {
  var o = $('theme-options');
  function onOA2Complete() {
    Y.D[(bOpen?'addClass':'removeClass')]($('slider'),'disabled');
  }
  function onOAComplete() {
    Y.D[(bOpen?'addClass':'removeClass')](o,'open');
    var oA2 = new Y.A(o,{opacity:{from:0,to:1}},animDuration/2,Y.UE.easeBothStrong);
    oA2.onComplete.subscribe(onOA2Complete);
    oA2.animate();
  }
  var oA = new Y.A(o,{opacity:{from:1,to:0}},animDuration/2,Y.UE.easeBothStrong);
  oA.onComplete.subscribe(onOAComplete);
  oA.animate();
}

// if (rv >= 7) {

function toggleThemeOptions() {
	var hackie = $('bgspecialie');
  var o = $('theme-options');
  var oT = $('theme-options-toggle');
  var oS = $('slider');
  themeOptionState = !themeOptionState;
  if (themeOptionState) {
    Y.D.addClass(oS,'disabled');
    if (rv >= 7) {hackie.style.display = 'block'};
  } else {
    Y.D.removeClass(oS,'disabled');
    if (rv >= 7) {hackie.style.display = 'none'};
  }
  setThemeOptions(themeOptionState);
}
  
var lastNavOpen = null;

function oldBrowserInit() {
  var o = $('nav').getElementsByTagName('h2');
  for (var i=o.length; i--;) {
    o[i].onclick = function() {
      var oNext = this.nextSibling;
      oNext.className = (oNext.className == 'open'?'':'open');
      if (lastNavOpen && lastNavOpen != oNext) lastNavOpen.className = '';
      lastNavOpen = oNext;
    }
  }
  $('col2').style.display = 'none';
  $('col2-content').style.display = 'none';
  var oEl = document.createElement('a');
  oEl.style.position = 'absolute';
  oEl.style.right = '2px';
  oEl.style.top = '5px';
  oEl.style.filter = 'alpha(opacity=50)';
  oEl.href = '/?theme=2008';
  oEl.innerHTML = 'Degraded for IE 6 - try 2008 edition';
  $('nav').appendChild(oEl);
}

function preInit() {
  _uacct = "UA-3081630-1";
  var d = new Date();
  Y.D.addClass($('body'),'hasjs');
  if (IS_MOON_COMPUTER) Y.D.addClass($('body'),'moon-computer');
  if (isFirefox) Y.D.addClass(document.getElementsByTagName('html')[0],'isFirefox');
  if (isFirefox3) Y.D.addClass(document.getElementsByTagName('html')[0],'isFirefox3');
  Y.D.addClass($('body'),(IS_SLOW?'slow':'fast'));
  $('speed-form').onsubmit = function() {return false;}
  $('slow').onclick = function(){toggleSlow.apply($('slow'));}
  var oS = $('slider');
  oS.parentNode.removeChild(oS);
  $('header').appendChild(oS);
  var oT = $('theme-options');
  oT.parentNode.removeChild(oT);
  $('options-stub').appendChild(oT);
  var oN = $('nav');
  oN.parentNode.removeChild(oN);
  $('header').appendChild(oN);
  if (isiPhone) {
    $('header').style.zIndex = 99;
    $('nav').style.zIndex = 100;
    $('sky').style.zIndex = -1;
    $('sky').style.display = 'none';
    $('header').style.border = '1px solid #ff33ff';
  }
  $('theme-options-toggle').title = 'Menu des photos';
  $('theme-options-toggle').onclick = function() {
    toggleThemeOptions();
  }
  if (isIE) {
    try {
      document.execCommand('BackgroundImageCache', false, true);
      function undoCache() {
        document.execCommand('BackgroundImageCache', false, false);
      }
      Y.E.on(window,'beforeunload',undoCache);
    } catch(e) {
    }
  }
  if (!isOldIE) {
    if (isIE) $('logo').getElementsByTagName('div')[0].className = '';
    setBackdrop(0);
  } else {
    oldBrowserInit();
  }
  if (snowStorm && snowStorm.preInit) snowStorm.preInit();
  var html = '';
 
  for (var i=0; i<backgrounds.length; i++) {
  
 var avant = backgrounds[i];
 var maintenant = avant.replace(/_/,"&nbsp;");
    html += '<div><a href="#bg'+i+'">'+maintenant+'</a></div>\n';
  }

  $('theme-list').innerHTML = html;

  var items = $('theme-list').getElementsByTagName('a');
  function setBG() {
    setBackdrop(this.rel);
    light.applyLight();
    try {
      this.focus();
    } catch(e) {
    }
    return false;
  }
  for (i=items.length; i--;) {
    items[i].title = (bgData[backgrounds[i]].description||'');
    items[i].rel = i;
    items[i].onclick = setBG;
    if (backgrounds[i].match(/secret/i)) items[i].style.display = 'none';
  }
  
  $('sliderthumb-tip').title = "Tirer le curseur verticalement pour modifier l'éclairage.";

  var oBGC = $('bg-controls');
  oBGC.getElementsByTagName('div')[0].onclick = function(){setBackdrop(backdropIndex-1);light.applyLight();}
  oBGC.getElementsByTagName('div')[1].onclick = function(){setBackdrop(backdropIndex+1);light.applyLight();}
  $('header-extras').appendChild(oBGC);

  var d2 = new Date();
  add2007Link();
  add2008Link();
  add2009Link();
  
  defiler = function(sens){setBackdrop(backdropIndex+sens);light.applyLight();}
}

var slider = null;
var sliderUpdateTimer = null;
var sliderUpdateCount = 0;
var light = null;
var DID_ENHANCED = 0;
var nav_state = 0;

var xhr = null;

setTimeout(doInit,500);

window._re = null;
window.re_ = null;
var lN = [];
var lnOffset = 0;

  /* *************** **
  ** -- SNOWSTORM -- **
  ** *************** */

var snowStorm = null;

function SnowStorm() {
  var s = this;
  var storm = this;
  this.timers = [];
  this.flakes = [];
  this.disabled = false;
  this.terrain = [];
  this.active = false;

  var usePNG = true;
  var imagePath = urlBase+'image/snow/';
  var flakeTypes = 6;
  var flakesMax = 128;
  var flakesMaxActive = 64;
  var vMaxX = 8;
  var vMaxY = 4;
  var flakeWidth = 5;
  var flakeHeight = 5;
  var flakeBottom;
  var snowCollect = true;
  var showStatus = true;

  var zIndex = 0;
  var flakeLeftOffset = 8;
  var flakeRightOffset = 0;

  var targetElement = 'backdrop';

  var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1);
  var isWin9X = (navigator.appVersion.toLowerCase().indexOf('windows 98')+1);
  var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1);
  if (isOpera) isIE = false;
  var screenX = null;
  var screenY = null;
  var scrollY = null;
  var vRndX = null;
  var vRndY = null;
  var pngSupported = (!isIE || (isIE && !navigator.userAgent.match(/msie 6/i) && !navigator.userAgent.match(/msie 5/i)));
  var docFrag = document.createDocumentFragment();
  this.oControl = null;
  if (flakeLeftOffset == null) flakeLeftOffset = 0;
  if (flakeRightOffset == null) flakeRightOffset = 0;

if ((theWidth >1060) && (theHeight >=570)) {flakeBottom = 430} else {flakeBottom = 300};

  function rnd(n,min) {
    if (isNaN(min)) min = 0;
    return (Math.random()*n)+min;
  }

  this.randomizeWind = function() {
    vRndX = plusMinus(rnd(vMaxX,0.2));
    vRndY = rnd(vMaxY,0.2);
    if (this.flakes) {
      for (var i=0; i<this.flakes.length; i++) {
        if (this.flakes[i].active) this.flakes[i].setVelocities();
      }
    }
  }

  function plusMinus(n) {
    return (parseInt(rnd(2))==1?n*-1:n);
  }

  this.resizeHandler = function() {
    if (window.innerWidth || window.innerHeight) {
      screenX = window.innerWidth-(!isIE?24:2)-flakeRightOffset;
      screenY = (flakeBottom?flakeBottom:window.innerHeight);
    } else {
      screenX = (document.documentElement.clientWidth||document.body.clientWidth||document.body.scrollWidth)-(!isIE?8:0)-flakeRightOffset;
      screenY = flakeBottom?flakeBottom:(document.documentElement.clientHeight||document.body.clientHeight||document.body.scrollHeight);
    }
  }

  this.resizeHandlerAlt = function() {
    screenX = targetElement.offsetLeft+targetElement.offsetWidth-flakeRightOffset;
    screenY = flakeBottom?flakeBottom:targetElement.offsetTop+targetElement.offsetHeight;
  }

  this.freeze = function() {
    if (!s.disabled) {
      s.disabled = 1;
    } else {
      return false;
    }
    for (var i=0; i<s.timers.length; i++) {
      clearInterval(s.timers[i]);
    }
  }

  this.resume = function() {
    if (s.disabled) {
       s.disabled = 0;
    } else {
      return false;
    }
    s.timerInit();
  }

  this.toggleSnow = function() {
    if (!s.flakes.length) {
      s.start();
      s.setControlActive(true);
    } else {
      s.active = !s.active;
      if (s.active) {
        s.show();
        s.resume();
        s.setControlActive(true); pauseneige = 'eau';
      } else {
        s.stop();
        s.freeze();
        s.setControlActive(false); pauseneige = 'sec';
      }
    }
  }

  this.setControlActive = function(bActive) {
    Y.D[(bActive?'addClass':'removeClass')](s.oControl,'active');
  }

  this.stop = function() {
    this.freeze();
    for (var i=this.flakes.length; i--;) {
      this.flakes[i].o.style.display = 'none';
    }
  }

  this.show = function() {
    for (var i=this.flakes.length; i--;) {
      this.flakes[i].o.style.display = 'block';
    }
  }

  this.SnowFlake = function(parent,type,x,y) {
    var s = this;
    var storm = parent;
    this.type = type;
    this.x = x||parseInt(rnd(screenX-12));
    this.y = (!isNaN(y)?y:-12);
    this.vX = null;
    this.vY = null;
    this.vAmpTypes = [2.0,1.0,1.25,1.0,1.5,1.75];
    this.vAmp = this.vAmpTypes[this.type];

    this.active = 1;
    this.o = document.createElement('img');
    this.o.style.position = 'absolute';
    this.o.style.width = flakeWidth+'px';
    this.o.style.height = flakeHeight+'px';
    this.o.style.fontSize = '1px';
    this.o.style.zIndex = zIndex;
    this.o.src = imagePath+this.type+(pngSupported && usePNG?'.png':'.gif');
    docFrag.appendChild(this.o);

    this.refresh = function() {
      s.o.style.left = s.x+'px';
      s.o.style.top = s.y+'px';
    }

    this.stick = function() {
      s.o.style.bottom = '0px';
      if (targetElement == document.documentElement) s.o.style.position = 'fixed';
    }

    this.vCheck = function() {
      if (s.vX>=0 && s.vX<0.2) {
        s.vX = 0.2;
      } else if (s.vX<0 && s.vX>-0.2) {
        s.vX = -0.2;
      }
      if (s.vY>=0 && s.vY<0.2) {
        s.vY = 0.2;
      }
    }

    this.move = function() {
      s.x += s.vX;
      s.y += (s.vY*s.vAmp);
      s.refresh();

      if (s.vX && screenX-s.x<flakeWidth+s.vX) {
        s.x = 0;
      } else if (s.vX<0 && s.x-flakeLeftOffset<0-flakeWidth) {
        s.x = screenX-flakeWidth;
      }
      var yDiff = screenY+scrollY-s.y-storm.terrain[Math.floor(s.x)];
      if (yDiff<flakeHeight) {
        s.active = 0;
        if (snowCollect) {
          var height = [0.75,1.5,0.75];
          for (var i=0; i<2; i++) {
            storm.terrain[Math.floor(s.x)+i+2] += height[i];
          }
        }
        s.o.style.left = (s.x/screenX*100)+'%';
        if (!flakeBottom) {
          s.stick();
        }
      }
    }

    this.animate = function() {
      s.move();
    }

    this.setVelocities = function() {
      s.vX = vRndX+rnd(vMaxX*0.12,0.1);
      s.vY = vRndY+rnd(vMaxY*0.12,0.1);
    }

    this.recycle = function() {
      s.o.style.position = 'absolute';
      s.setVelocities();
      s.vCheck();
      s.x = parseInt(rnd(screenX-flakeWidth-1));
      s.y = parseInt(rnd(300)*-1)-flakeHeight;
      s.active = 1;
    }

    this.recycle();
    this.refresh();

  }

  this.snow = function() {
    var active = 0;
    var used = 0;
    var waiting = 0;
    for (var i=s.flakes.length; i--;) {
      if (s.flakes[i].active == 1) {
        s.flakes[i].move();
        active++;
      } else if (s.flakes[i].active == 0) {
        used++;
      } else {
        waiting++;
      }
    }
    if (snowCollect && !waiting) {
      s.createSnow(flakesMaxActive,true);
    }
    if (active<flakesMaxActive) {
      with (s.flakes[parseInt(rnd(s.flakes.length))]) {
        if (!snowCollect && active == 0) {
          recycle();
        } else if (active == -1) {
          active = 1;
        }
      }
    }
  }

  this.createSnow = function(limit,allowInactive) {
    if (showStatus) window.status = 'Creating snow...';
    for (var i=0; i<limit; i++) {
      s.flakes[s.flakes.length] = new s.SnowFlake(s,parseInt(rnd(flakeTypes)));
      if (allowInactive || i>flakesMaxActive) s.flakes[s.flakes.length-1].active = -1;
    }
    targetElement.appendChild(docFrag);
    docFrag = document.createDocumentFragment();
    if (showStatus) window.status = '';
  }

  this.timerInit = function() {
    s.timers = (!isWin9X?[setInterval(s.snow,20)]:[setInterval(s.snow,75),setInterval(s.snow,25)]);
  }

  this.init = function() {
    for (var i=0; i<2048; i++) {
      s.terrain[i] = 0;
    }
    s.randomizeWind();
    s.createSnow(snowCollect?flakesMaxActive:flakesMaxActive*2);
    s.timerInit();
  }

this.oJoystick = null;

  this.preInit = function() {
    if (isOldIE) return false;
    s.oControl = document.createElement('div');
    s.oControl.className = 'snow-controls';
    s.oControl.title = 'Neige / sans neige';
    s.oControl.onclick = s.toggleSnow;
    s.oJoystick = document.createElement('div');
    s.oJoystick.className = 'joystick';
    s.oControl.appendChild(s.oJoystick);
    $('header-extras').appendChild(s.oControl);
  }

manuelsnow = function() {s.toggleSnow()}

	startsnow = function() {
if (!s.active)
 s.oControl.onclick()
}    

	stopsnow = function() {
 if (s.active)
 s.oControl.onclick()
}

	histstartsnow = function() {
if (Y.D.hasClass(backdrop, 'vueHiver') || Y.D.hasClass(backdrop, 'vuePaysage')) { startsnow()}
}

  this.start = function() {
    if (typeof targetElement == 'string') {
      targetElement = document.getElementById(targetElement);
      if (!targetElement) throw new Error('Snowstorm: Unable to get targetElement');
    }
    if (targetElement != document.documentElement) s.resizeHandler = s.resizeHandlerAlt;
    s.resizeHandler();
    if (screenX && screenY && !s.disabled) {
      s.init();
		s.active = true;
		s.setControlActive(true);
		tempetedeneige = 1;
		pauseneige = 'eau';
    }
  }

   Y.E.addListener(window,'load',s.start);

}
  snowStorm = new SnowStorm();


  /* *************** **
  ** -- XLSF 2007 -- **
  ** *************** */

function XLSF2007(oTarget) {
  var self = this;
  var xlsf = self;
  var animDuration = 1;
  this.oFrag = document.createDocumentFragment();
  this.oTarget = (oTarget||document.documentElement);
  this.oExplosionBox = document.createElement('div');
  this.oExplosionBox.className = 'xlsf-fragment-box';
  this.oExplosionFrag = document.createElement('div');
  this.oExplosionFrag.className = 'xlsf-fragment';
  this.lights = [];
  this.lightGroups = {
    left: [],
    haut: [],
    right: [],
    bottom: []
  }
  this.lightSmashCounter = 0;
  this.lightIndex = 0;
  this.lightInterval = 250;
  this.timer = null;
  this.bgBaseX = 0;
  this.bgBaseY = 0;
  
  this.cover = document.createElement('div');
  this.cover.className = 'xlsf-cover';
  document.documentElement.appendChild(this.cover);
  
  this.appendLights = function() {
    self.oTarget.appendChild(self.oFrag);
    self.oFrag = document.createDocumentFragment();
  }

  function ExplosionFragment(nType,sClass,x,y,vX,vY) {
    var self = this;
    this.o = xlsf.oExplosionFrag.cloneNode(true);
    this.nType = nType;
    this.sClass = sClass;
    this.x = x;
    this.y = y;
    this.w = 50;
    this.h = 50;
    this.bgBaseX = 0;
    this.bgBaseY = this.h*this.nType;
    this.vX = vX*(1+Math.random(0.75));
    this.vY = vY*(1+Math.random(0.75));
    this.oA = null;
    this.oA2 = null;
    this.burstPhase = 1;
    this.burstPhases = 3;
    this.o.style.backgroundPosition = ((this.w*-this.burstPhase)+'px '+(this.h*-nType)+'px');

    if (self.sClass == 'left') {
      this.vX = Math.abs(this.vX);
    } else if (self.sClass == 'right') {
      this.vX = Math.abs(this.vX)*-1;
    }

    this.burstTween = function() {
      var phase = 1+Math.floor((this.currentFrame/this.totalFrames)*self.burstPhases);
      if (phase != self.burstPhase) {
        self.burstPhase = phase;
        self.o.style.backgroundPosition = ((self.w*-self.burstPhase)+'px '+(self.h*-nType)+'px');
      }
    }

    this.burst = function() {
      self.oA = new Y.A(self.o,{marginLeft:{to:(self.vX*8)},marginTop:{to:(self.vY*8)}},animDuration,Y.UE.easeOutStrong);
      self.oA.onTween.subscribe(self.burstTween);
      self.oA.animate();
    }

    this.hide = function() {
      if (!isIE) self.o.style.opacity = 0;
    }

    this.reset = function() {
      self.o.style.left = '0px';
      self.o.style.top = '0px';
      self.o.style.marginLeft = '0px';
      self.o.style.marginTop = '0px';
      if (!isIE) self.o.style.opacity = 1;
    }

    this.animate = function() {
      self.reset();
      self.burst();
    }
  }

  function Explosion(nType,sClass,x,y) {
    var oParent = this;
    var self = this;
    this.o = null;
    this.nType = nType;
    this.sClass = sClass;
    this.x = x;
    this.y = y;
    this.boxVX = 0;
    this.boxVY = 0;
    this.o = xlsf.oExplosionBox.cloneNode(true);
    this.o.style.left = x+'px';
    this.o.style.top = y+'px';
    this.fragments = [];

    var mX = x;
    var mY = y;

    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,-5,-5));
    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,0,-5));
    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,5,-5));

    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,-5,0));
    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,0,0));
    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,5,0));

    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,5,-5));
    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,5,0));
    this.fragments.push(new ExplosionFragment(nType,sClass,mX,mY,5,5));

    this.init = function() {
      for (var i=self.fragments.length; i--;) {
        self.o.appendChild(self.fragments[i].o);
      }
      if (!IS_MOON_COMPUTER) {
        xlsf.oFrag.appendChild(self.o);
      } else {
        $('header').appendChild(self.o); 
      }
    }

    this.reset = function() {
      self.o.style.display = 'none';
      self.o.style.marginLeft = '0px';
      self.o.style.marginTop = '0px';
      self.o.style.left = self.x+'px';
      self.o.style.top = self.y+'px';
      if (!isIE) self.o.style.opacity = 1;
      for (var i=self.fragments.length; i--;) {
        self.fragments[i].reset();
      }
    }
    
    this.trigger = function(boxVX,boxVY) {
      self.o.style.display = 'block';
      self.boxVX = boxVX;
      self.boxVY = boxVY;

      if (self.sClass == 'right') {
        self.boxVX = Math.abs(self.boxVX)*-1;
      } else if (self.sClass == 'left') {
        self.boxVX = Math.abs(self.boxVX);
      }

      for (var i=self.fragments.length; i--;) {
        self.fragments[i].animate();
      }
      if (!isIE && (FULL_SCREEN || IS_MOON_COMPUTER)) {
        var oA = new Y.A(self.o,{marginLeft:{to:100*self.boxVX},marginTop:{to:150*self.boxVY},opacity:{to:0.01}},animDuration,Y.UE.easeInStrong);
      } else {
        var oA = new Y.A(self.o,{marginLeft:{to:100*self.boxVX},marginTop:{to:150*self.boxVY}},animDuration,Y.UE.easeInStrong);
      }
      oA.onComplete.subscribe(self.reset);
      oA.animate();
    }

    this.init();

  }

  function Light(sClass,nType,x,y) {
    var self = this;
    this.o = document.createElement('img');
    this.o.src = urlBase+'image/empty.gif';
    this.sClass = sClass;
    this.nType = (nType||0);
    this.useY = (sClass == 'left' || sClass == 'right');
    this.state = null;
    this.broken = 0;
    this.x = x;
    this.y = y;
    if (taille == 'gm') {this.w = 50; this.h = 50;} else {this.w = 32; this.h = 32;};
    this.bgBaseX = (self.useY?-self.w*this.nType:0);
    this.bgBaseY = (!self.useY?-self.h*this.nType:0);
    
    this.oExplosion = null;
    
    this.setBGPos = function(x,y) {
      self.o.style.backgroundPosition = ((self.bgBaseX+x)+'px '+(self.bgBaseY+y)+'px');
    }

    this.setLight = function(bOn) {
      if (self.broken || self.state == bOn) return false;
      if (!self.w || !self.h) self.getDimensions();
      self.state = bOn;
      if (self.useY) {
        self.setBGPos(0,-this.h*(bOn?0:1));
      } else {
        self.setBGPos(-this.w*(bOn?0:1),0);
      }
    }

    this.getDimensions = function() {
      self.w = self.o.offsetWidth;
      self.h = self.o.offsetHeight;
      self.bgBaseX = (self.useY?-self.w*self.nType:0);
      self.bgBaseY = (!self.useY?-self.h*self.nType:0);
    }

    this.on = function() {
      self.setLight(1);}

    this.off = function() {
      self.setLight(0);}
    
    this.flickr = function() {
      self.setLight(Math.random()>=0.5?1:0);}

    this.toggle = function() {
      self.setLight(!self.state?1:0);}

    this.explode = function(e) {
      self.oExplosion.trigger(0,1);}

    this.smash = function(e) {
      if (self.broken) return false;
      self.broken = true;
      
      self.explode(e);
      var rndFrame = 2+parseInt(Math.random()*3);
      if (self.useY) {
        self.setBGPos(0,self.h*-rndFrame);
      } else {
        self.setBGPos(self.w*-rndFrame,0);
      }
      xlsf.lightSmashCounter++;
    }
    
    this.reset = function() {
      if (!self.broken) return false;
      self.broken = false;
      self.state = null;
      xlsf.lightSmashCounter--;
      self.flickr();
    }

    this.init = function() {
      self.o.className = 'xlsf-light '+this.sClass;
      self.o.style.left = x+'px';
      self.o.style.top = y+'px';
       self.o.onmouseover = self.toggle;
       self.o.onmouseout = self.toggle;
      self.o.onclick = self.smash;
      self.flickr();
      xlsf.oFrag.appendChild(self.o);
      self.oExplosion = new Explosion(self.nType,self.sClass,self.x,self.y);
    }

    this.init();
    
  }

  this.createLight = function(sClass,nType,x,y) {
    var oLight = new Light(sClass,nType,x,y);
    self.lightGroups[sClass].push(oLight);
    self.lights.push(oLight);
    return oLight;
  }

  this.rotateLights = function() {
    self.lights[self.lightIndex==self.lights.length?self.lights.length-1:self.lightIndex].off();
    self.lightIndex++;
    if (self.lightIndex == self.lights.length) {
      self.lightIndex = 0;
    }
    self.lights[self.lightIndex].on();
  }

  this.randomLights = function() {
    self.lights[parseInt(Math.random()*self.lights.length)].toggle();
  }

  this.uberSmash = function() {
    self.stopSequence();
    var ebCN = Y.D.getElementsByClassName;
    window.setTimeout(function(){self.smashGroup(self.lightGroups.left)},500);
    window.setTimeout(function(){self.smashGroup(self.lightGroups.right)},2000);
    window.setTimeout(function(){self.smashGroup(self.lightGroups.bottom)},4000);
    window.setTimeout(function(){self.smashGroup(self.lightGroups.haut)},6000);    
  }

  this.smashGroup = function(oGroup) {
    for (var i=oGroup.length; i--;) {
      oGroup[i].smash();
    }
  }

  this.startSequence = function(fSequence,nInterval) {
    if (self.timer) self.stopSequence();
    self.timer = window.setInterval(fSequence,(typeof nInterval != 'undefined'?nInterval:self.lightInterval));
  }

  this.stopSequence = function() {
    if (self.timer) {
      window.clearInterval(self.timer);
      self.timer = null;
    }
  }

  var i=0;

 if ((theWidth >1060) && (theHeight >=570)) {
  for (i=0; i<10; i++) {
  if (taille == 'gm') {
	this.createLight('left',parseInt(Math.random()*4),-1,50+i*35);
	if (theWidth <=1060) {
    this.createLight('right',parseInt(Math.random()*4),851,50+i*35);}
    else {
    this.createLight('right',parseInt(Math.random()*4),961,50+i*35);}
    }
    else {
    this.createLight('left',parseInt(Math.random()*4),0,50+i*35);
    if (theWidth <=1060) {
    this.createLight('right',parseInt(Math.random()*4),868,60+i*35);}
    else {
    this.createLight('right',parseInt(Math.random()*4),978,60+i*35);}
    }
  }
} else {
  for (i=0; i<6; i++) {
  if (taille == 'gm') {
	this.createLight('left',parseInt(Math.random()*4),-1,50+i*35);
	if (theWidth <=1060) {
    this.createLight('right',parseInt(Math.random()*4),851,50+i*35);}
    else {
    this.createLight('right',parseInt(Math.random()*4),961,50+i*35);}
    }
    else {
    this.createLight('left',parseInt(Math.random()*4),0,50+i*35);
    if (theWidth <=1060) {
    this.createLight('right',parseInt(Math.random()*4),868,60+i*35);}
    else {
    this.createLight('right',parseInt(Math.random()*4),978,60+i*35);}
    }
  }
}

 if (theWidth <=1060) {
  for (i=0; i<24; i++) {
    if (taille == 'gm') {
    this.createLight('haut',parseInt(Math.random()*4),10+i*35,24);
    this.createLight('bottom',parseInt(Math.random()*4),10+i*35,254);}
    else {
    this.createLight('haut',parseInt(Math.random()*4),20+i*35,25);
    this.createLight('bottom',parseInt(Math.random()*4),20+i*35,268);
    }
  }
} else {
  for (i=0; i<27; i++) {
    if (taille == 'gm') {
    this.createLight('haut',parseInt(Math.random()*4),20+i*35,24);
    if (theHeight <570) {
    this.createLight('bottom',parseInt(Math.random()*4),20+i*35,254);}
    else {this.createLight('bottom',parseInt(Math.random()*4),20+i*35,384);}
    } else {
    this.createLight('haut',parseInt(Math.random()*4),20+i*35,25);
    if (theHeight <570) {
    this.createLight('bottom',parseInt(Math.random()*4),20+i*35,268);}
    else {this.createLight('bottom',parseInt(Math.random()*4),20+i*35,398);}    
    }    
  }  
}

  this.appendLights();

  this.startSequence(self.randomLights);

} // --- XLSF2007()

  preInit();

} // ----- SCHILLMANIA()

var s = null;

function preInit() {
  s = new SCHILLMANIA();
}
