	
			var thumbDir='uploads/images/thumbs/'
			var bigDir='uploads/images/large/'
			var ccimages = new Array();
			var ccCaptions = new Array();
			var pendingEvent;
			var curPic;
			var scrollEvent;
			var C_scrollInterval=50;
			var C_scrollStep=10;
			var imageWeAreOn = 1;
			var ssRunning=false;
			
			function preload(bigPicList,captionList){
				if(bigPicList !== undefined && captionList !== undefined) {
                                    var bigPics = bigPicList.split('~');

                                    var captions = captionList.split('~');
                                    for (var p=0;p<bigPics.length;p++)
                                    {
                                        ccimages[p] = new Image();
                                        ccimages[p].src = bigPics[p];

                                        ccimages[p].caption = captions[p];

                                        ccimages[p].thumbnailSrc=bigPics[p].replace(bigDir,thumbDir);
                                        ccimages[p].isPortrait=(ccimages[p].height>ccimages[p].width);
                                        var thumb=document.createElement('img');
                                        thumb.src=ccimages[p].thumbnailSrc;
                                        ccimages[p].thumbnail=thumb;
                                        var thumbRow=document.getElementById('thumbRow');
                                        var thumbCell=document.createElement('td');
                                        var thumbSpan=document.createElement('span');
                                        var thumbLink=document.createElement('a');
                                        thumbCell.className='thumbCell';
                                        thumbLink.setAttribute('onclick','viewPicture(' + p + ');');

                                        thumbLink.href='javascript:viewPicture(' + p + ');';

                                        thumbLink.appendChild(thumb);
                                        thumbCell.appendChild(thumbSpan);
                                        thumbSpan.appendChild(thumbLink);
                                        thumbRow.appendChild(thumbCell);
                                    }
                                    curPic=document.getElementById('picNum').innerHTML-1;
                                    highCurThumb();
                                    centreThumb(0,curPic,true);

                                    document.getElementById('imgProperty').style.height='350px';

                                    setTimeout('slide()',5000);
                                }
			}
			
			function viewPicture(p){
				stop_slide();
				showPic(p);
			}
			function next_picture(){
				var ssRunning=false;
				if(pendingEvent){
					ssRunning=true;
					clearTimeout(pendingEvent);
				}
				nextimg();
				if(ssRunning){
					//pendingEvent=setTimeout('ss_run()',2000);
					ssRunning = false;
					imageWeAreOn = 1;
					clearTimeout(pendingEvent);
					stop_slide();
				}
			}
			function prev_picture(){
				var ssRunning=false;
				if(pendingEvent){
					ssRunning=true;
					clearTimeout(pendingEvent);
				}
				previmg();
				if(ssRunning){
					//pendingEvent=setTimeout('ss_run()',2000);
					ssRunning = false;
					imageWeAreOn = 1;
					clearTimeout(pendingEvent);
					stop_slide();
				}
			}
			function showPic(p){
				curPic=p;
				//document.images.imgProperty.style.filter="blendTrans(duration=1)";
				//if (document.images.imgProperty.filters) document.images.imgProperty.filters.blendTrans.Apply();
				//document.images.imgProperty.src=ccimages[p].src;
				document.getElementById('imgProperty').style.backgroundImage = 'url("'+ccimages[p].src+'")';
				document.getElementById('caption').innerHTML = ccimages[p].caption;
				//if (document.images.imgProperty.filters) document.images.imgProperty.filters.blendTrans.play();
				document.getElementById('picNum').innerHTML=curPic+1;
				highCurThumb();

				document.getElementById('imgProperty').style.height='350px';
				
				// if width is greater than 555px, add position absolute to centre it to the div.
				/*
				if(document.getElementById('imgProperty').width > 630)
				{
					document.getElementById('imgProperty').style.position = 'absolute';
					document.getElementById('imgProperty').style.left = '-25%';
				}
				else
				{
					document.getElementById('imgProperty').style.position = '';
					document.getElementById('imgProperty').style.left = '';
				}
				*/
			}
			
			/*Highlight the thumbnail of the current picture.*/
			function highCurThumb(){
				for (var t=0;t<ccimages.length;t++){
					if (t==curPic){
						ccimages[t].thumbnail.style.borderColor='#00adef';
					} else{
						ccimages[t].thumbnail.style.borderColor='#ffffff';
					}
				}
			}
			
			function centreThumb(oldPic,newPic,noSmooth){
				if (scrollEvent != null) clearTimeout(scrollEvent);
				
				var lastPic=ccimages.length-1;
				var firstPic=0;
				if (ccimages[0].thumbnail.length != 0) { var scrollPos=-ccimages[0].thumbnail.width; }
				
				for (var t=1;t<newPic;t++){
					if (typeof ccimages[t].thumbnail.width == "number"){
						scrollPos=scrollPos+ccimages[t].thumbnail.width;
						scrollPos=scrollPos+20;
					}
				}
				if (scrollPos<0){
					scrollPos=0;
				}
				
				var smoothStep=0;
				if ((oldPic==lastPic) && (newPic==firstPic)){
					smoothStep=0;
				}else if((oldPic==firstPic) && (newPic==lastPic)){
					smoothStep=0;
				}else if(newPic>oldPic){
					smoothStep=C_scrollStep;
				}else{
					smoothStep=-C_scrollStep;
				}
				if(noSmooth){
					smoothStep=0;
				}
				
				if (smoothStep==0){
					document.getElementById('picThumbnails').scrollLeft=scrollPos;
				}else{
					slowScroll(document.getElementById('picThumbnails').scrollLeft,scrollPos,smoothStep);
				}
			}
			
			function slowScroll(scrollFrom,scrollTo,scrollStep)
			{	
				var curScroll=document.getElementById('picThumbnails').scrollLeft;
				var scrollAmt;
				if ((scrollTo-curScroll)>600){
					scrollAmt=(scrollTo-curScroll);
				}else if ((scrollTo-curScroll)>400){
					scrollAmt=scrollStep*4
				}else if ((scrollTo-curScroll)>200){
					scrollAmt=scrollStep*2
				}else{
					scrollAmt=scrollStep;
				}
 
				if ((scrollStep<0 && curScroll>scrollTo) || (scrollStep>0 && curScroll<scrollTo)){
					document.getElementById('picThumbnails').scrollLeft=curScroll+scrollAmt;
					if (document.getElementById('picThumbnails').scrollLeft!=curScroll){
						scrollEvent=setTimeout('slowScroll(' + scrollFrom + ',' + scrollTo + ',' + scrollStep + ');',C_scrollInterval)
					}
				}
			}
			
			function slide()
			{
				document.getElementById('slideshowSpan').innerHTML="Stop";
				document.getElementById('slideshow').href = 'javascript:stop_slide();';
				document.getElementById('slideshow').title="Stop";
				document.getElementById('slideshow').setAttribute('style', 'color:#27A9DC;');
				ss_run();
				
				ssRunning=true;
			}
			
			function nextimg()
			{					
				if(ssRunning){
					imageWeAreOn++;
				}
				
				var nextPic=curPic+1;
				if (nextPic > ccimages.length-1) nextPic=0;
				centreThumb(curPic,nextPic);
				showPic(nextPic);
			}
				
			function previmg()
			{
				var nextPic=curPic-1;
				if (nextPic < 0) nextPic = ccimages.length-1;
				centreThumb(curPic,nextPic);
				showPic(nextPic);
			}
			
			
			function ss_run()
			{
				if(ssRunning && imageWeAreOn==ccimages.length)
				{
					ssRunning = false;
					imageWeAreOn = 1;
					clearTimeout(pendingEvent);
					stop_slide();
				}
				else
				{
					nextimg();
					pendingEvent=setTimeout('ss_run()',3000);
				}
			}
				
			function stop_slide()
			{
				if (pendingEvent != null) clearTimeout(pendingEvent);
				document.getElementById('slideshowSpan').innerHTML="S/Show"
				document.getElementById('slideshow').href = 'javascript:slide();'
				document.getElementById('slideshow').title="S/Show"
			}
			
			function iniSlideShow()
			{
				var allcomplete=true;
				for (var i=0; i < ccimages.length; i++)
				{
					var img = ccimages[i];
					if (img.complete!=true)
					{
						allcomplete=false;
					}
				}
				//curPic=ccimages.length-1;
				curPic=0;
				if(allcomplete==true)
				{
					document.getElementById('prevSpan').style.visibility='visible';
					document.getElementById('prevSpan').innerHTML="Prev"
					
					document.getElementById('slideshowSpan').style.visibility='visible';
					document.getElementById('slideshowSpan').innerHTML="S/Show"
					
					document.getElementById('nextSpan').style.visibility='visible';
					document.getElementById('nextSpan').innerHTML="Next";
					
					document.getElementById('slideshow').href = 'javascript:slide();';
					document.getElementById('next_picture').href = 'javascript:next_picture();';
					document.getElementById('prev_picture').href = 'javascript:prev_picture();';
				}
				else
				{
					t=setTimeout('iniSlideShow()',2000);
				}
				
			}
			
