﻿// JScript File
var  checkscrollInterval;
 var intervalArray=new Array()
var fps=20 //frames per second
    function fs(fsid,bg,content,closeDiv,middleDiv,bottomDiv,bgOpacity,fadeTime){
        this._fsid=document.getElementById(fsid);
        this._bg=document.getElementById(bg);
        this._middleDiv=document.getElementById(middleDiv);
        this._content=document.getElementById(content);
        this._bgOpacity=bgOpacity;
        this._fadeTime=fadeTime;
        this._contentHeight=this._content.offsetHeight;
      
        this._contentTopMargin=regXreplace(this._content.style.top,"px","");
        this._contentWidth=regXreplace(this._content.style.width,"px","");
        this._contentHeight=regXreplace(this._content.style.height,"px","");
        
        this._closeDiv=document.getElementById(closeDiv);
         this._topHeight=regXreplace(this._closeDiv.style.height,"px","");
        this._bottomDiv=document.getElementById(bottomDiv);
         this._bottomHeight=regXreplace(this._bottomDiv.style.height,"px","");
        if (  this._contentTopMargin=='')this._contentTopMargin=0
        
    }
    fs.prototype.setContentSize=function(w,h,top){
     
        this._contentWidth=w
        this._contentHeight=h
        
        this._closeDiv.style.width=w +"px"
         this._bottomDiv.style.width=w +"px"
         this._middleDiv.style.height=h+"px"
        this._contentTopMargin=top
         
        
    }
    fs.prototype.show=function(html){
 
       this._bg.style.height=(document.body.offsetHeight >getScreenDimentions().y)?document.body.offsetHeight + "px":getScreenDimentions().y+ "px"
     
       var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
       this._bg.style.top=scrollTop + "px"
       this._content.style.top=String(Number(scrollTop+ this._contentTopMargin)) +"px"    
       showElement(this._fsid.id)
       animate(this._bg.id,"opacity",0,this._bgOpacity/100,this._fadeTime,"{value}")
       animate(this._bg.id,"filter",0,this._bgOpacity,this._fadeTime,"alpha(opacity={value})")
        this._content.style.width="0px"
        
       this._closeDiv.style.height="0px"
       this._bottomDiv.style.height="0px"

        this._middleDiv.innerHTML=""
       setTimeout("animate('"+ this._content.id+"','width',400,"+this._contentWidth+","+2*this._fadeTime+",'{value}px')",this._fadeTime*1000)        
       setTimeout("animate('"+ this._closeDiv.id+"','height',0,"+this._topHeight+","+this._fadeTime+",'{value}px')",this._fadeTime*3000)        
       setTimeout("animate('"+ this._bottomDiv.id+"','height',0,"+this._topHeight+","+this._fadeTime+",'{value}px')",this._fadeTime*3000)  
       setTimeout("document.getElementById('"+this._middleDiv.id+"').innerHTML=\"" +html +"\"",this._fadeTime*4000)
 
        checkscrollInterval=setInterval("checkscroll('"+this._fsid.id+"','"+this._content.id+ "','" + this._bg.id + "'," + this._contentTopMargin+")",20)
        // hide pulldowns as they cant be overlayed
        var selects =document.getElementsByTagName("SELECT")
        for (var i=0;i<selects.length;i++){
            selects[i].style.visibility="hidden"
            selects[i].style.display="none"
       }
         
    }
    fs.prototype.showShort=function(html){
     animate(this._middleDiv.id,"filter",100,0, this._fadeTime,"alpha(opacity={value})")
     animate(this._middleDiv.id,"opacity",1,0, this._fadeTime,"{value}")
     this.getPicShort(html);

    }
   fs.prototype.getPicShort=function(html){
   
        setTimeout("document.getElementById('"+this._middleDiv.id+"').innerHTML = '"+html+"'",this._fadeTime*1500);
        //this._middleDiv.innerHTML = html;
        setTimeout("animate('"+ this._middleDiv.id+"','filter',0,100,"+this._fadeTime+",'alpha(opacity={value})')",this._fadeTime*1500)  
        setTimeout("animate('"+ this._middleDiv.id+"','opacity',0,1,"+this._fadeTime+",'{value}')",this._fadeTime*1500)      
      }
  
      
