var Game = new Object();

Game.MARKUP = '<div id="game"></div>'
//Game.MARKUP = '<div id="game"><a id="game-close">Game goes here. Click to go back to the web page.</a></div>'


Game.insert = function() {
    // create game div
    $('#game').remove();
    $('body').append(Game.MARKUP);
    $("#game").flash
	 (
		{
		    src: "/_resx/js/flash/game/preloader.swf",
		    width: "100%",
		    height: "100%",
		    wmode: 'transparent'
		},
		{ version: 9 }
	 );

    $('html').css('overflow', 'hidden');
    $('body').addClass('game-mode');
    // scroll all the way over
    var left = $('#game').position().left + $('#game').width();
    var top = $('#game').position().top;
    $(document).scrollTo({ left: left, top: top }, 2000, { axis: 'yx', queue: true });

    // enable game closing
    $('#game-close').click(function() { Game.remove(); });

}

Game.remove = function() {
    $('body').removeClass('game-mode');
	$(document).scrollTo( { left:0, top:0 }, 2000, { axis:'xy', queue:true, onAfter:function(){ $('#game').remove(); $('html').css('overflow', 'auto'); } } );
}

Game.moveTo = function(n) {
    var nWindow = WindowSize.getPageSize();
    var nWidth = -(nWindow.windowWidth / 2) + n;
    var nLeft = "+=" + nWidth + "px";
    
    $(document).scrollTo({ left: nLeft }, 2000, { axis: 'x' });
}

Game.startPosition = function()
{
	// scroll all the way over
	var left = $('#game').position().left + $('#game').width();
	var top = $('#game').position().top;
	$(document).scrollTo( { left:left, top:top }, 3000, { axis:'yx', queue:true } );	
}

$(document).ready(function() {
    $("a[href*='#playgame']").click(function() {
        Game.insert();
        return false;
    })
});
