// JavaScript Document
//Jeff
//www.huntingground.freeserve.co.uk

speed=15
hideLast=0 // 0 = yes 1 = no: automatically hides the previously revealed content

function initExpCol(){ // create objects

count=0
numOfObj=0
tags=document.getElementsByTagName("DIV")

while(tags[count]){
if(tags[count].id.indexOf("expdiv")!= -1){
numOfObj++
}
count++
}


for(var i=1;i<=numOfObj;i++){
window["my_object"+i]=new create("expdiv"+i)
document.getElementById("expander"+i).i=i

document.getElementById("expander"+i).onclick=function(){
window["my_object"+this.i].chk_status(this.i,'down')
}

}

// passing the divs number via the query string will automatically reveal the div when the page loads
if (location.search.length > 0){
preNum = unescape(location.search.substring(1));
window["my_object"+preNum].chk_status(preNum,'down');
}

}

lastNum=null

function create(id){ //define properties, pass id
this.id=id
this.num=this.id.replace(/[A-z]/g,"") // get number in id
this.element=document.getElementById(this.id)
this.height=this.element.offsetHeight
this.timer=null
this.running=0

this.chk_status=function(num,d){ // method & its properties, pass div number as argument

if(hideLast==1&&this.num!=lastNum&&lastNum!=null&&document.getElementById("expdiv"+lastNum).offsetHeight>0){
window["my_object"+lastNum].chk_status(lastNum,'up')
}

this.dir=d
if(this.dir=="up"){
document.getElementById("expander"+this.num).onclick=function(){
window["my_object"+num].chk_status(num,'down')
}
}
if(this.dir=="down"){
document.getElementById("expander"+this.num).onclick=function(){
window["my_object"+num].chk_status(num,'up')
}

}
this.running=1

this.step=speed

if("filters" in document.body && "alpha" in document.body.filters){this.opac=this.element.filters.alpha.opacity}
else{this.opac=this.element.style.opacity*100}

window["my_object"+num].animate('my_object'+num,num)

lastNum=this.num
}

this.animate=function(myobject,num){ // method & its properties, pass object name as argument
clearTimeout(this.timer)

if(this.dir=="down"){
this.element.style.display="block"
this.height+=this.step

this.opacStep=100/(this.element.scrollHeight/this.step)
this.opac=(this.opac+this.opacStep)*1

}
else{
this.height-=this.step
this.opacStep=100/(this.element.scrollHeight/this.step)

this.opac=(this.opac-this.opacStep)*1
}

this.stop=this.element.scrollHeight
this.timer=setTimeout(myobject+".animate('"+myobject+"','"+num+"')",50)

if(this.dir=="down"&&this.height>=(this.stop-speed)){
this.running=0
this.opac=100
this.height=this.stop
clearTimeout(this.timer)
}

if(this.dir=="up"&&this.height<=speed){
this.height=0
this.running=0
this.opac=0
clearTimeout(this.timer)
this.element.style.display="none"
}

this.element.style.height=this.height

if("filters" in document.body && "alpha" in document.body.filters){this.element.filters.alpha.opacity=this.opac}
else{this.element.style.opacity=(this.opac/100)-0.01}

}

}

// add  onload="initExpCol()" to the opening BODY tag
