function InitGallery( )
{
	$( "#GalleryDiv" ).data( "GalleryPos", 0 );
	function MoveRight( )
	{
		$( "#GalleryScrollDiv" ).stop( true, true );
		var I = $( "#GalleryScrollDiv>img" );
		var NumItems = I.length;
		
		
		var CurrentScrollPos = Math.abs( parseInt( $( "#GalleryScrollDiv" ).css( 'marginLeft' ) ) );
		var MaxScroll = 0;
		$( I ).each(
			function( )
			{
				MaxScroll +=  $( this ).outerWidth( );
			}
		);
		var Padding =  parseInt( $( I[ I.length-1 ] ).css( 'padding-right' ) );
		MaxScroll -= Padding;
		MaxScroll -= $( '#GalleryWindowDiv' ).width( );


		
		// Calc the image position
			var GalleryPos = $( "#GalleryDiv" ).data( "GalleryPos" ) + 1;
			if( GalleryPos >= NumItems )
				GalleryPos = NumItems - 1;

			
		
		// Calculate new pos
			var Pos = 0;
			for( var x = 0; x < GalleryPos; x++ )
				Pos += $( I[ x ] ).outerWidth( );

				
				
			if( Pos >= MaxScroll )
			{
				Pos = MaxScroll;
				$( "#GalleryRightArrow" ).attr( "src", "/images/gallery_ends/gallery_r_end.gif" ); // Hit the end
			}

			if( Pos != CurrentScrollPos ) // We moved
			{
				$( "#GalleryScrollDiv" ).animate( { 'margin-left': -Pos } );
				$( "#GalleryDiv" ).data( "GalleryPos", GalleryPos );
				// Put the other arrow back - not at the end any more
				$( "#GalleryLeftArrow" ).attr( "src", "/images/gallery_ends/gallery_l.gif" );
			}
	}

	
	
	function MoveLeft( )
	{
		$( "#GalleryScrollDiv" ).stop( true, true );
		var I = $( "#GalleryScrollDiv>img" );
		var NumItems = I.length;
		
		
		var CurrentScrollPos = Math.abs( parseInt( $( "#GalleryScrollDiv" ).css( 'marginLeft' ) ) );



		// Calc the image pos
			var GalleryPos = $( "#GalleryDiv" ).data( "GalleryPos" ) - 1;
			if( GalleryPos < 0 )
				GalleryPos = 0;

			

		// Calculate new pos
			var Pos = 0;
			for( var x = 0; x < GalleryPos; x++ )
				Pos += $( I[ x ] ).outerWidth( );

			if( Pos <= 0 )
			{
				Pos = 0;
				$( "#GalleryLeftArrow" ).attr( "src", "/images/gallery_ends/gallery_l_end.gif" ); // Hit the end
			}

			if( Pos != CurrentScrollPos ) // We moved
			{
				$( "#GalleryScrollDiv" ).animate( { 'margin-left': -Pos } );
				$( "#GalleryDiv" ).data( "GalleryPos", GalleryPos );
				// Put the other arrow back - not at the end any more
				$( "#GalleryRightArrow" ).attr( "src", "/images/gallery_ends/gallery_r.gif" );
			}
	}	



	// Init
		var I = $( "#GalleryScrollDiv>img" );
		var NumItems = I.length;
		if( NumItems > 0 )
		{
			$( "#GalleryScrollDiv" ).show( );
			$( "#GalleryLeftArrow" )
				.attr( "src", "/images/gallery_ends/gallery_l_end.gif" ) // It's 0, see?
				.css( "cursor", "pointer" );
			$( "#GalleryRightArrow" )
				.attr( "src", "/images/gallery_ends/gallery_r.gif" )
				.css( "cursor", "pointer" );



			// On click
				$( "#GalleryRightArrow" ).bind( "click", MoveRight );
				$( "#GalleryLeftArrow" ).bind( "click", MoveLeft );



			// Mouse over/out of the gallery contents
				$( "#GalleryScrollDiv>img" ).bind( "mouseenter", function( )
				{
					var o = $( this ).offset( );
					var w = $( this ).width( );
					var h = $( this ).height( );
					$( "#GalleryMouseOver" ).show( ).offset( o ).width( w ).height( h );

					var Dif = parseInt( $( "#GalleryMouseOverBorder" ).css( "borderLeftWidth" ) ) +
						parseInt( $( "#GalleryMouseOverBorder" ).css( "margin-left" ) ) +
						parseInt( $( "#GalleryMouseOverBorder" ).css( "padding-left" ) );
					
					$( "#GalleryMouseOverBg" ).width( w ).height( h );
					
					Dif = 2 * ( Dif );
					w -= Dif;
					h -= Dif;
					
					var ImageId = $( this ).attr( 'id' );
					var TextId = 'GalleryText_' + ImageId.substring( 13 );
					var Text = $( '#' + TextId ).html( );
					$( "#GalleryMouseOverBorder" ).html( Text ).width( w ).height( h );
					
					
					$( "#GalleryMouseOver" ).show( );
				} );
					
				$( "#GalleryMouseOver" ).bind( "mouseleave", function( )
				{
					$( "#GalleryMouseOver" ).hide( );
				} );



			// Mouse over
				$( "#GalleryRightArrow" ).bind( "mouseover", function( )
				{
					if( $( this ).attr( "src" ) != "/images/gallery_ends/gallery_r_end.gif" )
						$( this ).attr( "src", "/images/gallery_ends/gallery_r_mo.gif" );
					$( "#GalleryMouseOver" ).hide( );
				} );

				$( "#GalleryLeftArrow" ).bind( "mouseover", function( )
				{
					if( $( this ).attr( "src" ) != "/images/gallery_ends/gallery_l_end.gif" )
						$( this ).attr( "src", "/images/gallery_ends/gallery_l_mo.gif" );
					$( "#GalleryMouseOver" ).hide( );
				} );



			// Mouse out
				$( "#GalleryRightArrow" ).bind( "mouseout", function( )
				{
					if( $( this ).attr( "src" ) != "/images/gallery_ends/gallery_r_end.gif" )
						$( this ).attr( "src", "/images/gallery_ends/gallery_r.gif" );
				} );

				$( "#GalleryLeftArrow" ).bind( "mouseout", function( )
				{
					if( $( this ).attr( "src" ) != "/images/gallery_ends/gallery_l_end.gif" )
						$( this ).attr( "src", "/images/gallery_ends/gallery_l.gif" );
				} );
	}
}
