var iQslideshow = {
	init: function() {
		var bigPhoto = $('currentphoto');
		
		/* Image caption */
		var caption = document.createElement('div');
		var insCaption = bigPhoto.parentNode.insertBefore(caption, bigPhoto);
		caption.id = 'imagecaption';
		caption.innerHTML = '<div>' + bigPhoto.getAttribute('alt') + '</div>';
		caption.style.display = 'none';
		bigPhoto.removeAttribute('alt');
		bigPhoto.onmouseover = function() {
			Effect.SlideDown('imagecaption', {duration: 0.2});
		};
		bigPhoto.onmouseout = function() {
			Effect.SlideUp('imagecaption', {duration: 0.2});
		};
		
		/* Image selector */
		var photoSelector;
		if($('photoselector')) {
			// Create the arrows
			$('prev-arrow-container').innerHTML = '<a id="prev-arrow" class="left-button-image">Previous</a>';
			
			$('next-arrow-container').innerHTML = '<a id="next-arrow" class="next-button-image">Next</a>';
			
			// Turn on the stylesheet
			$('carouselcss').rel = 'stylesheet';
			$('carouselcss').disabled = false;
			
			var carousel = new Carousel('photoselector',  {buttonStateHandler: iQslideshow.buttonStateHandler, animParameters: {duration: 0.4}});
			
			// Scroll to the current photo
			if(window.currentPhoto && window.currentPhoto >= carousel.options.numVisible) {
				carousel.scrollTo(Math.floor(window.currentPhoto / carousel.options.numVisible) * carousel.options.numVisible);
			}
		}
		
	},
	
	buttonStateHandler: function(button, enabled) {
		if(enabled) {
			$(button).removeClassName('disabled');
		} else {
			$(button).addClassName('disabled');
		}
	}
};

document.observe('dom:loaded', iQslideshow.init);