
function startChangePrototype(property,startValue,endValue,timeForChange,numberOfChanges,power,calculateFunction,onFinish){
  var changeSet = Array();
  changeSet["property"] = property;
  changeSet["startValue"] = startValue;

  changeSet["currentValue"] = startValue;
  changeSet["endValue"] = endValue;
  changeSet["timeForChange"] = timeForChange;
  changeSet["numberOfChanges"] = numberOfChanges;
  changeSet["power"] = power;
  changeSet["timePerChange"] = timeForChange / numberOfChanges;
  changeSet["currentChange"] = 0;
  changeSet["onFinish"] = onFinish;

  changeSet["calculateFunction"] = calculateFunction;
  
  /* Create this.changes if Necessary */
  if(!this.changes){ this.changes = Array() }
  
  /* Clear the running interval if we're already changing this property */
  if(this.changes[property]){
      clearInterval(this.changes[property].interval);
      if(this.changes[property]["onFinish"]) this.changes[property]["onFinish"](this);
    }
  
  /* Set the new Property Changes */
  this.changes[property] = changeSet;

  /* Set Interval And Start Changes */
  this.changes[property].interval = setInterval("document.getElementById('" + this.id + "').nextChange('"+property+"')",changeSet["timePerChange"]);

  

}

function nextChangePrototype(id){
  changeSet = this.changes[id];
  
  
  //if(changeSet["currentChange"] == 0) eval("document.getElementById('"+this.id+"')."+changeSet["property"]+" = "+changeSet["startValue"]);
  
  if(++changeSet["currentChange"] == changeSet["numberOfChanges"]){
    clearInterval(this.changes[id].interval);
    if(changeSet["onFinish"]) changeSet["onFinish"](this);
    nextValue = changeSet["endValue"];
  } else {
    /* Calculate next Value */
    if(changeSet["calculateFunction"]){
      nextValue = changeSet["calculateFunction"](changeSet["startValue"],changeSet["endValue"],changeSet["currentChange"],changeSet["numberOfChanges"])
    } else {
      nextValue = Math.pow( (changeSet["currentChange"] /  changeSet["numberOfChanges"]), changeSet["power"]);
      
      nextValue = nextValue * (changeSet["endValue"] - changeSet["startValue"]) + changeSet["startValue"];
      
      nextValue = parseInt(nextValue)
      
    } 
  }
  

  
  eval("document.getElementById('"+this.id+"')."+changeSet["property"]+" = '"+nextValue+"'");

}


function initChangeOverTimeSetup(){
   
  divs = document.getElementsByTagName("div");

  //Apply Start Change to Divs
  for(var i = 0; i < divs.length; i++){
    divs[i].startChange = startChangePrototype;
    divs[i].nextChange = nextChangePrototype;
  }
  
  imgs = document.getElementsByTagName("img");

  //Apply Start Change to Images
  for(var i = 0; i < imgs.length; i++){
    imgs[i].startChange = startChangePrototype;
    imgs[i].nextChange = nextChangePrototype;
  }  
  
}

window.onload = initChangeOverTimeSetup;

