var CSS_SHOW_ELEMENT = { opacity: 1.0, display: '' };
var CSS_HIDE_ELEMENT = { opacity: 0.0, display: 'none' };

function GameInfoSlideshow( prop ) {
    this.timeOut = (prop && prop.timeOut) ? prop.timeOut: 5000;
    this.index = 0;
    this.count = $("#game-info-menu-ul li").size();
    
    this.slide = function() {
        $("#game-info-menu-ul li:eq("+(this.index++)+") img").fadeOut("slow");
        $("#game-info-pictures").scrollTo( $("#game-info-pictures li").eq(this.index), 500 );
        if( this.index >= this.count ) {
            this.index = 0;

            setTimeout( function() { $("#game-info-pictures").stop().scrollTo(  $("#game-info-pictures li").eq( 0 ) ) }, 500 );
        }

        $("#game-info-menu-ul li:eq("+this.index+") img").fadeIn("normal");


    }

    this.jumpTo = function ( to ) {
        if( to >= 0 && to < this.count && to != this.index ) {
            $("#game-info-menu-ul li:eq("+this.index+") img").stop().hide().fadeOut("slow");
            $("#game-info-pictures").stop().scrollTo( $("#game-info-pictures li").eq(to), 500 );
            $("#game-info-menu-ul li:eq("+to+") img").stop().show().fadeIn("normal");

            this.index = to;
        }
    }


    // prepare for slideing
    $("#game-info-menu-ul li:not(:first) img").hide();
    $("#game-info-menu-ul li:first").addClass( 'active' );

    $("#game-info-pictures").scrollTo( $("#game-info-pictures li:first") );
    $("#game-info-pictures li:first").clone().appendTo("#game-info-pictures ul");
    $("#game-info-menu-ul-events li").each( function ( index ) { $(this).attr( "id", "game-info-menu-item-"+index ); } ); 

       try {
            if( this_is_so_wrong ) {
                var offset = $("#game-info-menu-ul").offset();
                $("#game-info-menu-ul-events").css( { position: 'absolute', left: "14px", top: offset.top + "px", width: "934px" } );
            }
        } catch(e) {}


    this.start = function() {
        this.intervalID = setInterval( gameInfoSlideShowTick, this.timeOut );
    }

    this.stop = function() {
        clearInterval( this.intervalID );
    }
    
    this.showTimeout = function() {
        alert( this.timeOut );
    }
}

var gameInfoSlideShow;

function gameInfoSlideShowTick() {
    gameInfoSlideShow.slide();
}

$(document).ready( function() {
    gameInfoSlideShow = new GameInfoSlideshow();
    $("#game-info-menu ul").hover(
        function() {
            gameInfoSlideShow.stop();
        }, 
        function() {
            gameInfoSlideShow.start();
        }
    );


    $("#game-info-menu-ul-events li").mouseenter( function() {
        var index = $(this).attr("id");
        index = index.replace( "game-info-menu-item-", "" );

        gameInfoSlideShow.jumpTo( index );
    } );

    gameInfoSlideShow.start();
} );


