var $$ = $.fn;
$$.extend({
  SplitID2 : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow2 : {
    Ready2 : function()
    {
      $('div.tmpnewsSlideshowControl')
        .hover(
          function() {
            $(this).addClass('tmpnewsSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpnewsSlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow2.Interrupted2 = true;

            $('div.tmpnewsSlide').hide();
            $('div.tmpnewsSlideshowControl').removeClass('tmpnewsSlideshowControlActive');
            $('div#tmpnewsSlide-' + $(this).SplitID2()).show()
            $(this).addClass('tmpnewsSlideshowControlActive');
          }
        );

      this.Counter2 = 1;
      this.Interrupted2 = false;

      this.Transition2();
    },

    Transition2 : function()
    {
      if (this.Interrupted2) {
        return;
      }
	  this.Howmany2 = ($('div#howmanynews').text());
      this.Last2 = this.Counter2 - 1;
      if (this.Last2 < 1) {
        this.Last2 = this.Howmany2; // total divs
      }
      $('div#tmpnewsSlide-' + this.Last2).fadeOut(
        'slow',
        function() {
        $('div#tmpnewsSlideshowControl-' + $$.Slideshow2.Last2).removeClass('tmpnewsSlideshowControlActive');
        $('div#tmpnewsSlideshowControl-' + $$.Slideshow2.Counter2).addClass('tmpnewsSlideshowControlActive');
        $('div#tmpnewsSlide-' + $$.Slideshow2.Counter2).fadeIn('slow');
		$('span#current_news_item').text($$.Slideshow2.Counter2);
        $$.Slideshow2.Counter2++;
        if ($$.Slideshow2.Counter2 > $$.Slideshow2.Howmany2) { // total divs
            $$.Slideshow2.Counter2 = 1;
          }

          setTimeout('$$.Slideshow2.Transition2();', 8000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow2.Ready2();
  }
);