fs.prototype.hide=function(){
    this._bg.style.opacity=0
    this._bg.style.filter="alpha(opacity=0)"
     hideElement(this._fsid.id);
     //show back the hidden elements
     var selects =document.getElementsByTagName("SELECT")
     for (var i=0;i<selects.length;i++){
        selects[i].style.visibility="visible"
        selects[i].style.display=""
    }
    this._middleDiv.innerHTML=""
 } 
 function getScreenDimentions(){
 var x,y
  if (self.innerHeight) // all except Explorer
            {
	            x = self.innerWidth;
	            y = self.innerHeight;
            }
            else if (document.documentElement && document.documentElement.clientHeight)
	            // Explorer 6 Strict Mode
            {
	            x = document.documentElement.clientWidth;
	            y = document.documentElement.clientHeight;
            }
            else if (document.body) // other Explorers
            {
	            x = document.body.clientWidth;
	            y = document.body.clientHeight;
            }
            return {x:x,y:y}
 }
function animate(objID,cssProperty,startValue,endValue,time,cssFormat){ // time in seconds
    var actionString;
    // set initial value
    curValue=startValue
    curFormattedValue=regXreplace(cssFormat,"{value}",curValue.toString())      
    document.getElementById(objID).style[cssProperty]=curFormattedValue;
    var  startTime = new Date().getTime();
    // set Interval
    actionString="animateRoutine("+startTime+","+intervalArray.length+",'"+objID+"','" + cssProperty +"'," +startValue+"," +endValue +"," + time*1000 + ",'" +cssFormat +"')"
    var intervalID=setInterval(actionString,1000/fps)
    intervalArray.push(intervalID)
    
}
function animateRoutine(startTime,intervalLoc,objID,cssProperty,startValue,endValue,time,cssFormat){
     var tDate=new Date()
     var curTime=tDate.getTime()    
     if (curTime>=startTime+time){
         clearInterval(intervalArray[intervalLoc])
        // intervalArray.splice(intervalLoc,1)
         curValue=endValue
     }else{
         var curIteration=(curTime-startTime)    
         curValue=easing(curIteration,startValue,endValue-startValue,time)  
     }
     curFormattedValue=regXreplace(cssFormat,"{value}",curValue.toString())      
     document.getElementById(objID).style[cssProperty]=curFormattedValue;
}
function easing(t,b,c,d){
/**
    * Uniform speed between points.
    * @param {Number} t Time value used to compute current value.
    * @param {Number} b Starting value.
    * @param {Number} c Delta between start and end values.
    * @param {Number} d Total length of animation.
    * @return {Number} The computed value for the current animation frame.
    */
  
	var ts=(t/=d)*t;
	var tc=ts*t;
	return b+c*(tc + -3*ts + 3*t);

}
 function regXreplace(theString,searchString,replaceString){
    var re = new RegExp(searchString, "g");
	var mystring=new String(theString)
	results=mystring.replace(re,replaceString)		
	return results
}
 function hideElement(element_id){
         if (document.getElementById && document.getElementById(element_id) && document.getElementById(element_id).style)
        {
		    document.getElementById(element_id).style.visibility="hidden";
		    document.getElementById(element_id).style.display="none"
        };
 }
 function showElement(element_id){
        if (document.getElementById && document.getElementById(element_id) && document.getElementById(element_id).style)
        {
		    document.getElementById(element_id).style.visibility="visible";
		    document.getElementById(element_id).style.display=""
        };
 }
function checkscroll(fsid,objName, bg, contentTopMargin){
    if ( document.getElementById(fsid).style.visibility=="visible"){

         var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
         document.getElementById(bg).style.top=scrollTop + "px"
         document.getElementById(objName).style.top=String(Number(scrollTop+contentTopMargin)) +"px"
        // setTimeout("checkscroll('"+fsid+"','"+objName+ "','" + bg + "',"+contentTopMargin+")",1)
      }else{
     var selects =document.getElementsByTagName("SELECT")
      for (var i=0;i<selects.length;i++){
        selects[i].style.visibility="visible"
        selects[i].style.display=""
      }
      clearInterval(checkscrollInterval)
    }
    clearInterval(checkscrollInterval)
 }
