var $$ = $.fn;

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

  Slideshow : {
    Ready : function()
    {
      $('div.tmpSlideshowControl')
        .mouseover(
          function() {
            $$.Slideshow.Interrupted = false;
		
            $('div.tmpSlide').hide();
            $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
						for(i=1;i<=3;i++){
							if(i != $(this).SplitID()){
								document.getElementById("slidebtl"+i).style.display = "none";
								document.getElementById("tmpSlideshowControl-"+i).style.opacity = "0.3";
								document.getElementById("tmpSlideshowControl-"+i).style.filter = "alpha(opacity=30)";
							}else{
								document.getElementById("slidebtl"+i).style.display = "";	
								document.getElementById("tmpSlideshowControl-"+i).style.opacity = "1";
								document.getElementById("tmpSlideshowControl-"+i).style.filter = "alpha(opacity=100)";
							}
						}
            $('div#tmpSlide-' + $(this).SplitID()).show()
            $(this).addClass('tmpSlideshowControlActive');
            //alert($(this).SplitID());
            this.Counter = $(this).SplitID() - 1;
            //if(this.Counter > 3) this.Counter = 1;
            clearTimeout(tmptimer);
            tmptimer = setTimeout('$$.Slideshow.Transition();', 5000);
          }
        )
        .mouseout(
          function(){
            //alert(1);
          }
        );

      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 = 3;
      }

      $('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');
					for(i=1;i<=3;i++){
						if(i != $$.Slideshow.Counter){
							document.getElementById("slidebtl"+i).style.display = "none";
							document.getElementById("tmpSlideshowControl-"+i).style.opacity = "0.3";
							document.getElementById("tmpSlideshowControl-"+i).style.filter = "alpha(opacity=30)";
						}else{
							document.getElementById("slidebtl"+i).style.display = "";	
							document.getElementById("tmpSlideshowControl-"+i).style.opacity = "1";
							document.getElementById("tmpSlideshowControl-"+i).style.filter = "alpha(opacity=100)";
						}
					}
          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > 3) {
            $$.Slideshow.Counter = 1;
          }

          tmptimer = setTimeout('$$.Slideshow.Transition();', 5000);
        }
      );
    }
  }
});

$(document).ready(
  function() {
    $$.Slideshow.Ready();
  }
);
