/**
 * Zine Website Scripts
 * ~~~~~~~~~~~~~~~~~~~~
 *
 * Some scripts for the Zine webpage.
 *
 * :copyright: 2008 by Armin Ronacher.
 * :license: BSD.
 */

var zine = {
  
  /* make a list an animated feature list */
  showAsSlideshow : function(expr, options) {
    options = options || {};
    var
      items = $('li', expr).hide(),
      index = -1,
      timeout = options.timeout || 4000,
      fadeTime = options.fadeTime || 'slow';

    if (!items.length)
      return;

    function nextImage() {
      if (index >= 0)
        $(items[index]).fadeOut(fadeTime);
      $(items[index = (index + 1) % items.length]).fadeIn(fadeTime);
      window.setTimeout(nextImage, timeout);
    }
    nextImage();
  },

  /* called on initializations */
  init : function() {

    /* add anchors to headlines */
    for (var i = 1; i <= 6; i++)
      for (var j = 0; j <= 1; j++)
        $('h' + i + (j == 1 ? ' a' : '') + '[@id]').each(function() {
          var anchor = $('<a class="anchor">¶</a>')
            .attr('href', '#' + $(this).attr('id'))
            .attr('title', 'Permalink to this headline')
            .appendTo(this);
        });
  }
};

// $(function() {
//   zine.init();
// });
