var Mlay = null, Ilay = null, MCtlay = null, MCblay = null, REFlinks = new Array();
var DIR = 4, WT = false, CLAP = false, IN_TRANS = 0;
var LOCReg = /\?r=([h|f][0-9][0-9]*)/;
var LOADED = null;
var finit = null, fcur = null;
var cu = '';
var MAC = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1);
var MACIE = (document.all && MAC);
var tid = null;

var OP = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);
var OPLNKCOL = '#9C9A9C', OPHOVERCOL = '#FF6699', OPFIRST = 0;

/* Maximize window */
function wmax(w){
 w.moveTo(0,0);
 if (document.all)
  w.resizeTo(screen.availWidth,screen.availHeight);
 else if(document.getElementById){
  if (w.outerHeight<screen.availHeight||w.outerWidth<screen.availWidth){
   w.outerHeight = screen.availHeight;
   w.outerWidth = screen.availWidth;
  }
 }
}

/* Favoris */
function addfav(){
 if(document.all)
  window.external.AddFavorite("http://www.lasamaritaine.com", "Samaritaine, le grand magasin de la mode et de la déco");
 return false;
}

/* Popup */
 function wopen(lng){
  var w = window.open(lng+'/global.html', 'samarpop', 'left='+(self.screen.availWidth-760)/2+', top='+(self.screen.availHeight-410)/2+', width=760, height=410, location=no, menubar=no, resizable=0, scrollbars=no, status=no, toolbar=no, fullscreen=no');
  w.focus();
  return false;
 }

/* Menus footer */
 function footer_build(){
  var f = document.getElementById("footer");
  f.INSf = 1;
  var ml = document.getElementById("ml");
  var fdivcol = f.getElementsByTagName("DIV");
  var facol = document.getElementById("fmenu").getElementsByTagName("A");
  for(i=0;i<facol.length;i++){
   facol[i].chld = fdivcol[i+2];
   if((i==0&&OP)||(i==0&&MACIE))
    OPFIRST = facol[i].parentNode.offsetLeft;
   facol[i].chld.style.left = facol[i].parentNode.offsetLeft + 15 - OPFIRST;
   facol[i].chld.style.top = facol[i].parentNode.offsetHeight + 2;
   facol[i].onmouseover = ml.childNodes[0].onmouseover = function(){
    if(IN_TRANS)
     return;
    if(fcur!=null)
     fcur.style.visibility = 'hidden';
    else if(finit!=null)
     finit.style.visibility = 'hidden';
    if(this.chld){
     fcur = this.chld;
     fcur.style.visibility = 'visible';
    }
    else
     this.getElementsByTagName("IMG").item(0).src = 'img/ml_b.gif';
   }
  }
  if(document.all){
   f.onmouseout = ml.childNodes[0].onmouseout = function(){
    if(this.refsrc)
     this.getElementsByTagName("IMG").item(0).src = this.refsrc;
    if(this.contains(window.event.toElement))
     return;
    _release();
   }
   f.onmouseleave = function(){
    f.onmouseout = null;
    _release();
   }
  }
  else{
   f.onmouseout = ml.childNodes[0].onmouseout = function(e){
    if(this.refsrc)
     this.getElementsByTagName("IMG").item(0).src = this.refsrc;
    if((o=e.relatedTarget)){
     o = (o.nodeType==3)?o.parentNode:o;
     if(o.INSf == 1)
      return;
    }
    _release();
   }
  }
 }
 
 function _release(){
  if(fcur!=null)
   fcur.style.visibility = (fcur!=finit)?'hidden':'visible';
  if((fcur=finit)!=null)
   fcur.style.visibility = 'visible';
 }
   
 function init(){
  TMPcol = document.getElementById("hmenu").getElementsByTagName("A");
  for(i=0;i<TMPcol.length;i++){
   REFlinks['h'+i] = TMPcol[i];
  }
  TMPcol = document.getElementById("fmenu").getElementsByTagName("A");
  dTMPcol = document.getElementById("footer").getElementsByTagName("DIV");
  for(i=0;i<TMPcol.length;i++){
   TMPcol[i].INSf = TMPcol[i].parentNode.INSf = dTMPcol[i+2].INSf = 1;
   sTMPcol = dTMPcol[i+2].getElementsByTagName("A");
   for(a=0;a<sTMPcol.length;a++){
    REFlinks['f'+i+''+a] = sTMPcol[a];
    sTMPcol[a].INSf = 1;
    sTMPcol[a].prt = dTMPcol[i+2];
   }
  }
  REFlinks['f6'] = document.getElementById("ml").childNodes[0];
  REFlinks['f6'].refsrc = 'img/ml_a.gif';
  Mlay = document.getElementById("wmain");
  Ilay = document.getElementById("imain");
  window.setTimeout("footer_build()", 100);
  highlight(window.location, 1);
  window.opener.location.href = 'reindex.asp?r=0';
  wmax(window.opener);
 }
 
