
function Anim(num_frames,obj){
    this.animframes=new Array();
    this.current_frame=0;
    this.total_frames=num_frames;
    this.obj=obj;
}

Anim.prototype.tick=function(){
    if (this.current_frame<this.total_frames){
        this.current_frame++;
        this.obj.style.left=this.frameLeft(this.current_frame)+'px';
        this.obj.style.top=this.frameTop(this.current_frame)+'px';
        this.obj.style.width=this.frameWidth(this.current_frame)+'px';
        this.obj.style.height=this.frameHeight(this.current_frame)+'px';
        newopacity=this.frameOpacity(this.current_frame);
        if (this.obj.filters&&this.obj.filters[0]){
        if (typeof this.obj.filters[0].opacity=="number"){ //if IE6+
        this.obj.filters[0].opacity=(newopacity*100)
        }
        else{ //else if IE5.5-
        this.obj.style.filter="alpha(opacity="+(newopacity*100)+")"
        }
        }
        else if (this.obj.style.MozOpacity){
        this.obj.style.MozOpacity=newopacity
        }
        else if (this.obj.style.KhtmlOpacity){
        this.obj.style.KhtmlOpacity=newopacity
        }
        else
        {
        this.obj.style.opacity=newopacity
        }
        return true;
    }
    else
    {
        return false;
    }
}


Anim.prototype.addKeyFrame=function(frame_number, key_frame){
    this.animframes[this.animframes.length]=Array(frame_number,key_frame);
}

Anim.prototype.reset=function(){
    this.current_frame=0;
}

Anim.prototype.frameLeft=function(frame_number){
    var totalweight=0;
    var totalleft=0;
    //loop though the key frames and calculate the change in Left
    for(n=0; n<(this.animframes.length); n++){
        theweight=(1/((Math.abs(this.animframes[n][0]-frame_number))+0.000000001));
        totalweight=totalweight+theweight;
        totalleft=totalleft+this.animframes[n][1].left*theweight;
    }
    thisleft=totalleft/totalweight;
    
    return Math.ceil(thisleft);
}

Anim.prototype.frameWidth=function(frame_number){
    var totalweight=0;
    var totalwidth=0;
    //loop though the key frames and calculate the change in Left
    for(n=0; n<(this.animframes.length); n++){
        theweight=(1/((Math.abs(this.animframes[n][0]-frame_number))+0.000000001));
        totalweight=totalweight+theweight;
        totalwidth=totalwidth+this.animframes[n][1].width*theweight;
    }
    thiswidth=totalwidth/totalweight;
    
    return Math.ceil(thiswidth);
}

Anim.prototype.frameHeight=function(frame_number){
    var totalweight=0;
    var totalheight=0;
    //loop though the key frames and calculate the change in Left
    for(n=0; n<(this.animframes.length); n++){
        theweight=(1/((Math.abs(this.animframes[n][0]-frame_number))+0.000000001));
        totalweight=totalweight+theweight;
        totalheight=totalheight+this.animframes[n][1].height*theweight;
    }
    thisheight=totalheight/totalweight;
    
    return Math.ceil(thisheight);
}

Anim.prototype.frameTop=function(frame_number){
    var totalweight=0;
    var totaltop=0;
    //loop though the key frames and calculate the change in Left
    for(n=0; n<(this.animframes.length); n++){
        theweight=(1/((Math.abs(this.animframes[n][0]-frame_number))+0.000000001));
        totalweight=totalweight+theweight;
        totaltop=totaltop+this.animframes[n][1].top*theweight;
    }
    thistop=totaltop/totalweight;
    
    return Math.ceil(thistop);
}

Anim.prototype.frameOpacity=function(frame_number){
    var totalweight=0;
    var totalopacity=0;
    //loop though the key frames and calculate the change in Left
    for(n=0; n<(this.animframes.length); n++){
            theweight=(1/((Math.abs(this.animframes[n][0]-frame_number))+0.000000001));
            totalweight=totalweight+theweight;
            totalopacity=totalopacity+this.animframes[n][1].opacity*theweight;
    }
    thisopacity=totalopacity/totalweight;
    
    return Math.ceil(thisopacity*100)/100;
}

