// DOM is ready, but not graphics.
window.addEvent('domready', function() {

  // Grab an array of elements to be animated.
  var list = $$('#offering_links div');

  // Initialise a counter for shape effects.
  var shapeCounter = 1;

  // Iterate each element.
  list.each(function(element) {

    // Set custom transition rate.
    var linkTinyBounce = new Fx.Transition(Fx.Transitions.Elastic, [.25, 10, 2]);

    // Create morph objects.

// 	Original: 
//	var linkFx = new Fx.Morph(element, {fps: 40, duration: 7000, transition: Fx.Transitions.Sine.easeInOut});
//	var linkFx2 = new Fx.Morph(element, {fps: 40, duration: 3000, transition: Fx.Transitions.Bounce.easeOut});

    var linkFx = new Fx.Morph(element, {fps: 40, duration: 2000, transition: Fx.Transitions.Sine.easeInOut});
    var linkFx2 = new Fx.Morph(element, {fps: 40, duration: 1000, transition: Fx.Transitions.Bounce.easeOut});

    var theTime = $time();
              
    var xPos = Math.sin(theTime) + 1;
    var yPos = Math.cos(theTime) + 1;

    var sign = 1;
    // Bad math day..
    if (shapeCounter%2 == 0) {
      sign = -1;
    } // if work

    linkFx.set({
      'left': (xPos + 0.5) * (window.getSize().x * sign),
      'top':  (yPos + 0.5) * (window.getSize().y * sign),
    });


    // Call every element back to a pattern. And make the type animate big-to-small.
    var tempLeft = (window.getSize().x / 2.2) + (Math.sin(Math.PI * (shapeCounter / 4.0)) * (140 * Math.sqrt(shapeCounter)));
    var tempTop  = (window.getSize().y / 2.5) + (Math.cos(Math.PI * (shapeCounter / 4.0)) * (142 * Math.sqrt(shapeCounter)));
    
    // Left / top position; width / height of spiral.
    var finalLeft = (window.getSize().x / 2.15) + (Math.sin(Math.PI * (shapeCounter / 4.0)) * (80 * Math.sqrt(shapeCounter)));
    var finalTop  = (window.getSize().y / 2.6) + (Math.cos(Math.PI * (shapeCounter / 4.0)) * (78 * Math.sqrt(shapeCounter)));

    linkFx.start({
        'display' : 'block',
        // Left-to-right position; width of spiral.
        'left': tempLeft * yPos,
        // Top-to-bottom position; height of spiral.
        'top':  tempTop * xPos,
        'font-size': ['400pt', '50pt']
      }).chain(function(){
        // executes immediately after completion of above effect
        linkFx2.start({
          'left': finalLeft,
          // Top-to-bottom position; height of spiral.
          'top':  finalTop,
          'font-size': ['50pt', '24pt']
        })});

    shapeCounter++;
  });    


}); // domready


// All graphics loaded.
window.addEvent('load', function() {


}); // load

