CSI = window.CSI || {};
CSI.slideshowExists = false;
CSI.slideshow = function (images, options) {
	if (!CSI.slideshowExists || options.embedded) { //the embedded check allows for multiple iterations of the embedded slideshow.
		return prepareSlideshow(images);
	}
	function prepareSlideshow(images) {
		CSI.slideshowExists = true;
		if (!images || images.length < 1) return;
		if (images.length == 1) options.hideButtons = true;
		//Preload images
		var imgs = [];
		for (var i=0;i<images.length;i++) {
			var img = new Image();
			img.src = images[i].src;
		}
		options = options || {};
		var delay = options.delay || 3000;
		var captionBoxHeight = 0;
		if (options.styles && !options.separateCaptionBox && !options.embedded) {
			if (options.styles.captionBox) {
				captionBoxHeight = parseInt(options.styles.captionBox, 10);
			} else {
				captionBoxHeight = 54;
			}
		}
		options.height = options.height || 484 - captionBoxHeight;
		getScroll();
		var testHeight = windowHeight - 40;
		if (options.height > testHeight - 50 && !options.embedded) {
			options.height = testHeight - 50;
			options.width = options.height * 1.3;
		}
		options.height = options.height || 440;
		options.width = options.width || options.height * 1.3;
		if (!CSI.slideshowDiv){ 
			var d = CSI.slideshowDiv = createBox();
			if (options.embedded) {
				d.style.postion = 'relative';
			} /*else {
				if (options.overlay) {
					d.overlay = document.createElement('div');
					Object.extend(d.overlay.style, {
						width : 1000 + 'px',
						height : 1000 + 'px',
						background : '#000000',
						opacity : '.5'
					});
					document.body.appendChild(d.overlay);
				}
			}*/
			Object.extend(d.style,{background:'black', padding:'0px'});
			d.innerHTML = '<ul id="slide-images"><li class="showLi"><img /></li><li class="showLi"><img /></li></ul>';
			Object.extend(d.firstChild.style,{position:'relative', margin:'0px', padding:'0px', right: '0', top:'0', width:'25px'});
			Object.extend(d.firstChild.firstChild.style,{listStyleType:'none',position:'absolute', display:'block', margin:'0px', padding:'0px'});
			Object.extend(d.firstChild.lastChild.style,{listStyleType:'none',position:'absolute', display:'block', margin:'0px', padding:'0px'});
			if (!options.embedded) d.parentNode.style.zIndex = 3000;
			//adds close button if popup
			if (!options.embedded) {
				//set srcs for button, create
				var closeSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-close.png' : (options.buttons.close || '/wwwroot/remaint/images/sc-close.png');
				var closeDownSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-close-d.png' : (options.buttons.closeDown || '/wwwroot/remaint/images/sc-close-d.png');
				var myImg = document.createElement('img');
				//necessary attribute adding
				myImg.style.cssText = ';position:relative; float:right; margin-top:-1px; z-index:999;cursor:pointer;';
				if (Prototype.Browser.IE && document.compatMode == 'BackCompat') {
					myImg.style.cssText = myImg.style.cssText  + '; margin-left:5px !important';
				}
				myImg.className = 'ssCloseButton';
				myImg.src = closeSrc;
				if (options.styles) Object.extend(myImg.style, options.styles.closeButton);
				//smallbuttons option makes this small also
				if (options.smallButtons) {
					myImg.width = myImg.height = 23;
				} else if (options.buttonSize) {
					myImg.width = myImg.height = parseInt(options.buttonSize, 10);
				}
				//function called on close of slideshow - popup only
				d.terminate = function(){
					if (d) {
						clearTimeout(d.timeoutHolder);
						clearTimeout(d.getNextTimeout);
						//var lis = d.getElementsByClassName('showLi');
						lis = $('slide-images').children;
						lis[1].style.visibility = lis[0].style.visibility = '';  
						lis[1].style.display = lis[0].style.display = '';  
						//var caps = d.getElementsByClassName('captionLi');
						var caps = $('slide-captions').children;
						caps[1].style.visibility = caps[0].style.visibility = '';  
						caps[1].style.display = caps[0].style.display = '';  
						d.active = false;
						d.style.visibility='hidden';
						d.style.display='block';
						//if (d.overlay) d.overlay.remove();
						d.close();
						d.remove();
						d = undefined; 
						CSI.slideshowExists = false;
						CSI.slideshowDiv = null;
					}
				};
				//append to wrapper
				d.appendChild(myImg);
				//close button functionality
				Event.observe(myImg,'click', d.terminate);
				Event.observe(window,'scroll', d.terminate);
				Event.observe(myImg, 'mouseleave', function() { myImg.src = closeSrc; });
				Event.observe(myImg, 'mouseenter', function() { myImg.src = closeDownSrc; });
			}
			//set button sources
			var previousSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-left.png' : (options.buttons.previous || '/wwwroot/remaint/images/sc-left.png');
			var previousDownSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-left-d.png' : (options.buttons.previousDown || '/wwwroot/remaint/images/sc-left-d.png');
			var pauseSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-pause.png' : (options.buttons.pause || '/wwwroot/remaint/images/sc-pause.png');
			var pauseDownSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-pause-d.png' : (options.buttons.pauseDown || '/wwwroot/remaint/images/sc-pause-d.png');
			var playSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-play.png' : (options.buttons.play || '/wwwroot/remaint/images/sc-play.png');
			var playDownSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-play-d.png' : (options.buttons.playDown || '/wwwroot/remaint/images/sc-play-d.png');
			var nextSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-right.png' : (options.buttons.next || '/wwwroot/remaint/images/sc-right.png');
			var nextDownSrc = (options.buttons === undefined) ? '/wwwroot/remaint/images/sc-right-d.png' : (options.buttons.nextDown || '/wwwroot/remaint/images/sc-right-d.png');
			//build control div
			d.controlDiv = document.createElement('div');
			d.controlDiv.className = 'ssControlDiv';
			d.controlDiv.style.display = 'none';
			//creates fade effect variables, so back and forth buttons work seamlessly
			d.frameFadeEffect = '';
			d.frameAppearEffect = '';
			//create the buttons
			var previousButton = new Image();
			var pauseButton = new Image();
			var playButton = new Image();
			var nextButton = new Image();
			//set button load variable to zero
			d.buttonLoadCount = 0;
			//set function onload of the image
			previousButton.onload = function() { placeButtons() };
			pauseButton.onload = function() { placeButtons() };
			playButton.onload = function() { placeButtons() };
			nextButton.onload = function() { placeButtons() };
			//set visibility to hidden (set to visible in placeButtons() )
			previousButton.style.visibility = nextButton.style.visibility = pauseButton.style.visibility = playButton.style.visibility = 'hidden';
			//set button styles
			if (options.styles) {
				if (options.styles.previousButton) {
					Object.extend(previousButton.style, options.styles.previousButton)
				}
				if (options.styles.nextButton) {
					Object.extend(nextButton.style, options.styles.nextButton);
				}
				if (options.styles.pauseButton) {
					Object.extend(pauseButton.style, options.styles.pauseButton);
				}
				if (options.styles.playButton) {
					Object.extend(playButton.style, options.styles.playButton);
				}
			}
			//preload images, so positioning works all the time
			var preloadImg = new Image();
			preloadImg.src = playSrc;
			preloadImg.src = playDownSrc;
			preloadImg.src = pauseSrc;
			preloadImg.src = pauseDownSrc;
			preloadImg.src = nextSrc;
			preloadImg.src = nextDownSrc;
			preloadImg.src = previousSrc;
			preloadImg.src = previousDownSrc;
			//set srcs, loading images
			previousButton.src = previousSrc;
			pauseButton.src = pauseSrc;
			playButton.src = playSrc;
			nextButton.src = nextSrc;
			//set class names
			previousButton.className = 'ssPrevious';
			pauseButton.className = 'ssPause';
			playButton.className = 'ssPlay';
			nextButton.className = 'ssNext';
			//set titles correctly
			previousButton.title = 'Previous';
			nextButton.title = 'Next';
			pauseButton.title = 'Pause';
			playButton.title = 'Play';
			//set class name
			previousButton.className = pauseButton.className = playButton.className = nextButton.className = 'ssControlButton';
			//set cursor
			previousButton.style.cursor = pauseButton.style.cursor = playButton.style.cursor = nextButton.style.cursor = 'pointer'
			playButton.style.display = 'none';
			//append to control div IFF more than one image
			d.controlDiv.appendChild(previousButton);
			d.controlDiv.appendChild(pauseButton);
			d.controlDiv.appendChild(playButton);
			d.controlDiv.appendChild(playButton);
			d.controlDiv.appendChild(nextButton);
			//removes buttons if only one image
			//allows smallbutton settings for normal images
			if (options.smallButtons) {
				previousButton.height = previousButton.width = pauseButton.height = pauseButton.width = playButton.height = playButton.width = nextButton.height = nextButton.width = 23;
			} else if (options.buttonSize) {
				previousButton.height = previousButton.width = pauseButton.height = pauseButton.width = playButton.height = playButton.width = nextButton.height = nextButton.width = parseInt(options.buttonSize, 10);
			}
			//function called on pause press
			d.pause = function(){
				playButton.style.display = 'inline';
				pauseButton.style.display = 'none';
				clearTimeout(d.timeoutHolder);
				clearTimeout(d.getNextTimeout);
				d.paused = true;
			}
			//button functionality
			Event.observe(pauseButton,'click',function(){ // pause
				d.pause();
			});
			Event.observe(playButton,'click',function(){ // play
				this.style.display = 'none';
				this.previousSibling.style.display = 'inline';
				d.paused = false;
				d.timeoutHolder = setTimeout(transition(), 500);
			});
			Event.observe(previousButton,'click',function(){ // previous
				d.pause();
				setImage(-1);
			});
			Event.observe(nextButton,'click',function(){ // next
				d.pause();
				if (d.isFading) {
					d.isFading = false;
				} else {
					setImage(1);
				}
			});
			//button rollover style effects
			Event.observe(previousButton, 'mouseenter', function() { previousButton.src = previousDownSrc; });
			Event.observe(previousButton, 'mouseleave', function() { previousButton.src = previousSrc; });
			Event.observe(pauseButton, 'mouseenter', function() { pauseButton.src = pauseDownSrc; });
			Event.observe(pauseButton, 'mouseleave', function() { pauseButton.src = pauseSrc; });
			Event.observe(playButton, 'mouseenter', function() { playButton.src = playDownSrc; });
			Event.observe(playButton, 'mouseleave', function() { playButton.src = playSrc; });
			Event.observe(nextButton, 'mouseenter', function() { nextButton.src = nextDownSrc; });
			Event.observe(nextButton, 'mouseleave', function() { nextButton.src = nextSrc; });
			//fade of pause button on mouse out
			if (options.fadePause) {
				var fadeOutEffect = new Effect.Fade(pauseButton, { duration : 2});
				var fadeInListener = Event.observe(d.firstChild, 'mouseover', function() { 
					fadeOutEffect.cancel();
					pauseButton.style.filter = 'alpha(opacity=100)';
					pauseButton.style.opacity = '1.0';
					if (playButton.style.display == 'none') {
						pauseButton.style.display = 'block';
					}
				});
				var newFadeInListener = Event.observe(pauseButton, 'mouseover', function() {
					fadeOutEffect.cancel();
					pauseButton.style.filter = 'alpha(opacity=100)';
					pauseButton.style.opacity = '1.0';
					if (playButton.style.display == 'none') {
						pauseButton.style.display = 'block';
					}
				});
				var fadeOutListener = Event.observe(d.firstChild, 'mouseout', function() { fadeOutEffect = new Effect.Fade(pauseButton, { duration : 2, from : 1.0, to : 0 }); })
			}
			d.caption = d.appendChild(document.createElement('div'));
			//determine caption height - taller if displayed as address and button
			var captionHeight = (options.classId) ? '44px' : '54px';
			//default styles for caption div
			Object.extend(d.caption.style, {
				width: options.width - 6 + 'px'
				,padding:'3px'
				,height:'54px'
				,position:'absolute'
				,backgroundColor:'black'
				,color:'white'
				,fontWeight : 'normal'
				,fontSize : '13px'
				,fontFamily:'Arial, Helvetica, Sans Serif'
				,textAlign:'center'
				,overflow:'hidden'
				,lineHeight:'18px'
			});
			if (options.separateCaptionBox) Object.extend(d.caption.style, { marginTop:options.height + 'px' });
			else  Object.extend(d.caption.style, { bottom:'0px' });
			//make caption <ul> for rotating captions
			d.caption.innerHTML = '<ul id="slide-captions"><li class="captionLi"><span>This is caption 1</span></li><li class="captionLi"><span>This is caption 2</span></li></ul>';
			//allows for hiding of caption box
			if (options.hideCaptions) {
				d.caption.style.visibility='hidden';
				d.caption.style.display='none';
			}
			//adds controlDiv to wrapper div
			if (!options.hideButtons && images.length != 1) {
				d.appendChild(d.controlDiv);
				d.controlDiv.style.position = 'absolute';
				d.controlDiv.style.backgroundColor = 'transparent';
			}
			//preloads images
			var imgs = d.getElementsByTagName('img');
			for (var i=0; i<=1; i++) {
				imgs[i].onload = sizeImage;
			}
			//allows fully custom CSS from caller
			if (options.styles) {
				if (options.styles.captionBox) Object.extend(d.caption.style, options.styles.captionBox);
				if (options.styles.pictureBox) Object.extend(d.style, options.styles.pictureBox);
			}
			//finish declaring styles, respecting caller's css for caption box overflow: 'inherit',
			Object.extend(d.caption.firstChild.style,{ position:'relative', margin:'auto', padding : '0px',paddingLeft:'5px', paddingRight : '5px', right: '0', top:'0',height: '' +  d.caption.style.height + '' });
			Object.extend(d.caption.firstChild.firstChild.style,{listStyleType:'none', width: d.caption.style.width, margin : 'auto !important', position:'absolute', display:'block', margin:'0px', padding:'0px', textAlign: 'center', overflow:'visible', left : '0px'});
			Object.extend(d.caption.firstChild.lastChild.style,{listStyleType:'none', width: d.caption.style.width, margin: 'auto !important', position:'absolute', display:'none', margin:'0px', padding:'0px', textAlign: 'center', overflow:'visible', left : '0px'});
			if (Prototype.Browser.IE && document.compatMode == 'BackCompat') {
				//Object.extend(d.caption.style, {paddingTop : '0px')};
				Object.extend(d.caption.firstChild.style,{ marginLeft : '0px', paddingTop : '0px' });
				Object.extend(d.caption.firstChild.firstChild.style,{ marginTop : '-5px', paddingTop : '0px' });
				Object.extend(d.caption.firstChild.lastChild.style,{ marginTop : '-5px', paddingTop : '0px' });
			}
			//adds appropriate space in wrapper
			if ((!options.embedded && !options.hideCaptions) || !options.separateCaptionBox) {
				d.style.paddingBottom = parseInt(d.caption.style.paddingBottom, 10) + parseInt(d.caption.style.paddingTop, 10) + 3+ 'px';
			}
		}		
		d.initialize = d.active = true;
		d.controlDiv.children[2].style.display = 'none';
		d.controlDiv.children[1].style.display = 'inline';
		
		if (d.clonedCaption){
			d.removeChild(d.clonedCaption)
			d.clonedCaption = false;
		}
		if (options.caption){
			d.caption.innerHTML = options.caption;
			d.caption.style.display = 'block';
			var tds = d.caption.getElementsByTagName('td');
			for (var i=0; i<tds.length; i++){
				Object.extend(tds[i].style,{padding:'3px', color:'#fff'});
			}
			d.clonedCaption = d.caption.cloneNode(true);
			Object.extend(d.clonedCaption.style,{backgroundColor:'',opacity:'',filter:''});
			d.appendChild(d.clonedCaption);
			for (var i=0; i<tds.length; i++){
				Object.extend(tds[i].style,{padding:'3px', color:''});
			}
		}
		var height, width;
		d.images = images;
		//lis = d.getElementsByClassName('showLi');
		lis = $('slide-images').children;
		slideshowCounter = 0;
		d.images.index = 1;
		d.paused = false;	

		lis[0].style.display = 'none';
		lis[1].style.display = 'none';
		lis[0].style.visibility = 'hidden';  
		lis[1].style.visibility = 'hidden';
		lis[0].firstChild.style.width = lis[0].firstChild.style.height = '';
		lis[1].firstChild.style.width = lis[1].firstChild.style.height = '';
		lis[0].firstChild.src = d.images[0].src;
		sizeImage(lis[0].firstChild);
		//Allows hyperlinking of an image
		if (d.images[0].href !== undefined) {
			Event.observe(lis[0], "click", function() {
				window.location = d.images[0].href;
			});
			lis[0].firstChild.style.cursor = 'pointer';
		} else {
			Event.observe(lis[0], "click", function(e) {
				Event.stop(e);
			});
			lis[0].firstChild.style.cursor = 'normal';
		}
		
		caps = $('slide-captions').children;
		caps[0].innerHTML = d.images[0].caption;
		caps[1].innerHTML = d.images[1].caption;
		if (d.images.length > 1){
			setTimeout(function(){
				//var lis = d.getElementsByClassName('showLi');
				lis = $('slide-images').children;
				lis[1].firstChild.src = d.images[1].src;
				sizeImage(lis[1].firstChild);
			},1);
		}
		else {
			d.controlDiv.style.display = 'none';
		}
		
		if (options.paused || d.images.length == 1){
			d.pause();
		}
		else {
			d.timeoutHolder = setTimeout(transition(), delay);
		}
		caps[0].style.marginLeft = ((parseInt(d.caption.style.width, 10) - caps[0].offsetWidth)/2 - 1) + 'px';
		caps[1].style.marginLeft = ((parseInt(d.caption.style.width, 10) - caps[0].offsetWidth)/2 - 1) + 'px';
			
		//appends or shows wrapper div so the first image sizes correctly
		Event.observe(lis[1].firstChild, "load", function() {
			if (options.embedded) {
				//this fixed the annoying issue of text-align ruining everything in IE7.
				$(options.targetDiv).style.textAlign = 'left';
				$(options.targetDiv).appendChild(d);
			} else {
				d.show();
				Event.observe(window, "resize", function() { if (d !== undefined) d.center(); });
			}	
			//place the buttons
			if (d.images.length != 1) placeButtons();
		});	
		Event.observe(lis[0].firstChild, "load", function() {
			//place the buttons
			if (d.images.length != 1) placeButtons();
		});
		
		//button positioning function, called on slideshow load to ensure correct positioning.
		function placeButtons() {
			d.buttonLoadCount++;
			if (d.buttonLoadCount >= 4) {
				//set visibility to visible so they don't show up in the wrong spot
				previousButton.style.visibility = 'visible';
				nextButton.style.visibility = 'visible';
				pauseButton.style.visibility = 'visible';
				playButton.style.visibility = 'visible';
			}
			//Event observes for all buttons so placing works actually.
			//vertical - defaults to top
			if (options.buttonVertPos == 'middle') {
				d.controlDiv.style.marginTop = (options.height - previousButton.height)/2 + 'px';
			} else if (options.buttonVertPos == 'bottom') {
				d.controlDiv.style.bottom = (options.separateCaptionBox ? 0 : d.caption.offsetHeight) + 'px';
			}
			//horizontal - defaults to left
			if (options.buttonHorizPos == 'outside') {
				previousButton.style.position = pauseButton.style.position = playButton.style.position = nextButton.style.position = 'absolute';
				previousButton.style.marginLeft = '-' + previousButton.width + 'px';
				pauseButton.style.marginLeft = (options.width - pauseButton.width)/2 + 'px';
				playButton.style.marginLeft = (options.width - playButton.width)/2 + 'px';
				if (options.buttonVertPos == 'middle') {
					pauseButton.style.marginTop = (options.height - pauseButton.height)/2 + 'px';
					playButton.style.marginTop = (options.height - playButton.height)/2 + 'px';
				}
				nextButton.style.marginLeft = options.width + 'px';
			} else if (options.buttonHorizPos == 'center') {
				d.controlDiv.style.marginLeft = (options.width - (pauseButton.width + previousButton.width + nextButton.width))/2 + 'px'; 
			} else if (options.buttonHorizPos == 'right') {
				d.controlDiv.style.marginLeft = (options.width - (pauseButton.width + previousButton.width + nextButton.width)) + 'px';
			}
			d.controlDiv.style.display = '';
		}
		
		function setImage(i) {
			i--;
			var theIndex = d.images.incrementIndex(i);
			var on = slideshowCounter%2;
			var off = (slideshowCounter+1)%2;
			lis[on].firstChild.style.height = lis[on].firstChild.style.width = '0px';
			lis[on].firstChild.src = d.images[d.images.index].src;
			
			//Allows custom hyperlinking of an image
			currentIndex = d.images.index;
			if (d.images[d.images.index].href !== undefined) {
				Event.observe(lis[on], "click", function() {
					window.location = d.images[currentIndex].href;
				});
				lis[on].firstChild.style.cursor = 'pointer';
			} else {
				Event.observe(lis[on], "click", function(e) {
					Event.stop(e);
				});
				lis[on].firstChild.style.cursor = 'normal';
			}
			
			lis[on].firstChild.style.opacity = 1;
			lis[off].firstChild.src = d.images[d.images.incrementIndex(1)].src;
			if (options.rotateCaptions) {
				caps[on].innerHTML = d.images[theIndex].caption;
				caps[off].innerHTML = d.images[d.images.index].caption;
			}
		}
		function sizeImage() {
			if(this !== window) {
				if (d.initialize && lis[0]==this.parentNode) {
					d.initialize = false;
					lis[0].style.display = 'block';
					lis[0].style.visibility = 'visible';
					height = options.height || this.height;
					width = options.width || this.width;
					if (!options.hideCaptions && !options.separateCaptionBox) {
						height = height + parseInt(d.caption.style.height, 10);
					}
					getScroll();
					var testHeight = windowHeight - 30;
					if (height > testHeight){
						var adj = testHeight/height;
						options.height = height = height * adj
						options.width = width = width * adj
					}
					d.style.width = width+'px';
					d.style.height = height+'px';
					if (options.embedded) {
						$(options.targetDiv).appendChild(d);
					} else {
						d.center().show();
						myImg.style.left = '0px';
					}
				}
				if(!width) {
					width = options.width;
				}
				
				var disp = this.parentNode.style.display;
				this.parentNode.style.display = 'block';
				this.style.width = this.style.height = '';
				this.style.width = options.width + 'px';
				var adj = Math.max((this.offsetWidth-width)/width,(this.offsetHeight-height)/height);

				try {
					//fix for quirks mode
					if (Prototype.Browser.IE && document.compatMode == 'BackCompat') {
						this.style.width = (parseInt(this.offsetWidth / (1+adj), 10) - 2) +'px';
						this.parentNode.style.marginLeft = '-1px';
					} else {
						this.style.width = parseInt(this.offsetWidth / (1+adj), 10) +'px';
					}
				}
				catch (err){
					if (window.console)
						console.log('|---'+this.width+'|\n'+lis[0]==this.parentNode);
				}
				
				if (this.offsetHeight > options.height) {
					this.style.height = options.height + 'px';
					this.style.width = '';
				}
				
				this.style.marginLeft = this.style.marginRight = parseInt((width-parseInt(this.offsetWidth, 10))/2, 10)+'px';
				this.style.marginTop = parseInt((options.height-this.offsetHeight)/2, 10)+'px';
				this.parentNode.style.display = disp;
				
				if (this.parentNode.style.visibility=='hidden') {  
					this.parentNode.style.visibility='visible';
					this.parentNode.style.display='none';
				}
			}
		}
		function transition(frame) {
			return (function() {
				var off = (slideshowCounter++)%2;
				var on = slideshowCounter%2;
				//var lis = d.getElementsByClassName('showLi');
				lis = $('slide-images').children;
				//separate if statements due to instantaneous nature of d becoming closed, thereby undefined.
				//fixes error regarding d.frameAppearEffect when slideshow is closed during transitions.
				if (d) d.isFading = true;
				if (d) d.frameFadeEffect = Effect.Fade(lis[off], { afterFinish : function() { if (d) d.isFading = false; } });
				if (d) d.frameAppearEffect = Effect.Appear(lis[on]);
				//This allows caption changing
				if (options.rotateCaptions) {
					//var caps = d.getElementsByClassName('captionLi');
					var caps = $('slide-captions').children;
					Effect.Fade(caps[off]);
					caps[on].style.display = 'none';
					caps[on].style.visibility = 'visible';
					Effect.Appear(caps[on]);
				}
				//Allows custom hyperlinking of an image
				if (d.images[d.images.index].href) {
					var currentIndex = d.images.index;
					Event.observe(lis[on].firstChild, "click", function() {
						window.location = d.images[currentIndex].href;
					});
					lis[on].firstChild.style.cursor = 'pointer';
				} else {
					Event.observe(lis[on].firstChild, "click", function(e) {
						Event.stop(e);
					});
					lis[on].firstChild.style.cursor = 'normal';
				}
				
				d.images.incrementIndex(1);
				
				d.getNextTimeout = setTimeout(function(){
					var img = lis[off].firstChild;
					img.style.marginLeft = img.style.marginRight = img.style.marginTop = img.style.marginBottom = '';
					img.style.height = img.style.width = '0px';
					img.parentNode.style.display = 'block';
					img.parentNode.style.visibility = 'hidden';
					img.style.visibility = 'visible';
					img.style.display = 'block';
					img.src = d.images[d.images.index].src;
					//change caption text
					if (options.rotateCaptions) {
						var cap = caps[off];
						cap.style.display = 'block';
						cap.style.visibility = 'hidden';
						cap.innerHTML = d.images[d.images.index].caption;
					}
				},1200);
				if (!d.paused) d.timeoutHolder = setTimeout(transition(frame), delay + 1850);
			})
		}
		return d;
	}
}
//necessary function for incrementing index, somehow broken in csitools
Array.prototype.incrementIndex = function (i) {
	if (!i) return this.index;
	if (this.length < 2)
		return this.index = 0;
	this.index = this.index+i;
	while (this.index < 0)
		this.index = this.length+this.index;
	while (this.index > (this.length-1))
		this.index = this.index - this.length;
	return this.index;
}
