var $duration = 2;
var $$ = $.fn;
$$.extend({
	SplitID : function(){
		return this.attr('id').split('-').pop();
	},
	Slideshow : {
		Ready : function(duration){
			$('div.tmpSlideshowControl')
			.hover(
				function(){
					$(this).addClass('tmpSlideshowControlOn');
				},
				function(){
					$(this).removeClass('tmpSlideshowControlOn');
				}
			)
			.click(
				function(){
					$$.Slideshow.Interrupted = true;
					$('div.tmpSlide').fadeOut(500);
					$('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
					$('div#tmpSlide-' + $(this).SplitID()).fadeIn(500);
					$(this).addClass('tmpSlideshowControlActive');
				}
			);
			$duration = duration;
			this.Counter = 1;
			this.Interrupted = false;
			this.Transition(1);
		},
		Transition : function(key){
			if(this.Interrupted){
				return;
			}
			this.Last = this.Counter - 1;
			if(this.Last < 1){
				this.Last = $('div.tmpSlide').length;
			}
			$('div#tmpSlide-'+this.Last).fadeOut(
				2000,
				function(){
					$('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
					$('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
					$$.Slideshow.Counter++;
					if($$.Slideshow.Counter > $('div.tmpSlide').length){
						$$.Slideshow.Counter = 1;
					}
					setTimeout('$$.Slideshow.Transition();', $duration*100);
				}
			);
			if(key == 1)
				$('div#tmpSlide-' + ($$.Slideshow.Counter - 1)).fadeIn(0);
			else
				$('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn(2000);
		}
	}
});
