/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var $j = jQuery.noConflict();

var $$j = $j.fn;

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

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

                    $j('div.tmpSlide').hide();
                    $j('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

                    $j('div#tmpSlide-' + $j(this).SplitID()).show()
                    $j(this).addClass('tmpSlideshowControlActive');
                }
                );

            this.Counter = 1;
            this.Interrupted = false;

            this.Transition();
        },

        Transition : function()
        {
            var numNews = $j("#tmpSlideshowControls div").length;
            if (this.Interrupted) {
                return;
            }

            this.Last = this.Counter - 1;

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

            $j('div#tmpSlide-' + this.Last).fadeOut(
                'slow',
                function() {
                    $j('div#tmpSlideshowControl-' + $$j.Slideshow.Last).removeClass('tmpSlideshowControlActive');
                    $j('div#tmpSlideshowControl-' + $$j.Slideshow.Counter).addClass('tmpSlideshowControlActive');
                    $j('div#tmpSlide-' + $$j.Slideshow.Counter).fadeIn('slow');

                    $$j.Slideshow.Counter++;

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

                    setTimeout('$$j.Slideshow.Transition();', 15000);
                }
                );
        }
    }
});

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