// FELIXONE.it © 2002/2007 - All rights reserved.

function doOutline(evnt) {
  var targetId, srcElm, id, opn, myclass, fh=0;
  if (window.event) {
    srcElm = window.event.srcElement;
    nav = "ie";
  } else {
    srcElm = evnt.target;
    nav = "nt";
  }
  id = srcElm.id;
  opn = id.substring(id.lastIndexOf("_"));
  if (opn == "_I" || opn == "_H") {
    prnElm = srcElm.parentNode;
    mytag = prnElm.tagName;
    srcElm = srcElm.id;
    srcElm = srcElm.substr(0, srcElm.length-2);
    targetId = srcElm + "_S";
    checkid = srcElm;
    mname = checkid.replace(/_\d+/g, "");
    mname = mname.replace(/_$/, "");
    srcElm1 = srcElm + "_I";
    srcElm2 = srcElm + "_F";
    if (document.getElementById) {
      srcElm1 = document.getElementById(srcElm1);
      if (document.getElementById(srcElm2)) srcElm2 = document.getElementById(srcElm2);
      targetElm = document.getElementById(targetId);
      for (i=0; i<targetElm.childNodes[0].length; i++) {
        targetElm.removeChild(targetElm.firstChild);
      }
    } else {
      srcElm1 = document.all(srcElm1);
      if (document.all(srcElm2)) srcElm2 = document.all(srcElm2);
      targetElm = document.all(targetId);
    }
    if (targetElm.firstChild.className) {
      myclass = targetElm.firstChild.className;
    } else myclass = getTheClass(targetElm);
    if (myclass) fh = getFHeight(myclass);
    if (targetElm) {
      alltext = targetElm.parentNode.innerHTML;
      if (srcElm1.src) imgopn = srcElm1.src.replace(/_open\./, ".");
      if (srcElm2.src) imgcnt = srcElm2.src.replace(/_open\./, ".");
      ih1 = (srcElm1.height);
      ih2 = (srcElm2.height) ? srcElm2.height : 0;
      hs = Math.max(ih1,ih2)+2;
      hs = Math.max(hs,fh);
      str = targetElm.innerHTML;
      myids = str.match(new RegExp(checkid+"_\\d+_S","g"));
      str = str.replace(/<div[^>]*?>[\W\w]+?<\/div>/gi, "");
      str = str.replace(/>\s+</g, "");
      match = str.match(/>[^>]+</gi);
      lnh = (match.length)*hs;
      if (targetElm.style.display == "none") {
        if (eval(mname+"_ffxcls")) closeAll(alltext,hs);
        if (srcElm1.src) srcElm1.src = imgopn.replace(/\.(\w+)$/, "_open.$1");
        if (srcElm2.src) srcElm2.src = imgcnt.replace(/\.(\w+)$/, "_open.$1");
        if (eval(mname+"_ffxnm") == "Slide") {
          targetElm.style.height = "0px";
          startOpen(myclass);
        }
        targetElm.style.display = "";
      } else {
        if (eval(mname+"_ffxnm") == "Slide") {
          if (eval(mname+"_ffxcls")) {
            closeAll(alltext,hs);
          } else startClose();
        } else {
          if (srcElm1.src) srcElm1.src = imgopn;
          if (srcElm2.src) srcElm2.src = imgcnt;
          targetElm.style.display = 'none';
        }
      }
    }
  }
}


function reopen(node) {
  var fxoid = node;
  var fxsrc, fxid="";
  var fxparam = fxoid.split(",");
  var fxsrcs = fxparam[1].split("_");
  for (i=0; i<fxsrcs.length; i++) {
    if (fxid != "") fxid += "_";
    fxid += fxsrcs[i];
    fxsrc = fxparam[0]+"__"+fxid;
    fxsrc1 = fxsrc + "_I";
    fxsrc2 = fxsrc + "_F";
    fxsrc += "_S";
    if (document.all) {
      fxsrc = document.all(fxsrc);
      fxsrc1 = document.all(fxsrc1);
      if (document.all(fxsrc2)) fxsrc2 = document.all(fxsrc2);
    } else if (document.getElementById) {
      fxsrc = document.getElementById(fxsrc);
      fxsrc1 = document.getElementById(fxsrc1);
      if (document.getElementById(fxsrc2)) fxsrc2 = document.getElementById(fxsrc2);
    }
    if (fxsrc) {
      if (fxsrc1.src) {
        imgopn = fxsrc1.src;
        fxsrc1.src = imgopn.replace(/\.(\w+)$/, "_open.$1");
      }
      if (fxsrc2.src) {
        imgcnt = fxsrc2.src;
        fxsrc2.src = imgcnt.replace(/\.(\w+)$/, "_open.$1");
      }
      lf = parseInt(eval(fxparam[0]+"_ffxpo"));
      fxsrc.style.position = "relative";
      fxsrc.style.left = lf+"px";
      fxsrc.style.display = "";
    }
  }
}