function keyFrame(){
    this.height=0;
    this.width=0;
    this.opacity=1;
    this.left=0;
    this.top=0;
}

var photoAnim;
var textAnim;

function animate_photo(initx,inity){
    photoAnim=new Anim(30,document.getElementById('photo'));
    var myFrame=new keyFrame();
    myFrame.opacity=0;
    myFrame.left=initx;
    myFrame.top=inity;
    photoAnim.addKeyFrame(0,myFrame);
    var myFrame3=new keyFrame();
    myFrame3.left=730;
    myFrame3.top=20;
    myFrame3.height=150;
    myFrame3.width=150;
    myFrame3.opacity=1;
    photoAnim.addKeyFrame(30,myFrame3);
}
function animate_text(){
    textAnim=new Anim(30,document.getElementById('maintext'));
    var myFrame=new keyFrame();
    myFrame.opacity=0;
    myFrame.left=400;
    myFrame.top=131;
    myFrame.height=5;
    myFrame.width=460;
    textAnim.addKeyFrame(0,myFrame);
    var myFrame2=new keyFrame();
    myFrame2.left=400;
    myFrame2.top=131;
    myFrame2.height=360;
    myFrame2.width=460;
    myFrame2.opacity=1;
    textAnim.addKeyFrame(30,myFrame2);
}
function loaded_document(){
    animate_photo(0,0);
    animate_text();
    animate();
}
function dointro(thelink,person_number){
    document.getElementById("photo").src=getimage(person_number);
    document.getElementById("maintext").innerHTML=getdescription(person_number);
    
    //animate_photo(thelink.offsetLeft+thelink.offsetParent.offsetLeft+32,thelink.offsetTop+thelink.offsetParent.offsetTop+32);
    animate_photo(thelink.offsetLeft+32,thelink.offsetTop+32);
    animate_text('');
    animate();
}
function animate(){
    if(photoAnim.tick() && textAnim.tick()) timerID = setTimeout("animate()", 1);
}

function blank(){}

function generatelinks(){
    divs=document.getElementsByTagName("div");
    links="";
    for(n=0; n<divs.length; n++){
        if (divs[n].className=="person"){
            hs=divs[n].getElementsByTagName("h2");
            for(cnt=0; cnt<hs.length; cnt++){
                if (hs[cnt].className=="name") name=hs[cnt].innerHTML;
            }
            hs=divs[n].getElementsByTagName("img");
            for(cnt=0; cnt<hs.length; cnt++){
                if (hs[cnt].className=="smallimage") smallimage=hs[cnt].src;
                if (hs[cnt].className=="largeimage") largeimage=hs[cnt].src;
            }
            links=links+"<a href=\"javascript: blank();\" onclick=\"dointro(this,"+n+");\" class=\"photo\"><img style=\"border: 0px; margin: 0px; height: 75px; width: 75px;\" src=\""+smallimage+"\" alt=\""+name+"\" /></a>"
            divs[n].style.display='none'; 
        }
    }
    document.getElementById("photoblock").innerHTML=links;
    document.getElementById("animcontainer").style.display='';
}


function getdescription(person_number){
    divs=document.getElementsByTagName("div");
    if (divs[person_number].className=="person"){
        hs=divs[person_number].getElementsByTagName("div");
        for(cnt=0; cnt<hs.length; cnt++){
            if (hs[cnt].className=="description") description=hs[cnt].innerHTML;
        }
    }
    return description;
}
function getimage(person_number){
    divs=document.getElementsByTagName("div");
    hs=divs[person_number].getElementsByTagName("img");
    for(cnt=0; cnt<hs.length; cnt++){
        if (hs[cnt].className=="smallimage") smallimage=hs[cnt].src;
        if (hs[cnt].className=="largeimage") largeimage=hs[cnt].src;
    }
    return largeimage;
}
