
$( document ).ready(
	function( )
	{
		$( "#header ").bind( "click", menuClick );
		createMenu( );
		loadPage( );
	}
);

function createMenu( )
{
	$( "img.menu" ).bind( "mouseover", menuMouseOver );
	$( "img.menu" ).bind( "mouseout", menuMouseOut );	
	$( "img.menu" ).bind( "click", menuClick );
}

function menuClick( )
{
	$("#content").slideUp( "slow" );
	$("#wlayer").fadeIn( "slow" );
}

function menuMouseOver( )
{
	$( "#puce_" + this.name ).css( "visibility", "visible" );
}

function menuMouseOut( )
{
	var id = getID( );
	
	if ( this.name != id || id == 0 )
	{
		$( "#puce_" + this.name ).css( "visibility", "hidden" );
	}
}

function getID( )
{
	var id = 500;
	
	var searchTerm = "lang=fr";
	var searchTermIndex = window.location.href.indexOf( searchTerm );

	if ( searchTermIndex != -1 )
	{
		id = 1;
	}

	searchTerm = "page=";
	searchTermIndex = window.location.href.indexOf( searchTerm );
	
	if ( searchTermIndex != -1 )
	{
		id = parseInt( window.location.href.substr( searchTermIndex + searchTerm.length ) ) || 0;
	}
	
	return id;
}

function loadPage( )
{
		var id = getID( );

		if ( id != 0 )
		{
			$( "#puce_" + id ).css( "visibility", "visible" );
		}
		
		$( "body" ).css( "backgroundImage", "url('themes/default/images/" + id + ".png')" );
		
		if ( id == 7 )
		{
			$( "body" ).css( "backgroundColor", "#EE4623" );
		}
		else if ( ( id == 0 ) || ( id == 1 ) || ( id == 2 ) || ( id == 101 ) || ( id == 129 ) || ( id == 127 ) || ( id >= 500 && id % 2 == 0 ) )
		{
			$( "body" ).css( "backgroundColor", "#000000" );
		}
		else
		{
			$( "body" ).css( "backgroundColor", "#FFFFFF" );
		}
		
		changeContainerBackground( id );
		
		if ( id == 2 )
		{
			initSlideshow( );
		}
		
		if ( id == 4 )
		{
			initSlideshow2( );
		}
		
		$( "#content" ).slideDown( "slow" );
		$( "#wlayer" ).fadeOut( "slow" );	
}

function changeContainerBackground( id )
{
	if( id == 101 )
	{
		$( "#container" ).css( "backgroundImage", "url(themes/default/images/bg_1.png)" );
	}
	else
	{
		$( "#container" ).css( "backgroundImage", "none" );
	}
}