//$(function(){
  var timer;
  var count;
  var slides = $("div[id^='copy-']");
  var slides_len = $("div[id^='copy-']").length;

  $.each($('.nav li a'), function() {
    var id = $(this).attr('id');
    $('#' + id).click(function() {
      clearTimeout(timer);
      var copy = $("#copy-"+id).html();
      fadeInto('#main-copy',copy,'fast', -1);
      mpmetrics.track("click-" + id);
    });
  });

  function fadeInto(source,dest,speed, next) {
    var curwidth = $(source).css('margin-top');
    $(source).animate({'margin-top' : '100px', opacity: 0.0},speed, function() {
      $(source).html(dest).animate({'margin-top' : curwidth, opacity: 1},speed, function(){
        if (next != -1) {
          timer = setTimeout("cycleCopy("+ next +")",6000);
        }
      });
    });
  }

  function cycleCopy(count) {
    var next = (count + 1) % slides_len;
    var copy = $(slides[next]).html();
    fadeInto('#main-copy',copy,'slow',next);
  }
  mpmetrics.track("page");
  timer = setTimeout("cycleCopy(0)",6000);

//});

