var $$ = $.fn;
 
$$.extend({
  SplitID : function()
  {
    //return this.attr('id').split('-').pop();
	return this.attr("id").split("-")[1]*1-1;
  },
 
  Slideshow : {
    Ready : function()
    {
      $('#projectthumbbar li a')
        .hover(
          function() {
            $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow.Interrupted = true;
			
            $('#projectvisual li').hide();
            $('#projectthumbbar li a').removeClass('tmpSlideshowControlActive');
 
			$('#projectvisual li:eq(' + $(this).SplitID() +')').show()
            $(this).addClass('tmpSlideshowControlActive');
			
			return false;
          }		  
        );
 
      this.Counter = 1;
      this.Interrupted = false;
	  this.totalNum = $("#projectvisual li").length;
 
      this.Transition();
    },
 
    Transition : function()
    {
      if (this.Interrupted) {
        return;
      }
 		
		this.Last = this.Counter - 1;
 
      if (this.Last < 1) {
        this.Last = this.totalNum;
      }
 
      $('li#projectvis-' + this.Last).fadeOut(
        'slow',
        function() {
          $('#projectthumb-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
          $('#projectthumb-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
          $('li#projectvis-' + $$.Slideshow.Counter).fadeIn('slow');
 
          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > $$.Slideshow.totalNum) {
            $$.Slideshow.Counter = 1;
          }
 
          setTimeout('$$.Slideshow.Transition();', 5000);
        }
      );
	 	  
    }
  }
});
 
$(document).ready(

	
		function() {
			if ( $('#projectthumbbar li a').length > 1 ){
		    $$.Slideshow.Ready();
		  }
	}
  
);