//----------------------------- Effects --------------------------------

function startOpen(clss) {
  opnsize = getOpened(myids);
  if (!clss) alert("A class with the height or font-size style for this menu does not exists. Please create it.");
  if (mytag.toLowerCase() == "div") prnElm.style.height = "";
  h = 0;
  lf = 0;
  targetElm.style.overflow = "hidden";
  oh = lnh + opnsize;
  openSlide();
}


function openSlide() {
  if (h < oh) {
    h += parseInt(eval(mname+"_ffxst"));
    if (h > oh) h = oh;
    targetElm.style.height = h+"px";
    setTimeout("openSlide()",parseInt(eval(mname+"_ffxsp"))/2);
  }
  if (h == oh) {
    if (lf < parseInt(eval(mname+"_ffxpo"))) {
      lf += parseInt(eval(mname+"_ffxst"));
      if (lf > parseInt(eval(mname+"_ffxpo"))) lf = parseInt(eval(mname+"_ffxpo"));
      targetElm.style.position = "relative";
      targetElm.style.left = lf+"px";
      setTimeout("openSlide()",parseInt(eval(mname+"_ffxsp")));
    }
  }
}


function startImplode() {
  if (len > 0) {
    allElm[ix].style.overflow = "hidden";
    prElm = allElm[ix].parentNode;
    thetag = prElm.tagName;
    if (thetag.toLowerCase() == "div") prElm.style.height = "";
    theElm = allElm[ix];
    theElm1 = allElm1[ix];
    theElm2 = allElm2[ix];
    ch = ach[ix];
    clf = alf[ix];
    len--;
    ix++;
    stk = parseInt(eval(mname+"_ffxst"));
    spd = parseInt(eval(mname+"_ffxsp"));
    delay = (ch/stk*spd)*1.4+((clf/stk)*(spd/2));
    closeSlide();
    setTimeout("startImplode()",parseInt(delay));
  }
}


function startClose() {
  opnsize = getOpened(myids);
  if (mytag.toLowerCase() == "div") prnElm.style.height = "";
  targetElm.style.overflow = "hidden";
  theElm = targetElm;
  theElm1 = srcElm1;
  theElm2 = srcElm2;
  ch = lnh + opnsize;
  clf = parseInt(eval(mname+"_ffxpo"));
  closeSlide();
}


function closeSlide() {
  if (clf > 0) {
    clf -= parseInt(eval(mname+"_ffxst"));
    if (clf < 0) clf = 0;
    theElm.style.position = "relative";
    theElm.style.left = clf+"px";
    setTimeout("closeSlide()",parseInt(eval(mname+"_ffxsp"))/2);
  }
  if (clf == 0) {
    if (ch > 1) {
      ch -= parseInt(eval(mname+"_ffxst"));
      if (ch < 1) ch = 1;
      theElm.style.height = ch+"px";
      setTimeout("closeSlide()",parseInt(eval(mname+"_ffxsp")));
    } else {
      if (theElm1.src) theElm1.src = imgopn;
      if (theElm2 && theElm2.src) theElm2.src = imgcnt;
      theElm.style.display = "none";
    }
  }
}

//--------------------------- end Effects ------------------------------

