﻿//CONSTRUCTOR

function TweenManager(oControl, oRootElement) {

  //PROPERTIES
  this.__oControl = oControl;
  this.__oRootElement = oRootElement;
  var __sStoryboard = new String();
  
  var __aTween = [];
 

  //PUBLIC
  
  
  //ADD REMOVE GET STORYBOARDS
     this.add = function(sAniName, sAniType) {
        var nLength = __aTween.length;
        for(i = 0; i < nLength; i++) {
         if(__aTween[i].sName == sAniName) {
           return false;
         }
        }
         __aTween.push({sName:sAniName, tTween:this.animationType(sAniType)});
        return true;
    }

   
    this.remove = function(sAniName) {
        var nLength = __aTween.length;
        for(i = 0; i < nLength; i++) {
            if(__aTween[i].sName == sAniName) {
                    __aTween.splice(1,i);
                    return true;
            }
        }
    }

    this.Get = function(sAniName) {
      var nLength = __aTween.length; 
      for(i = 0; i < nLength; i++) {
        if(__aTween[i].sName == sAniName) {
           return __aTween[i].tTween;
        }
      }
    }
   
   
   //DETERMINES ANIMATION TYPE LOADS INSTANCE OF CLASS
   this.animationType = function(sAniType) { 
        
        var aniType;
        
        switch(sAniType) {
        case "Double":
        aniType = new Double(this.__oControl);
        break;
        case "KeyFrame":
        aniType = new KeyFrame(this.__oControl);
        default:
        }
    
    return aniType;
   }
   

   
   
   //COMPILE ANIMATION PROPERTIES RETURN STORYBOARD ELEMENT
   this.runAni = function(oTargetElement, sTargetProp, nFrom, nTo, nDuration) {
   
    //Animation Build
     this.animation =  this.Get(__sStoryboard).buildTween(__sStoryboard, 
                                     oTargetElement,
                                     sTargetProp,
                                     nFrom,
                                     nTo,
                                     nDuration);
   
   //Add animation to Canvas.Resources                           
   this.__oRootElement.Resources.add(this.animation);
   return this.animation;
  }
   
}


