/* Megagram Fade Transition
 * Plugin for jQuery 1.3
 * License: GPLv3
 * Copyright 2009 Megagram, http://www.megagram.com/
 */

(function($){

  $.fn.mgFadeTransitionPrep = function()
  {
    var isFirst = true;
    return $(this).each(function()
    {
      var $this = $(this);
      if (!isFirst) $this.hide();
      isFirst = false;
      $this.css('position', 'absolute');
    }); // end each
  } // end mgFadeTransitionPrep

  $.fn.mgFadeTransition = function(speed)
  {
    var $set = $(this);
    var $old = $set.eq(0); // currently visible is at front
    var $new = $set.eq(1); // next to become visible is second
    $old.insertAfter($set.slice(-1)); // move the previous visible to end
    $new.fadeIn(speed);
    $old.fadeOut(speed);
  } // end mgFadeTransition

})(jQuery); // end wrapper

