/**
 * This class requires the prototype javascript library version 1.6 or above.
 */

	var ReNet_ImageGallery = Class.create({
		
		initialize: function(element, images, options) 
		{
			this.name = name;
			this.images = images;
			this.options = options;
			
			if (this.options.links == undefined) {
				this.options.links = {};
			}
			if (this.options.buttons == undefined) {
				this.options.buttons = {};
			}
			if (this.options.caption == undefined) {
				this.options.caption = {};
			}
			if (this.options.count == undefined) {
				this.options.count = {};
			}
			if (this.options.overlay == undefined) {
				this.options.overlay = {};
			}
			
			// For scaling the images.
			this.imageScript = '';
			if ( this.options.scaleImages == true ) {
				this.imageScript = 'http://www.api.renet.com.au/lbimage.php?';
			}
			
			this.gallery = { imageCount:this.images.length,
				 			 currentImageNumber:1,
							 rebuildLinks:true,
							 playSlideshow:false
							};
			
			//
			//Set up some valueable setting for the gallery.
			//
			
			//Width.
			if (options.width != undefined && typeof(options.width) == 'number') {
				this.options.width = options.width;
			} else {
				this.options.width = 400;
			}
			//Height.
			if (options.height != undefined && typeof(options.height) == 'number') {
				this.options.height = options.height;
			} else {
				this.options.height = 300;
			}
			//Background.
			if (options.background == undefined || typeof(options.background) != 'string') {
				this.options.background = '#000000';
			}
			
			//Image links number.
			if (options.links.number != undefined && typeof(options.links.number) == 'number') {
				this.gallery.imageLinksNumber = options.links.number;
			} else {
				this.gallery.imageLinksNumber = 7;
			}
			
			if (this.gallery.imageLinksNumber > this.gallery.imageCount) {
				this.gallery.imageLinksNumber = this.gallery.imageCount;
				this.gallery.linksPadding = 0;
				this.gallery.rebuildLinks = false;
			} else {
				//How many links to show either side of the current link.
				if (this.gallery.imageLinksNumber%2) {
					//The number of links is odd. Don't change it.
				} else {
					//The number of links is even. Make it odd.
					this.gallery.imageLinksNumber --;
				}
				if (this.gallery.imageLinksNumber < 3) {
					this.gallery.imageLinksNumber = 3;
				}
				this.gallery.linksPadding = Math.round( (this.gallery.imageLinksNumber - 1) / 2 );
			}
			
			//Show buttons.
			if (options.buttons.show != undefined && options.buttons.show == true) {
				this.gallery.showButtons = true;
			} else {
				this.gallery.showButtons = false;
			}
				//Button styles.
				if (options.buttons.height == undefined) {
					this.options.buttons.height = '30';
				}
				if (options.buttons.background == undefined) {
					this.options.buttons.background = '#333333';
				}
				if (options.buttons.color == undefined) {
					this.options.buttons.color = '#FFFFFF';
				}
				if (options.buttons.font == undefined) {
					this.options.buttons.font = '10px/'+this.options.buttons.height+'px Verdana';
				}
				if (options.buttons.textAlign == undefined) {
					this.options.buttons.textAlign = 'center';
				}
				if (options.buttons.textIndent == undefined) {
					this.options.buttons.textIndent = '0';
				}
			
			//Show image caption.
			if (options.caption.show != undefined && options.caption.show == true) {
				this.gallery.showImageCaption = true;
			} else {
				this.gallery.showImageCaption = false;
			}
				//Caption styles.
				if (options.caption.height == undefined) {
					this.options.caption.height = '30';
				}
				if (options.caption.background == undefined) {
					this.options.caption.background = '#333333';
				}
				if (options.caption.color == undefined) {
					this.options.caption.color = '#FFFFFF';
				}
				if (options.caption.font == undefined) {
					this.options.caption.font = '10px/'+this.options.caption.height+'px Verdana';
				}
				if (options.caption.opacity == undefined) {
					this.options.caption.opacity = 0.6;
				}
				if (options.caption.bottom == undefined) {
					this.options.caption.bottom = 0;
				}
				if (options.caption.textAlign == undefined) {
					this.options.caption.textAlign = 'left';
				}
				if (options.caption.textIndent == undefined) {
					this.options.caption.textIndent = '20';
				}
			//Show image number.
			if (options.count.show != undefined && options.count.show == true) {
				this.gallery.showImageNumber = true;
			} else {
				this.gallery.showImageNumber = false;
			}
				//Count styles.
				if (options.count.height == undefined) {
					this.options.count.height = '20';
				}
				if (options.count.background == undefined) {
					this.options.count.background = '#333333';
				}
				if (options.count.color == undefined) {
					this.options.count.color = '#FFFFFF';
				}
				if (options.count.font == undefined) {
					this.options.count.font = '10px/'+this.options.count.height+'px Verdana';
				}
				if (options.count.opacity == undefined) {
					this.options.count.opacity = 0.6;
				}
				if (options.count.top == undefined) {
					this.options.count.top = 10;
				}
				//Optional left or right. Use right by default.
				if (options.count.right == undefined) {
					this.options.count.right = 10;
				}
				if (options.count.width == undefined) {
					this.options.count.width = 80;
				}
				if (options.count.textAlign == undefined) {
					this.options.count.textAlign = 'center';
				}
				if (options.count.textIndent == undefined) {
					this.options.count.textIndent = '0';
				}
			//Show image links.
			if (options.links.show != undefined && options.links.show == true) {
				this.gallery.showImageLinks = true;
			} else {
				this.gallery.showImageLinks = false;
			}
				//Links styles.
				if (options.links.height == undefined) {
					this.options.links.height = '30';
				}
				if (options.links.background == undefined) {
					this.options.links.background = '#333333';
				}
				if (options.links.color == undefined) {
					this.options.links.color = '#FFFFFF';
				}
				if (options.links.font == undefined) {
					this.options.links.font = '10px/'+this.options.links.height+'px Verdana';
				}
				if (options.links.textAlign == undefined) {
					this.options.links.textAlign = 'center';
				}
				if (options.links.textIndent == undefined) {
					this.options.links.textIndent = '0';
				}
				if (options.links.textDecoration == undefined) {
					this.options.links.textDecoration = 'underline';
				}
			//Overlay options.
			if (options.overlay.show != undefined && options.overlay.show == true) {
				this.options.overlay.show = true;
			} else {
				this.options.overlay.show = false;
			}
				//Overlay styles.
				if (options.overlay.height == undefined) {
					this.options.overlay.height = '100';
				}
				if (options.overlay.width == undefined) {
					this.options.overlay.width = '100';
				}
				if (options.overlay.top == undefined) {
					this.options.overlay.top = '0';
				}
				if (options.overlay.left == undefined) {
					this.options.overlay.left = '0';
				}
				if (options.overlay.background == undefined) {
					this.options.overlay.background = '';
				}
				if (options.overlay.color == undefined) {
					this.options.overlay.color = '#FFFFFF';
				}
				if (options.overlay.font == undefined) {
					this.options.overlay.font = '18px/'+this.options.overlay.height+'px Verdana';
				}
				if (options.overlay.textAlign == undefined) {
					this.options.overlay.textAlign = 'center';
				}
				if (options.overlay.textIndent == undefined) {
					this.options.overlay.textIndent = '0';
				}
				if (options.overlay.textDecoration == undefined) {
					this.options.overlay.textDecoration = 'none';
				}
				if (options.overlay.content == undefined) {
					this.options.overlay.content = '';
				}
				if (options.overlay.url == undefined) {
					this.options.overlay.url = '';
				}
				if (options.overlay.target == undefined) {
					this.options.overlay.target = '_blank';
				}
			
			//Show the images as a slide show. Should over ride the default setting. Should also play as a slideshow if now buttons or links are shown.
			if ( (options.slideshow != undefined && options.slideshow == true) || (this.gallery.showImageLinks == false && this.gallery.showButtons == false) ) {
				this.gallery.playSlideshow = true;
				this.gallery.playMode = 'play';
			}
			//Slide show duration. Milliseconds.
			if (this.options.slideshowDuration != undefined && typeof(this.options.slideshowDuration) == 'number') {
				this.options.slideshowDuration *= 1000;
			} else {
				this.options.slideshowDuration = 5000;
			}
			//Slide show transition duration. Seconds.
			if (this.options.transitionDuration == undefined || typeof(this.options.transitionDuration) != 'number') {
				this.options.transitionDuration = 0.5;
			}
			
			//Transition duration should not be more than the slideshow duration.
			if (this.options.transitionDuration * 1000 > this.options.slideshowDuration) {
				this.options.transitionDuration = (this.options.slideshowDuration - 500) / 1000;
			}
			//
			//End of setting up valuable settings.
			//
			
			//Save a reference to the specified container element in a 'domElements' object. This is used later to reference many more elements.
			this.domElements = { container:$(element) };
			//Print the markup to the screen.
			this.show();
		},
		
		/**
		 * Prints the entire image gallery markup to the screen.
		 */
		show: function()
		{
			//Create a wrapper div for the image gallery.
			this.domElements.wrapper = new Element('div', { 'class':'ReNetSlideshow', 'style':'margin:0px auto 0px auto; width:'+this.options.width+'px;' });
			
			//Put the wrapper element into the specified container.
			this.domElements.container.update( this.domElements.wrapper );
			
			//Print the images container.
			this.domElements.imagesPlaceholder = new Element('div', { 'class':'ReNetSlideshow-images', 'style':'position:relative; background:'+this.options.background+'; width:'+this.options.width+'px; height:'+this.options.height+'px; overflow:hidden;' });
			this.domElements.wrapper.update(this.domElements.imagesPlaceholder);
			this.domElements.imagesList = new Element('ul', { 'class':'ReNetSlideshow-images-list', 'style':'margin:0px; border:none; padding:0px; list-style:none; white-space:nowrap;' });
			
			//Build the images.
			for (i = 0; i < this.gallery.imageCount; i ++) {
				
				var imgSize = '';
				if (this.imageScript != '') {
					src = this.imageScript+'src='+this.images[i].url+'&w='+this.options.width+'&h='+this.options.height+'&format=jpg';
				} else {
					src = this.images[i].url;
					var imgSize = ' width="'+this.options.width+'" height="'+this.options.height+'"';
				}
				
				// Do some clickable styles for the images if it has a link associated with it.
				var imgOpen = '';
				var imgClose = '';
				var imgTarget = '';
				if ( this.images[i].link != undefined ) {
					if ( this.images[i].linkTarget != undefined ) {
						imgTarget = ' target="'+this.images[i].linkTarget+'"';
					}
					imgOpen = '<a style="text-decoration:none;" href="'+this.images[i].link+'"'+imgTarget+'>';
					imgClose = '</a>'
				}
				
				this.domElements['image_'+(i+1)] = new Element('li', { 'class':'ReNetSlideshow-image', 'style':'margin:0px; border:none; padding:0px; position:absolute; text-align:center; vertical-align:middle; top:0px; left:0px; width:'+this.options.width+'px; height:'+this.options.height+'px;' });
				this.domElements['image_'+(i+1)].update( imgOpen+'<img src="'+src+'" alt="'+this.images[i].description+'"'+imgSize+' />'+imgClose );
				
				if (i == 0) {
					this.domElements.imagesList.update( this.domElements['image_'+(i+1)] );
				} else {
					this.domElements['image_'+ i].insert( { after : this.domElements['image_'+(i+1)] } )
				}
				
				this.domElements['image_'+(i+1)].hide();
				
			}
			
			this.gallery.currentImage = this.domElements['image_1'];
			this.gallery.currentImage.show();
			
			this.domElements.imagesPlaceholder.update( this.domElements.imagesList );
			
			//
			//Create the image caption elements.
			//
			
			/*
			
			Allow the height, line-height, font, color, bg color, bg opacity, and position
			
			*/
			
			captionBGStyle = 'position:absolute; bottom:'+this.options.caption.bottom+'px; left:0px; z-index:103; height:'+this.options.caption.height+'px; background:'+this.options.caption.background+'; filter:alpha(opacity='+(this.options.caption.opacity * 100)+'); opacity:'+this.options.caption.opacity+'; width:'+this.options.width+'px;';
			if (this.gallery.showImageCaption == false) {
				captionBGStyle += ' display:none;';
			}
			
			this.domElements.imageCaptionBG = new Element('div', { 'class':'ReNetSlideshow-image-caption-bg', 'style':captionBGStyle });
			this.domElements.imagesList.insert( { after : this.domElements.imageCaptionBG } );
			
			captionStyle = 'position:absolute; bottom:'+this.options.caption.bottom+'px; left:0px; z-index:104; height:'+this.options.caption.height+'px; color:'+this.options.caption.color+'; text-align:'+this.options.caption.textAlign+'; font:'+this.options.caption.font+'; text-indent:'+this.options.caption.textIndent+'px; width:'+this.options.width+'px;';
			if (this.gallery.showImageCaption == false) {
				captionStyle += ' display:none;';
			}
			
			this.domElements.imageCaption = new Element('div', { 'class':'ReNetSlideshow-image-caption', 'style':captionStyle });
			this.domElements.imageCaption.update( this.images[0].description );
			this.domElements.imageCaptionBG.insert( { after : this.domElements.imageCaption } );
			
			//
			//Create the image number elements.
			//
			
			countBGStyle = 'position:absolute; top:'+this.options.count.top+'px; right:'+this.options.count.right+'px; z-index:100; height:'+this.options.count.height+'px; width:'+this.options.count.width+'px; background:'+this.options.count.background+'; filter:alpha(opacity='+(this.options.count.opacity * 100)+'); opacity:'+this.options.count.opacity+';';
			if (this.gallery.showImageNumber == false) {
				countBGStyle += ' display:none;';
			}
			
			this.domElements.imageCountBG = new Element('div', { 'class':'ReNetSlideshow-image-number-bg', 'style':countBGStyle });
			this.domElements.imageCaption.insert( { after : this.domElements.imageCountBG } );
			
			countStyle = 'position:absolute; top:'+this.options.count.top+'px; right:'+this.options.count.right+'px; z-index:101; height:'+this.options.count.height+'px; width:'+this.options.count.width+'px; text-align:'+this.options.count.textAlign+'; color:'+this.options.count.color+'; font:'+this.options.count.font+';';
			if (this.gallery.showImageNumber == false) {
				countStyle += ' display:none;';
			}
			
			this.domElements.imageCount = new Element('div', { 'class':'ReNetSlideshow-image-number', 'style':countStyle });
			this.domElements.imageCount.update( '1 of ' + this.gallery.imageCount );
			this.domElements.imageCountBG.insert( { after : this.domElements.imageCount } );
			
			//Add the overlay if required.
			if (this.options.overlay.show == true) {
				this.domElements.overlay = new Element('a', { 'class':'ReNetSlideshow-overlay', 'href':'javascript:void(0);', 'style':'display:block; overflow:hidden; position:absolute; z-index:99; width:'+this.options.overlay.width+'px; height:'+this.options.overlay.height+'px; top:'+this.options.overlay.top+'px; left:'+this.options.overlay.left+'px; background:'+this.options.overlay.background+'; text-decoration:none; text-align:'+this.options.overlay.textAlign+'; font:'+this.options.overlay.font+'; text-indent:'+this.options.overlay.textIndent+';' });
				if (this.options.overlay.content != '') {
					this.domElements.overlay.update( this.options.overlay.content );
				}
				if (this.options.overlay.url != '') {
					this.domElements.overlay.setAttribute( 'href', this.options.overlay.url );
					this.domElements.overlay.setAttribute( 'target', this.options.overlay.target );
				}
				this.domElements.imageCount.insert( { after : this.domElements.overlay } );
			}
			
			//
			//Create the image links.
			//
			
			//Create the links container.
			linksStyle = 'margin:1px auto 1px auto; padding:0px; height:'+this.options.links.height+'px; background:'+this.options.links.background+'; color:'+this.options.links.color+'; font:'+this.options.links.font+'; width:'+this.options.width+'px;';
			if (this.gallery.showImageLinks == false) {
				linksStyle += ' display:none;';
			}
			
			this.domElements.imageLinks = new Element('div', { 'class':'ReNetSlideshow-image-links', 'style':linksStyle });
			this.domElements.imagesPlaceholder.insert( { after : this.domElements.imageLinks } );
			this.domElements.imageLinksContainer = new Element('div', { 'style':'text-align:center;' } );
			this.domElements.imageLinks.update( this.domElements.imageLinksContainer );
			
			//Put in the 'fewer' span.
			this.domElements.imageLinksFewer = new Element('span', { 'class':'ReNetSlideshow-image-links-fewer', 'style':'padding:0px 5px 0px 5px;' });
			this.domElements.imageLinksContainer.update( this.domElements.imageLinksFewer );
			
			for (count = 1; count <= this.images.length && count <= this.gallery.imageLinksNumber; count ++) {
				this.domElements['imageLink_'+count] = new Element('a', { 'class':'ReNetSlideshow-image-links-link', href:'javascript:void(0);', 'style':'padding:0px 5px 0px 5px; text-decoration:'+this.options.links.textDecoration+';' });
				this.domElements['imageLink_'+count].update( count );
				if (count == 1) {
					this.domElements['imageLink_'+count].setAttribute( 'class', 'current');
				}
				//Add an event observer to the element.
				this.domElements['imageLink_'+count].observe('click', this.swapImage.bind(this, count));
				
				//Add the element to the dom.
				if (count == 1) {
					this.domElements.imageLinksFewer.insert( { after : this.domElements['imageLink_'+count] } );
				} else {
					this.domElements['imageLink_'+(count-1)].insert( { after : this.domElements['imageLink_'+count] } );
				}
			}
			
			//Add the 'more' link.
			this.domElements.imageLinksMore = new Element('span', { 'class':'ReNetSlideshow-image-links-more', 'style':'padding:0px 5px 0px 5px;' });
			if (this.gallery.imageLinksNumber < this.gallery.imageCount) {
				this.domElements.imageLinksMore.update( '...' );
			}
			this.domElements['imageLink_'+this.gallery.imageLinksNumber].insert( { after : this.domElements.imageLinksMore } );
			
			//
			//Create the buttons.
			//
			
			if (this.options.buttons.show == true) {
				this.domElements.buttons = new Element('div', { 'class':'ReNetSlideshow-buttons', 'style':'margin:0px auto 0px auto; color:'+this.options.buttons.color+'; font:'+this.options.buttons.font+'; text-align:'+this.options.buttons.textAlign+'; text-indent:'+this.options.buttons.textIndent+'; width:'+this.options.width+'px; height:'+this.options.buttons.height+'px; background:'+this.options.buttons.background+'; position:relative;' });
				this.domElements.imageLinks.insert( { after : this.domElements.buttons } );
				//First.
				this.domElements.buttonFirst = new Element('a', { 'href':'javascript:void(0);', 'class':'ReNetSlideshow-button-first', 'style':'margin:0px 2px 0px 2px; text-decoration:'+this.options.buttons.textDecoration+';' });
				if (this.options.buttons.firstButton == undefined) {
					this.domElements.buttonFirst.update( '<span>first</span>' );
				} else {
					this.domElements.buttonFirst.update( '<img src="'+this.options.buttons.firstButton+'" alt="first" />' );
				}
				this.domElements.buttonFirst.observe('click', this.first.bind(this));
				this.domElements.buttons.update( this.domElements.buttonFirst );
				//Previous.
				this.domElements.buttonPrevious = new Element('a', { 'href':'javascript:void(0);', 'class':'ReNetSlideshow-button-previous', 'style':'margin:0px 2px 0px 2px; text-decoration:'+this.options.buttons.textDecoration+'' });
				if (this.options.buttons.previousButton == undefined) {
					this.domElements.buttonPrevious.update( '<span>previous</span>' );
				} else {
					this.domElements.buttonPrevious.update( '<img src="'+this.options.buttons.previousButton+'" alt="previous" />' );
				}
				this.domElements.buttonPrevious.observe('click', this.previous.bind(this));
				this.domElements.buttonFirst.insert( { after : this.domElements.buttonPrevious } );
				//Play / Pause.
				this.domElements.buttonPlay = new Element('a', { 'href':'javascript:void(0);', 'class':'ReNetSlideshow-button-play', 'style':'margin:0px 2px 0px 2px; text-decoration:'+this.options.buttons.textDecoration+'' });
				if (this.options.buttons.playButton == undefined) {
					this.domElements.buttonPlay.update( '<span>play/pause</span>' );
				} else {
					this.domElements.buttonPlay.update( '<img src="'+this.options.buttons.playButton+'" alt="play" />' );
				}
				this.domElements.buttonPlay.observe('click', this.togglePlayPause.bind(this));
				this.domElements.buttonPrevious.insert( { after : this.domElements.buttonPlay } );
				//Next.
				this.domElements.buttonNext = new Element('a', { 'href':'javascript:void(0);', 'class':'ReNetSlideshow-button-next', 'style':'margin:0px 2px 0px 2px; text-decoration:'+this.options.buttons.textDecoration+'' });
				if (this.options.buttons.nextButton == undefined) {
					this.domElements.buttonNext.update( '<span>next</span>' );
				} else {
					this.domElements.buttonNext.update( '<img src="'+this.options.buttons.nextButton+'" alt="next" />' );
				}
				this.domElements.buttonNext.observe('click', this.next.bind(this));
				this.domElements.buttonPlay.insert( { after : this.domElements.buttonNext } );
				//Last.
				this.domElements.buttonLast = new Element('a', { 'href':'javascript:void(0);', 'class':'ReNetSlideshow-button-last', 'style':'margin:0px 2px 0px 2px; text-decoration:'+this.options.buttons.textDecoration+'' });
				if (this.options.buttons.lastButton == undefined) {
					this.domElements.buttonLast.update( '<span>last</span>' );
				} else {
					this.domElements.buttonLast.update( '<img src="'+this.options.buttons.lastButton+'" alt="last" />' );
				}
				//Add the 'last' button after the 'next' button.
				this.domElements.buttonLast.observe('click', this.last.bind(this));
				this.domElements.buttonNext.insert( { after : this.domElements.buttonLast } );
			}
			
			//Start the image gallery slideshow.
			if (this.gallery.playSlideshow == true) {
				this.gallery.timeout = setTimeout( this.next.bind( this ), this.options.slideshowDuration );
			}
			
		},

		/**
		 * Swaps between the current image and another specified image.
		 */
		swapImage: function(imageNumber) 
		{
			if (imageNumber == this.gallery.currentImageNumber) {
				return;
			}

			//Fade out the old image.
			this.gallery.currentImage.className = 'lower';
			new Effect.Fade( this.gallery.currentImage, { duration: this.options.transitionDuration } );
			// this.gallery.currentImage.fade( { duration: this.options.transitionDuration } );

			//Update the reference for the current image.
			this.gallery.currentImage = this.domElements['image_'+imageNumber];
			this.gallery.currentImageNumber = imageNumber;

			//Fade in the new image.
			this.gallery.currentImage.className = 'higher';
			new Effect.Appear( this.gallery.currentImage, { duration: this.options.transitionDuration } );
			// this.gallery.currentImage.appear( { duration: this.options.transitionDuration } );

			//Update the image number text.
			this.domElements.imageCount.update( imageNumber + ' of ' + this.gallery.imageCount );
			this.domElements.imageCaption.update( this.images[ this.gallery.currentImageNumber - 1].description );

			//Rebuild the links to images.
			if (this.gallery.rebuildLinks == true) {
				this.rebuildImageLinks();
			}

			if (this.gallery.playSlideshow == true) {
				clearTimeout(this.gallery.timeout);
				this.gallery.timeout = setTimeout( this.next.bind( this ), this.options.slideshowDuration );
			}

		},

		/**
		 * Goes to the next image.
		 */
		next: function()
		{
			if (this.gallery.currentImageNumber == this.gallery.imageCount) {
				goto = 1;
			} else {
				goto = this.gallery.currentImageNumber + 1;
			}
			this.swapImage(goto);
		},

		/**
		 * Goes to the previous image.
		 */
		previous: function()
		{
			if (this.gallery.currentImageNumber == 1) {
				goto = this.gallery.imageCount;
			} else {
				goto = this.gallery.currentImageNumber - 1;
			}
			this.swapImage(goto);
		},

		/**
		 * Goes to the first image.
		 */
		first: function()
		{	
			this.swapImage(1);
		},

		/**
		 * Goes to the last image.
		 */
		last: function()
		{	
			this.swapImage(this.gallery.imageCount);
		},
			
		/**
		 * Toogle the slideshow between play and pause mode.
		 */
		togglePlayPause: function()
		{
			if (this.gallery.playMode == 'play') {
				this.gallery.playMode = 'pause';
				this.pauseSlideshow();
			} else {
				this.gallery.playMode = 'play';
				this.playSlideshow()
			}
			//$('play-button').className = this.gallery.playMode;
		},
		
		/**
		 * Play the slideshow
		 */
		playSlideshow: function()
		{
			this.next();
			this.gallery.timeout = setTimeout( this.next.bind( this ), this.options.slideshowDuration );
		},

		/**
		 * Pause the slideshow
		 */
		pauseSlideshow: function()
		{	
			clearTimeout(this.gallery.timeout);
			// ?
			this.gallery.currentImage.show();
		},
		
		/**
		 * Rebuild the text and handers for the image links.
		 */
		rebuildImageLinks: function()
		{
			startNum = this.gallery.currentImageNumber - this.gallery.linksPadding;
			endNum = startNum + this.gallery.imageLinksNumber;
			//Refine the start and end numbers.
			if (startNum < 1) {
				startNum = 1;
				endNum = startNum + this.gallery.imageLinksNumber;
			} else if (startNum + this.gallery.imageLinksNumber > this.gallery.imageCount) {
				startNum = this.gallery.imageCount - this.gallery.imageLinksNumber + 1;
				endNum = this.gallery.imageCount;
			}
			//The 'fewer' cell.
			if (startNum > 1) {
				this.domElements.imageLinksFewer.update('...');
			} else {
				this.domElements.imageLinksFewer.update('');
			}
			//The 'more' cell.
			if (endNum < this.gallery.imageCount) {
				this.domElements.imageLinksMore.update('...');
			} else {
				this.domElements.imageLinksMore.update('');
			}
			//Content and handlers for the links.
			var content = startNum;
			for (i = 1; i <= this.gallery.imageLinksNumber; i ++) {
				link = this.domElements['imageLink_'+i];
				link.update(content);
				if (content == this.gallery.currentImageNumber) {
					link.addClassName('current');
				} else {
					link.removeClassName('current');
				}
				//Kill the current handler for the link.
				link.stopObserving('click');
				if (content + 1 <= this.gallery.imageCount) {
					link.observe('click', this.swapImage.bind(this, content));
					content ++;
					//bind;
				} else {
					content = '';
				}
			}
		}
		//End of last method definition.
		
	});
	