var $$ = $.fn;

//$('div#tmpSlide-1').show()

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

    Slideshow : {
        Ready : function() {
            $('div.tmpSlideshowControl')
            .hover(
                function() {
                    $(this).addClass('tmpSlideshowControlOn');
                },
                function() {
                    $(this).removeClass('tmpSlideshowControlOn');
                }
            )
            .click(
                function() {
                    $$.Slideshow.Interrupted = true;

                    $('div.tmpSlide').hide();
                    $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');
                    $('div#tmpSlide-' + $(this).SplitID()).show()

                    $(this).addClass('tmpSlideshowControlActive'); 

                    $('div#contBut').removeClass('remotebuttonOff');
                    $('div#contBut').addClass('remotebuttonOn'); 
                }
            );

        
        var randomnumber;
        var tNumb;
        tNumb = ReadCookie('SGL');

		//alert(ReadCookie('SGL'));
		
        if ((isNaN(tNumb)== true) || (tNumb != "")) {
            randomnumber=tNumb;
        } else {
            randomnumber=Math.floor(Math.random() * 10);
        }


        this.Counter = randomnumber;
        this.Interrupted = false;
        this.Transition();
    },

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

        this.Last = this.Counter - 1;

        if (this.Last < 1) {
            this.Last = 9;
        }

    $('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');

                $$.Slideshow.Counter++;

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

                setTimeout('$$.Slideshow.Transition();', 10000);
            });
        },
    PlayRotation : function() {
    
        $('div#contBut').addClass('remotebuttonOff');
        $('div#contBut').removeClass('remotebuttonOn'); 

        (this.Counter)++;
        this.Interrupted = false;
        this.Transition();
       
        } 
    }
});

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

);

function play(){
    $$.Slideshow.PlayRotation();
    return false;
}