/* Transition clap */
 function trans(o, u){
  o.blur();
  if((u==cu)||CLAP)
   return false;
  cu = u;
  IN_TRANS = 1;
  if(arguments[2]!=null){
   aid = arguments[2];
   if(window.aloaded==undefined)
    window.aloaded = null;
   if(window.aloaded!=null){
    highlight('?r=f3'+aid, 0);
    if(aid==0&&!document.all)
     aid = 'top';
    else
     aid = 'a' + aid;
    if(OP)
     window.frames['main'].location.href = u;
    else
     window.frames['main'].document.getElementById('desc').src = window.aloaded + '#' + aid;
    return false;
   }
   window.aloaded = 'd_savourer.asp';
  }
  else
   window.aloaded = null;
  if(Mlay.style.clip!=null&&!MAC&&!OP){
   CLAP = true;
   Mlay.clipt = 0;
   Mlay.clipb = 260;
   WT = false;
   _trans(u, DIR);
   return false;
  }
  else if(MAC){
   Ilay.src = u;
   return false;
  }
  else if(OP){
   frames['main'].location.href = u;
   return false;
  }
  return true;
 }

 function _trans(u, d){
  if(!WT){
   Mlay.style.clip = "rect("+(Mlay.clipt += d)+"px 760px "+(Mlay.clipb -= d)+"px 0px)";
   if(Mlay.clipt>Mlay.clipb){
    Ilay.src = u;
    d = -d;
    WT = true;
   }
  }
  if((Mlay.clipt>=0)&&(Mlay.clipb<=260))
   window.setTimeout("_trans('"+u+"', "+d+")", 10);
  else{
   Mlay.style.clip = "rect(0px 760px 260px 0px)";
   CLAP = false;
  }
 }

/* Highlight de la rubrique en cours */
 function highlight(rid, ld){
  WT = false;
  if(LOADED!=null){
   if(LOADED.getElementsByTagName("IMG").length>0)
    LOADED.refsrc = LOADED.getElementsByTagName("IMG").item(0).src = 'img/ml_a.gif';
   else{
    if(LOADED.prt)
     LOADED.prt.style.visibility = 'hidden';
    if(OP)
     LOADED.style.color = OPLNKCOL;
    else
     LOADED.className = '';
   }
   LOADED = finit = null;
  }
  IN_TRANS = 0;
  if(rid=='?r='){
   return;
  }
  if((res = LOCReg.exec(rid))==null)
   return;
  LOADED = REFlinks[res[1]];
  if(LOADED.getElementsByTagName("IMG").length>0)
   LOADED.refsrc = LOADED.getElementsByTagName("IMG").item(0).src = 'img/ml_b.gif';
  else{
   if(OP)
    LOADED.style.color = OPHOVERCOL;
   else
    LOADED.className = 'on';
   if((finit=LOADED.prt))
    finit.style.visibility = 'visible';
  }
  if(ld)
   Ilay.src = LOADED.href;
 }