
  var Screenshots = new Array();
for (i=1; i<=38; i++){ 
  Screenshots[i]= ["view/fun/img/background/b ("+i+").jpg"];
 } 

var InGame = false;
var ScreenChangeTimer = null;
var GModVersion = "0.1";
var iLastScreenshot = 0;

function ChangeBackground( newimg )
{
	var img = new Image()
	img.src = newimg;
	
	$(img).load( function() 
	{ 
		$( '#BackgroundImage' ).fadeOut( 1000, function() { $(this).css( "background-image", "URL('"+newimg+"')" ) } ).fadeIn( 2000 ); 
	} );
	
}


function RandomBackground()
{
	clearTimeout( ScreenChangeTimer );
	

	var screenshot = Screenshots[ iLastScreenshot ]
	iLastScreenshot++;
	if ( iLastScreenshot >= Screenshots.length ) iLastScreenshot = 0;
	
	ChangeBackground( screenshot );
	
	ScreenChangeTimer = setTimeout( RandomBackground, 60000 );

	
}



$( function()
{
	if ( navigator.userAgent.indexOf( "Valve Source Client" ) == -1 )
	{

		setTimeout( GarrysModInit, 500 );
		setTimeout( function(){ GotTicket() }, 1000 );
	}
	
	

});

function RaceVersion( cur )
{
	$( "#Version" ).html( "version (dev)  " + Math.min( Math.floor(cur), GModVersion ) );
	
	if ( cur < GModVersion )
	{
		setTimeout( function(){ RaceVersion( cur+1 ) }, 20 );
	}
	else
	{
		ButtonPressed( $( "#Version" ) );
	}
}

function GarrysModInit()
{
	$( "#MenuOptions" ).fadeIn( 1000 );

	$( "#Console" ).animate( {  opacity: 1 }, 2000 );
	$( "#Console" ).animate( {  opacity: 0.8 }, 15000 );
	$( '#BackgroundImage' ).fadeIn( 500, function(){ $("BODY").css( "background-color", "#131f2b" ) } );
	$( ".ingame" ).hide();
	$( "#Logo" ).animate( { top: 64, opacity: 1 }, 1000 );
	
	// Move the buttons in - except CloudButtons - that comes in later!
	$( ".BottomButtons" ).animate( { bottom: 20 }, 500 );	
	$( "#CloudboxButtons" ).stop()
	
	SetupButtons( ".BottomButtons" );	
	UpdateOptions( false );
	
	Screenshots.sort( function() {return 0.5 - Math.random()} )
	setTimeout( RandomBackground, 500 );
	
	$( "#Version" ).hide();
	setTimeout( function()
	{
		RaceVersion( 1 );
		$( "#Version" ).fadeIn( 2000 );
		
	}, 1500 );
	
	$( "BODY" ).click( function( e )
	{
		if ( e.srcElement == this && $( '#BackgroundImage' ).queue("fx").length == 0 )
		{
			//RunLua( 'surface.PlaySound("npc/scanner/scanner_nearmiss1.wav")');
			RandomBackground();
		}

	});
	
	UpdateCycler();
	
}




function StartGame(){
	setTimeout( function() { Print( "Lancement de la partie\n",50,255,50,255) } ,50)
	setTimeout( function() { Print( "\t Maps : 1/0.bsp\n",255,255,255,255) } ,300)
	setTimeout( function() { Print( "\t Gamemode : Voilà\n",255,255,255,255) } ,400)
	setTimeout( function() {  window.location = 'view/fun/loading.html'} ,1500)
}

function UpdateOptions( ingame )
{
	
		$( ".ingame" ).slideUp( 500 );
		$( "#BackgroundImage" ).fadeIn( 500 );
	
}



function SetupButtons( element )
{
	var Buttons = $(element).find( "A IMG" );
	
	$.each( Buttons, function()
	{
		$(this).parent().css( "position", "relative" );
		
		var text = $(this).attr( "alt" );
		var Tip = $( "<span class='ButtonName'>"+text+"</span>" );
		Tip.insertBefore( $(this) );
		
		$(this).hover( function()
		{
			Tip.show();
		},function()
		{
			Tip.hide();
		})
		
	})
	
}



function GotTicket(  )
{
	$( "#CloudboxButtons" ).animate( { bottom: 20 }, 250 );
	
	AddCycler( "Site en construction" );
}


var CyclerStats = new Array();
var iLastCycler = 0;

function AddCycler( str )
{
	CyclerStats.push( str );
	CyclerStats.sort( function() {return 0.5 - Math.random()} )
}

function UpdateCycler()
{
	$( "#Cycler" ).fadeOut( 1000, function(){ $( "#Cycler" ).html( CyclerStats[ iLastCycler ] )}).fadeIn( 1000 );
	setTimeout( UpdateCycler, 5000 );
	
	iLastCycler++;
	if ( iLastCycler >= CyclerStats.length ) iLastCycler = 0;
}

