		/* CONFIG */
		var imageWidth 		= 600;
		var imageHeight 	= 278;
		var imagePrevWidth 	= 200;
		var linkSize 		= 37;
		var currentLink     = '';

		
		var images = new Array();
		var currentIndex = 0;

		var animationDuration = 500;
		var animationPlaying = false;

		var slideshowTimer = null;


		$(document).ready( function(){
			initContainers();
			initImages();
			initGallery();
			$('#gallerBG').show();
			$('#gallery .text').click( function(){ location.href = currentLink; });
		});

		function initContainers()
		{
			$('#gallery')
			.css( "width", imageWidth + imagePrevWidth * 2 )
			.css( "height", imageHeight );
			
			$('#gallery .scrollableContainer')
			.css( "width", imageWidth + imagePrevWidth * 2 )
			.css( "height", imageHeight );

			$('#gallery .scrollableContainer .scrollable').css( "width", 5 * imageWidth );

			var prevBgSelector = '#gallery .scrollableContainer a.prevBg';
			var prevLinkSelector = '#gallery .scrollableContainer a.prev';
			
			$(prevBgSelector)
				.css( "width", imagePrevWidth )
				.css( "height", imageHeight )
				.css( "opacity", 0.4 )
				.css( "background-color", "#FFF" )
				.mouseover( _mouseOverPrev ) 
				.mouseout( _mouseOutPrev );

			$(prevLinkSelector)
				.css( "top", imageHeight / 2 - linkSize / 2 )
				.css( "left", imagePrevWidth - linkSize - 5 )
				.css( "opacity", 0.4 )
				.mouseover( _mouseOverPrev ) 
				.mouseout( _mouseOutPrev );
		
			$('#gallery .scrollableContainer img.prevOver')
				.css( "width", imagePrevWidth )
				.css( "height", imageHeight );
				

			
			$('#gallery .scrollableContainer a.nextBg')
				.css( "width", imagePrevWidth )
				.css( "height", imageHeight )
				.css( "opacity", 0.4 )
				.css( "background-color", "#FFF" )
				.mouseover( _mouseOverNext ) 
				.mouseout( _mouseOutNext );


			$('#gallery .scrollableContainer a.next')
				.css( "top", imageHeight / 2 - linkSize / 2 )
				.css( "right", imagePrevWidth - linkSize - 5 )
				.css( "opacity", 0.4 )
				.mouseover( _mouseOverNext ) 
				.mouseout( _mouseOutNext );

			$('#gallery .scrollableContainer img.nextOver')
				.css( "width", imagePrevWidth )
				.css( "height", imageHeight );
			

			$('#gallery .text' )
			.css( "left", imagePrevWidth + ( imageWidth - $('#gallery .text' ).width() ) / 2 );
		}

		function initImages()
		{
			for( i=0; i< images.length; i++ )
			{
				$('#debug').append( images[i].image + '<br />' );
			}			
		}


		function initGallery()
		{
			for( i = -2; i < 3; i++ )
			{
				_addImage(i);
			}
			_setText( 0 );
			$('.scrollable' ).css( "left", -2 * imageWidth + imagePrevWidth );
			_resetTimer();
		}

		

		function displayImage( direction )
		{
			if( animationPlaying ) return;

			
			_resetTimer();
			
			animationPlaying = true;
			if( direction > 0 )
			{
				currentIndex++;
				
				$('.scrollable' ).animate( { "left" : -3 * imageWidth + imagePrevWidth }, animationDuration, function(){
					_addImage( currentIndex + 2 );
					$( '.scrollable' ).css( "left", -2 * imageWidth + imagePrevWidth );
					$( '.scrollable img:nth-child(1)' ).remove();
				} );
				
				_setText( currentIndex );
			}
			else
			{
				currentIndex--;
				
				$('.scrollable' ).animate( { "left" : -1 * imageWidth + imagePrevWidth }, animationDuration, function(){
					_addImage( currentIndex - 2, true );
					$( '.scrollable' ).css( "left", -2 * imageWidth + imagePrevWidth );
					$( '.scrollable img:nth-child(5)' ).remove();
				} );
				
				_setText( currentIndex );
			}

			
			setTimeout( "animationPlaying = false;", animationDuration );
		}



		

		function _setText( index )
		{
			var text 	= images[_getImageIndex(index)].text;
			currentLink = images[_getImageIndex(index)].link;
			var logo	= images[_getImageIndex(index)].logo;

			$('#gallery .text').fadeOut( animationDuration / 2, function() { 
					$('#gallery .text p').html( text );
					$('#gallery .text img').attr( "src", logo );
					$('#gallery .text').fadeIn( animationDuration / 2 );  
			} );
		}
		
		function _resetTimer()
		{
			clearTimeout( slideshowTimer );
			slideshowTimer = setTimeout( "displayImage( 1 );", 300000 );
		}


		function _addImage( index, isFirst )
		{
			if( isFirst == null )
			{
				$('.scrollable')
				.append( 
					$( '<img src="' + images[ _getImageIndex( index ) ].image + '" />' )
					.css( "width", imageWidth )
					.css( "height", imageHeight )
				);
			}
			else
			{
				$('.scrollable')
				.prepend( 
					$( '<img src="' + images[ _getImageIndex( index ) ].image + '" />' )
					.css( "width", imageWidth )
					.css( "height", imageHeight )
				);
			}
		}

		function _getImageIndex( index )
		{
			if( index >= 0 )
			{
				return index % images.length;
			}
			else
			{
				return ( images.length + index % images.length ) % images.length ; 
			}
		}




		var isMouseOverPrev = false;
		
		function _mouseOverPrev()
		{
			isMouseOverPrev = true;
			$('#gallery .scrollableContainer a.prevBg').animate( { opacity: 0 }, 100 );
			$('#gallery .scrollableContainer a.prev').animate( { opacity: 1 }, 100 );
		}

		function _mouseOutPrev()
		{
			isMouseOverPrev = false;

			setTimeout( _doMouseOutPrev, 100 );
		}

		function _doMouseOutPrev()
		{
			if( isMouseOverPrev ) return;
			$('#gallery .scrollableContainer a.prevBg').animate( { opacity: 0.4 }, 100 );
			$('#gallery .scrollableContainer a.prev').animate( { opacity: 0.4 }, 100 );
		}

		var isMouseOverNext = false;
		
		function _mouseOverNext()
		{
			isMouseOverNext = true;
			$('#gallery .scrollableContainer a.nextBg').animate( { opacity: 0 }, 100 );
			$('#gallery .scrollableContainer a.next').animate( { opacity: 1 }, 100 );
		}

		function _mouseOutNext()
		{
			isMouseOverNext = false;

			setTimeout( _doMouseOutNext, 100 );
		}

		function _doMouseOutNext()
		{
			if( isMouseOverNext ) return;
			$('#gallery .scrollableContainer a.nextBg').animate( { opacity: 0.4 }, 100 );
			$('#gallery .scrollableContainer a.next').animate( { opacity: 0.4 }, 100 );
		}
		

