var $ss = jQuery.noConflict();

var jQuerySlideshow = $ss.fn;
var successStoryrTansitionTime = 5000;

jQuerySlideshow.extend({
  SplitID : function()
  {
	return this.attr('id').split('-').pop();
  },

  Slideshow : {
	Ready : function()
	{
	  $ss('.tmpSlideshowControl a')
		.click(
		  function() {
			//jQuerySlideshow.Slideshow.Interrupted = true;
			jQuerySlideshow.Slideshow.Counter = jQuerySlideshow.Slideshow.Last;
			jQuerySlideshow.Slideshow.Counter = $ss(this).parent().SplitID();

			$ss('div.tmpSlide').hide();
			$ss('.tmpSlideshowControl a').removeClass('act');

			$ss('div#tmpSlide-' + $ss(this).parent().SplitID()).show();
			$ss(this).addClass('act');

			return false;
		  }
		);

	  jQuerySlideshow.Slideshow.Counter = 1;
	  jQuerySlideshow.Slideshow.Interrupted = false;

	  this.Transition();
	},

	Transition : function()
	{
	  if (jQuerySlideshow.Slideshow.Interrupted) {
		return;
	  }

	  jQuerySlideshow.Slideshow.Last = jQuerySlideshow.Slideshow.Counter - 1;

	  if (jQuerySlideshow.Slideshow.Last < 1) {
		jQuerySlideshow.Slideshow.Last = $ss('div.tmpSlide').size();
	  }

	  $ss('div#tmpSlide-' + jQuerySlideshow.Slideshow.Last).fadeOut(
		'slow',
		function() {
		  $ss('#tmpSlideshowControl-' + jQuerySlideshow.Slideshow.Last + ' a').removeClass('act');
		  $ss('#tmpSlideshowControl-' + jQuerySlideshow.Slideshow.Counter + ' a').addClass('act');
		  $ss('div#tmpSlide-' + jQuerySlideshow.Slideshow.Counter).fadeIn('slow');
		  var elementHeight = $ss('div#tmpSlide-' + jQuerySlideshow.Slideshow.Counter).height();
		  $ss('div#tmpSlide-' + jQuerySlideshow.Slideshow.Counter).parent().height(elementHeight);

		  jQuerySlideshow.Slideshow.Counter++;

		  if (jQuerySlideshow.Slideshow.Counter > $ss('div.tmpSlide').size()) {
			jQuerySlideshow.Slideshow.Counter = 1;
		  }

		  setTimeout('jQuerySlideshow.Slideshow.Transition();', successStoryrTansitionTime);
		}
	  );
	}
  }
});

$ss(document).ready(function() {
	var successStoryslideshowTransitionTime = $ss('#slideshowTransitionTime');
	if (successStoryslideshowTransitionTime.html() > 0) {
		successStoryrTansitionTime = successStoryslideshowTransitionTime.html() * 1000;
	}
	jQuerySlideshow.Slideshow.Ready();
});

