/*
  slideShow
  specialized tool for animating slideShows on a metaSite.
  david mccombs w3Sys.com 12/2009
*/
var liveBoxes = new Array();

var liveBox = new Class({
   initialize: function(strtEl) {
      this.idx = 0; // to start
      this.els = new Array(); // all the elements
      strtEl.set('opacity',1);
      this.els.push( strtEl );
      strtEl.setStyle('display','block');
      var Next = strtEl.getNext();
      while( Next.get('class') == "twoSplit" )
      {
        Next.setStyle('display','none');
        Next.set('opacity',0);
        this.els.push( Next );
        Next = Next.getNext();
      }
      if( Next.get('class') == "twoSplitEnd" )
      {
        Next.setStyle('display','none');
        Next.set('opacity',0);
        this.els.push( Next );
      }
   },
   nextSlide: function() {
    this.Next = this.els[this.idx];
    if( $defined( this.Next ) )
    {
      this.Next.setStyle('display','none');
      this.idx = circleLoop(this.idx, this.els);
      this.Next = this.els[this.idx];
      if( $defined( this.Next ) )
        this.Next.setStyle('display','block');
    }
   },
   nextTweeningSlide: function() {
    this.Next = this.els[this.idx];
    if( $defined( this.Next ) )
    {
      this.Next.set( 'tween', { link: 'chain', onComplete: this.completeTweenSlide()  } ).fade('out');
    }
   },
   completeTweenSlide: function()
   {
      this.Next.setStyle('display','none');
      this.idx = circleLoop(this.idx, this.els);
      this.Next = this.els[this.idx];
      if( $defined( this.Next ) )
      {
        this.Next.setStyle('display','block');
        this.Next.fade('in');
      }
   }

});


// this comes up for me a lot, so make it a function
var circleLoop = function( inv, arry )
{
  return ((inv+1)<arry.length)?inv+1:0;
}

var nextLiveBox = 0;
var slidetimedelay = 4000;
// visible iterator with delay
var visIter = function()
{
    if( $defined(nextLiveBox) && $defined(liveBoxes[nextLiveBox]) && $defined(liveBoxes[nextLiveBox].nextTweeningSlide) )
    {
      liveBoxes[nextLiveBox].nextTweeningSlide();
    }
    nextLiveBox = circleLoop(nextLiveBox, liveBoxes);
    visIter.delay(slidetimedelay);
};

window.addEvent('domready', function(){
        $$('div.twoSplitStart').each( function(el){
          var livebx = new  liveBox(el);
          liveBoxes.push(livebx);
        });
        visIter.delay(slidetimedelay);

    });


