var expandDetailsList=new Array();
function expandDetails(div, height){
  this.index=expandDetailsList.length;
  expandDetailsList[this.index]=this;
  this.div=div;
  this.maxHeight=height;
  this.items=new Array();
  this.itemHeight=new Array();
  this.itemCurrent=new Array();
  var itemIndex;
  this.selectedIndex=-1;
  var x=this.div.childNodes;
  var instance=this;
  this.div.onmouseout=function(evt){instance.selectedIndex=-1;instance.timeOut=window.setTimeout("expandDetailsList["+instance.index+"].slide();",200);};  
  for(var i=0; i<x.length; i++){   
    if(x[i].tagName=='IMG'||x[i].tagName=='DIV'){   
      itemIndex=this.items.length;   
      this.items[itemIndex]=x[i];
      this.itemHeight[itemIndex]=parseInt(x[i].offsetHeight);
      x[i].style['height']=this.itemHeight[itemIndex];
      this.itemHeight[itemIndex]-=parseInt(x[i].offsetHeight)-this.itemHeight[itemIndex];
      x[i].style['height']=this.itemHeight[itemIndex];    
      this.itemCurrent[itemIndex]=this.itemHeight[itemIndex];
      x[i].setAttribute('expandIndex',itemIndex);
      x[i].onmouseover=function(evt){instance.selectedIndex=this.getAttribute('expandIndex');instance.slide();};
      x[i].style["overflow"]="hidden";
    }
  }      
  this.snap();
}
expandDetails.prototype.slide=function(){
  window.clearTimeout(this.timeOut);
  var factor=0.25;
  var targetHeight=0;
  var cont=false;
  if(this.selectedIndex>=0)  targetHeight=Math.round((this.maxHeight-this.itemHeight[this.selectedIndex])/(this.items.length-1));
  else  targetHeight=Math.round(this.maxHeight/this.items.length);  
  for(var i=0; i<this.items.length; i++){
    if(this.selectedIndex==i){
      if(this.itemCurrent[i]!=this.itemHeight[i]){
        cont=true;
        this.itemCurrent[i]=this.itemCurrent[i]+(parseInt((this.itemHeight[i]-this.itemCurrent[i])*factor)+1)
      }            
    }else{
      if(this.itemCurrent[i]!=targetHeight){
        cont=true;
        this.itemCurrent[i]=this.itemCurrent[i]-(parseInt((this.itemCurrent[i]-targetHeight)*factor)+1)        
      }
    }
    this.items[i].style["height"]=this.itemCurrent[i]+"px";
  }
  if(cont){
    this.timeOut=window.setTimeout("expandDetailsList["+this.index+"].slide();",100);
  }
}
expandDetails.prototype.snap=function(){
  var targetHeight=0;
  if(this.selectedIndex>=0) targetHeight=Math.round((this.maxHeight-this.itemHeight[this.selectedIndex])/(this.items.length-1));
  else  targetHeight=Math.round(this.maxHeight/this.items.length);  
  for(var i=0; i<this.items.length; i++){
    if(this.selectedIndex==i) this.itemCurrent[i]=this.itemHeight[i];
    else this.itemCurrent[i]=targetHeight;
    this.items[i].style["height"]=this.itemCurrent[i]+"px";
  }
}

