﻿
function $(d){
 return document.getElementById(d);
}
// set or get the current display style of the div
function treesfuc1(d,v){
 if(v==undefined){
  return d.style.display;
 }else{
  d.style.display=v;
 }
}
// set or get the height of a div.
function treesfuc2(d,v){
 // if you are getting the height then display must be block to return the absolute height
 if(v==undefined){
  if(treesfuc1(d)!='none'&& treesfuc1(d)!=''){
   return d.offsetHeight;
  }
  viz = d.style.visibility;
  d.style.visibility = 'hidden';
  o = treesfuc1(d);
  treesfuc1(d,'block');
  r = parseInt(d.offsetHeight);
  treesfuc1(d,o);
  d.style.visibility = viz;
  return r;
 }else{
  d.style.height=v;
 }
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
speed1=7;
t=10;
//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function treesfuc3(d){
 d = $(d);
 if(treesfuc2(d)>0){
  v = Math.round(treesfuc2(d)/d.speed1);
  v = (v<1) ? 1 :v ;
  v = (treesfuc2(d)-v);
  treesfuc2(d,v+'px');
  d.style.opacity = (v/d.maxh);
  d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
 }else{
  treesfuc2(d,0);
  treesfuc1(d,'none');
  clearInterval(d.t);
 }
}
//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function treesfuc4(d){
 d = $(d);
 if(treesfuc2(d)<d.maxh){
  v = Math.round((d.maxh-treesfuc2(d))/d.speed1);
  v = (v<1) ? 1 :v ;
  v = (treesfuc2(d)+v);
  treesfuc2(d,v+'px');
  d.style.opacity = (v/d.maxh);
  d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
 }else{
  treesfuc2(d,d.maxh);
  clearInterval(d.t);
 }
}
// Collapse Initializer
function treesfuc5(d){
 if(treesfuc1(d)=='block'){
  clearInterval(d.t);
  d.t=setInterval('treesfuc3("'+d.id+'")',t);
 }
}
//Expand Initializer
function treesfuc6(d){
 if(treesfuc1(d)=='none'){
  treesfuc1(d,'block');
  d.style.height='0px';
  clearInterval(d.t);
  d.t=setInterval('treesfuc4("'+d.id+'")',t);
 }
}
// Removes Classname from the given div.
function treesfuc7(n,v){
 s=n.className.split(/\s+/);
 for(p=0;p<s.length;p++){
  if(s[p]==v+n.tc){
   s.splice(p,1);
   n.className=s.join(' ');
   break;
  }
 }
}
//Accordian Initializer
function treesfuc8(d,s,tc){
 // get all the elements that have id as content
 l=$(d).getElementsByTagName('div');
 c=[];
 for(i=0;i<l.length;i++){
  h=l[i].id;
  if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
 }
 sel=null;
 //then search through headers
 for(i=0;i<l.length;i++){
  h=l[i].id;
  if(h.substr(h.indexOf('-')+1,h.length)=='header'){
   d=$(h.substr(0,h.indexOf('-'))+'-content');
   d.style.display='none';
   d.style.overflow='hidden';
   d.maxh =treesfuc2(d);
   d.speed1=(s==undefined)? 7 : s;
   h=$(h);
   h.tc=tc;
   h.c=c;
   // set the onclick function for each header.
   h.onclick = function(){
    for(i=0;i<this.c.length;i++){
     cn=this.c[i];
     n=cn.substr(0,cn.indexOf('-'));
     if((n+'-header')==this.id){
      treesfuc6($(n+'-content'));
      n=$(n+'-header');
//      treesfuc7(n,'__');
      n.className=n.className+' '+n.tc;
     }else{
      treesfuc5($(n+'-content'));
      treesfuc7($(n+'-header'),'');
     }
    }
   }
   if(h.className.match(/selected+/)!=undefined){ sel=h;}
  }
 }
 if(sel!=undefined){sel.onClick();}
}

