1 goog.provide('lime.animation.Spawn');
  2 
  3 goog.require('lime.animation.Animation');
  4 goog.require('lime.animation.Delay');
  5 goog.require('lime.animation.Sequence');
  6 
  7 /**
  8  * Animations that are run parallel with each other.
  9  * Also accepts more than two animations
 10  * @param {lime.animation.Animation} one First animation.
 11  * @param {lime.animation.Animation} two Second animation.
 12  * @constructor
 13  * @extends lime.animation.Animation
 14  */
 15 lime.animation.Spawn = function(one, two) {
 16 
 17     lime.animation.Animation.call(this);
 18 
 19     var act = goog.array.toArray(arguments);
 20     if (goog.isArray(one)) act = one;
 21 
 22     if (act.length > 2) {
 23 
 24         this.one = act.shift();
 25         this.two = new lime.animation.Spawn(act);
 26     }
 27     else {
 28         this.one = act[0];
 29         this.two = act[1];
 30     }
 31     var d1 = this.one.duration_;
 32     var d2 = this.two.duration_;
 33 
 34     this.setDuration(Math.max(d1, d2));
 35 
 36     var delay = new lime.animation.Delay;
 37 
 38     if (d1 > d2) {
 39         this.two = new lime.animation.Sequence(this.two,
 40             delay.setDuration(d1 - d2));
 41     }
 42     else if (d1 < d2) {
 43         this.one = new lime.animation.Sequence(this.one,
 44             delay.setDuration(d2 - d1));
 45     }
 46 
 47 };
 48 goog.inherits(lime.animation.Spawn, lime.animation.Animation);
 49 
 50 /**
 51  * @inheritDoc
 52  * @see lime.animation.Animation#initTarget
 53  */
 54 lime.animation.Spawn.prototype.initTarget = function(target) {
 55     lime.animation.Animation.prototype.initTarget.call(this, target);
 56 
 57     this.one.status_ = 1;
 58     this.two.status_ = 1;
 59 };
 60 
 61 /**
 62  * @inheritDoc
 63  * @see lime.animation.Animation#updateAll
 64  */
 65 lime.animation.Spawn.prototype.updateAll = function(t, targets) {
 66     if (this.status_ == 0) return;
 67     var i = targets.length;
 68     while (--i >= 0) {
 69         this.getTargetProp(targets[i]);
 70     }
 71     this.one.updateAll(t, targets);
 72     this.two.updateAll(t, targets);
 73     
 74     return t;
 75 };
 76 
 77 /**
 78  * @inheritDoc
 79  * @see lime.animation.Animation#reverse
 80  */
 81 lime.animation.Spawn.prototype.reverse = function() {
 82     return new lime.animation.Spawn(this.one.reverse(), this.two.reverse());
 83 };
 84