/* Slideshow code from: http://www.spicypeanut.net/Slideshow/Slideshow.html */

var $$ = $.fn;

$$.extend({
    SplitID: function() {
        return this.attr('id').split('-').pop();
    },

    Slideshow: {
        Ready: function() {
            $('div.tmpSlideshowControl')
        .hover(
          function() {
              $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
              $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
              $$.Slideshow.Interrupted = true;

              $('div.tmpSlide').hide();
              $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

              $('div#tmpSlide-' + $(this).SplitID()).show()
              $(this).addClass('tmpSlideshowControlActive');
          }
        );

            this.Counter = 1;
            this.Interrupted = false;

            this.Transition();
        },

        Transition: function() {
            if (this.Interrupted) {
                return;
            }

            this.Last = this.Counter - 1;

            if (this.Last < 1) {
                this.Last = 5;
            }

            $('div#tmpSlide-' + this.Last).fadeOut(
        'slow',
        function() {
            $('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
            $('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
            $('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');

            $$.Slideshow.Counter++;

            if ($$.Slideshow.Counter > 5) {
                $$.Slideshow.Counter = 1;
            }

            setTimeout('$$.Slideshow.Transition();', 5000);
        }
      );
        }
    }
});

$(document).ready(
  function() {
      $$.Slideshow.Ready();
  }
);


/*var timer = "";			// our timer
var timerSeconds = 6;	// interval between switches
var timerOn = 1;		// which element are we on currently
var lastSpotlight = 0;		// the last element
var playing = true;
function swap(el) {
	// they clicked, clear mouseover
	lastSpotlight = 0;
	if ( playing === false ) playing = true; // we want the playPause() to pause
	playPause();
	change(el);
}

function change(idx) {
	timerOn = idx;
  
  for( var i=1; i<=7; i++ ) {
    var el = document.getElementById('Spotlight'+i);
    if (el) //el.style.display = (i===idx ? "block" : "none");
    {
        //JasonM: 11-3-2010, jQuery Fade effect added.
        if (i === idx)
            $(el).stop().fadeIn('slow');
        else
            $(el).stop().fadeOut('slow');
    }
  }
}

function startTimer() {
	if ( timer === "" ) timer = setTimeout("doTimer()", timerSeconds * 1000)
}
function doTimer() {
	timer = "";
	if ( playing === true && lastSpotlight === 0 ) {
		timerOn++;
		if ( timerOn === 4 ) {
			timerOn = 1;
		}
		change(timerOn);
		startTimer();
	}
}

function playPause() {
	if( playing === true ) {
		timer = "";
		playing = false;
	} else {
		startTimer();
		playing = true;
	}
  
  for( var i=1; i<=7; i++ ) {
    var el = document.getElementById('imgPlayPause'+i);
    if( el ) el.src = (playing ? "/files/PageLayoutImages/bn_Pause.gif" : "/files/PageLayoutImages/bn_Play.gif");
  }
}

function spotlightOver(el) {
	lastSpotlight = timerOn;
//	playPause();
	change(el);
}
function spotlightOut() {
	if ( lastSpotlight > 0 ) {
		change(lastSpotlight);
		lastSpotlight = 0;
		startTimer();
	}
}
startTimer();
*/
