LETTERS_SPEED = 2, DOTS_SPEED = 2, F = function(){};

animate_logo = function () {
  var r = Raphael("holder", 900, 165); 
  
  Words = function() {
    var words = $('#header span.expand');
    words.eq(0).animate({width:'162.5px', easing: 'swing'}, LETTERS_SPEED * 1100, F);
    words.eq(1).animate({width:'120px', easing: 'swing'}, LETTERS_SPEED * 1300, F);
    words.eq(2).animate({width:'115px', easing: 'swing'},  LETTERS_SPEED * 1500, F);
  }
  Words.reset = function() {
    $('#header span.expand').width('0px');
  }

  Circles = [];
  Circles.reset = function() {
    for(var i = 0; i < Circles.length; i++) {
      Circles[i].el.attr({cx: 300, cy: -112, r: 5, fill: "#a20035", "fill-opacity": 1, stroke: "#000", "stroke-width": 1})
    }
  };
  
  Circle = function(num) {
    if (Circles[num-1]) { // if circle already exists
      var circ = Circles[num-1];
      this.el  = circ.el;
      this.num = circ.num;
      this.cur = 0;
    } else { // ... or create the circle
      this.el   = r.circle(300, -112,5).attr({fill: "#a20035", "fill-opacity": 1, stroke: "#000", "stroke-width": 1});
      this.num  = num;
      this.cur  = 0;
      Circles[num-1] = this;
    }
    this.move();
    return this;
  }
  Circle.prototype.move = function() {
    var self = this, 
        next = (self.cur == 0 && self.num > 1);

    if (self.cur < self.num) {
      var cb = function() { 
        self.move(); 
        if (next) { new Circle(self.num - 1); } // create next node
      }
      var kf = Circle.frames[self.cur++];
      self.el.animate(kf, kf['seconds'](), cb);
    } else {
      if (self.num == 9) { new Words(); }
    };
  };
  Circle.frames = [{cx: 105,  cy: 113, r: 3,    fill: "#DFACAA",  seconds: function(){return DOTS_SPEED * 200} },
                   {cx: 85.5, cy: 124.5, r: 4,    fill: '#DFACAA',  seconds: function(){return DOTS_SPEED * 20} },
                   {cx: 62.5, cy: 124.5, r: 5,    fill: '#DFACAA',  seconds: function(){return DOTS_SPEED * 30} },
                   {cx: 43.5, cy: 113,   r: 5.5,  fill: '#D69494',  seconds: function(){return DOTS_SPEED * 40} },
                   {cx: 32.5, cy: 93.5,  r: 7,    fill: '#CD7E80',  seconds: function(){return DOTS_SPEED * 50} },
                   {cx: 32,   cy: 71,    r: 7.5,  fill: '#C46A6E',  seconds: function(){return DOTS_SPEED * 60} },
                   {cx: 43.5, cy: 52,    r: 8,    fill: '#BB575E',  seconds: function(){return DOTS_SPEED * 70} },
                   {cx: 63,   cy: 40.5,  r: 9,    fill: '#B3414F',  seconds: function(){return DOTS_SPEED * 80} },
                   {cx: 85.5, cy: 40.5,  r: 9.5,  fill: '#AA2841',  seconds: function(){return DOTS_SPEED * 90} },
                   {cx: 106,  cy: 53,    r: 10.5, fill: '#A20035',  seconds: function(){return DOTS_SPEED * 100} }];
  new Circle(10);
};