function getFHeight(clss) {
  var size, fsize = 0;
  var csss = document.styleSheets;
  for (var is=0; is<csss.length; is++) {
    shtrul = csss[is].rules ? csss[is].rules : csss[is].cssRules;
    for (var x=0; x<shtrul.length; x++) {
      name = shtrul[x].selectorText;
      names = name.match(/^(\w*\.)*(\w+)/i);
      if (names[2] == clss) {
        size = shtrul[x].style.height ? shtrul[x].style.height : "f"+shtrul[x].style.fontSize;
        myrule = shtrul[x];
        break;
      }
    }
  }
  matches = size.match(/(f*)(\d+)(\w+)/i);
  if (matches) {
    if (matches[3] != "px") {
      alert("The height or font-size style for this menu is not expressed in 'px'. Please correct it.");
      return;
    } else {
      fsize = matches[2];
      if (matches[1] == "f") {
        fsize = fsize*1+4;
      } else {
        gap = 0;
        if (myrule.style.padding) {
          gap = gap*1+parseInt(myrule.style.padding)*4;
        } else {
          if (myrule.style.paddingTop) gap = gap*1+parseInt(myrule.style.paddingTop);
          if (myrule.style.paddingLeft) gap = gap*1+parseInt(myrule.style.paddingLeft);
          if (myrule.style.paddingBottom) gap = gap*1+parseInt(myrule.style.paddingBottom);
          if (myrule.style.paddingRight) gap = gap*1+parseInt(myrule.style.paddingRight);
        }
        if (myrule.style.border) {
          vals = myrule.style.border;
          val = vals.match(/\s*(\d+px)\s*/i);
          gap = gap*1+parseInt(val[1])*4;
        } else {
          if (myrule.style.borderTopWidth) gap = gap*1+parseInt(myrule.style.borderTopWidth);
          if (myrule.style.borderLeftWidth) gap = gap*1+parseInt(myrule.style.borderLeftWidth);
          if (myrule.style.borderBottomWidth) gap = gap*1+parseInt(myrule.style.borderBottomWidth);
          if (myrule.style.borderRighttWidth) gap = gap*1+parseInt(myrule.style.borderRightWidth);
        }
        fsize = fsize*1+gap;
      }
    }
  }
  return fsize;
}


function closeAll(txt,hg) {
  var myelm2, myidx;
  var opnarray = new Array();
  var opn1array = new Array();
  var opn2array = new Array();
  allids = txt.match(/ id="*\w+_S"*\s*/gi);
  for (y=0; y<allids.length; y++) {
    theid = allids[y].match(/="*((\w+)_S)"*/i);
    if (nav == "ie") {
      myelm = document.all(theid[1]);
      myelm1 = document.all(theid[2]+"_I");
      if (document.all(theid[2]+"_F")) myelm2 = document.all(theid[2]+"_F");
    } else {
      myelm = document.getElementById(theid[1]);
      myelm1 = document.getElementById(theid[2]+"_I");
      if (document.getElementById(theid[2]+"_F")) myelm2 = document.getElementById(theid[2]+"_F");
    }
    if (myelm.style.display == "") {
      if (eval(mname+"_ffxnm") == "Slide") {
        opnarray.push(myelm);
        opn1array.push(myelm1);
        if (myelm2) opn2array.push(myelm2);
      } else {
        if (myelm1.src) myelm1.src = imgopn;
        if (myelm2) myelm2.src = imgcnt;
        myelm.style.display = "none";
      }
    }
  }
  allElm = new Array();
  allElm1 = new Array();
  allElm2 = new Array();
  ach = new Array();
  alf = new Array();
  if (opnarray.length > 0) {
    for (var r=opnarray.length-1; r>=0; r--) {
      allElm.push(opnarray[r]);
      allElm1.push(opn1array[r]);
      allElm2.push(opn2array[r]);
    }
    for (oN=0; oN<allElm.length; oN++) {
      chkid = (allElm[oN].id).replace(/_S/,"");
      thestr = allElm[oN].innerHTML;
      myidx = thestr.match(new RegExp(chkid+"_\\d+_S","g"));
      opnsize = getOpened(myidx);
      if (!myidx) {
        thestr = thestr.replace(/<div[^>]*?>[\W\w]+?<\/div>/gi, "");
        thestr = thestr.replace(/>\s+</g, "");
        myidx = thestr.match(/>[^>]+</gi);
      }
      cnh = (myidx.length)*hg;
      thisch = cnh + opnsize;
      ach.push(cnh);
      alf.push(parseInt(eval(mname+"_ffxpo")));
    }
    len = ach.length;
    ix = 0;
    startImplode();
  }
}


function getTheClass(elm) {
  thetag = elm.parentNode.tagName;
  theclass = elm.parentNode.className;
  if (!theclass && thetag.toLowerCase() != "body") {
    elm = elm.parentNode;
    getTheClass(elm);
  }
  return theclass;
}


function getOpened(ids) {
  val = 0;
  if (ids && ids.length > 0) {
    for (op=0; op<ids.length; op++) {
      if (document.all) {
        thisElm = document.all(ids[op]);
      } else thisElm = document.getElementById(ids[op]);
      val += thisElm.style.height ? parseInt(thisElm.style.height) : 0;
    }
  }
  return val;
}


