//Slideshow Viewer w/MooTools, Copyright (c) 2009 Andrew Munro.

function slideshowinit () {	
	if ($('slideshowinit')) {
		var divCellWidth = 617;
		var thumbsPerRow = 4;
		var indexScroller = new Fx.Scroll('index-scroll', {
			duration: 500,
			transition: Fx.Transitions.Pow.easeOut
		});
		$('title').innerHTML       = showInfo['info1'].title;
		$('slideshow-description').innerHTML = showInfo['info1'].description;
		infoBarLink                = showInfo['info1'].url;
		var selectedThumb      = $('thumb-1').id;
		var currentSlide       = 1;
		var thumbs             = 0;
		var disableIndexScroll = false;
		$('index').getElements('img').each(function(el) {
			el.addEvent('click', function (event) {
				$(selectedThumb).src = '/wp-content/themes/innocentsurfschool/images/thumb.jpg';
				selectedThumb = this.id;
				el.src = '/wp-content/themes/innocentsurfschool/images/thumb-over.jpg';
				$('slideshow').fade('out');
				(function() { 
					$('slideshow').style.background = 'url(/slideshow/slideshow-images/processed/'+showInfo['info'+el.id.substr(6)].image+')';
					$('slideshow-description').innerHTML = showInfo['info'+el.id.substr(6)].description;
					$('title').innerHTML       = showInfo['info'+el.id.substr(6)].title;
					infoBarLink                = showInfo['info'+el.id.substr(6)].url;
					$('slideshow').fade('in'); 
				}).delay(400);
				if (event)
					clearInterval(automator);			
			});
			thumbs = thumbs + 1;
		});
		var totalSlides = Math.ceil(thumbs/thumbsPerRow);
		$('viewer').addEvent('click', function () { 
			if (infoBarLink != '')
				window.location.href = infoBarLink; 
		});
		autoThumb = 1;
		autoThumbSize = $('index').getElements('img').length;
		var automator = (function () {
			if (autoThumb == autoThumbSize) {
				autoThumb = 1;
			} else {
				autoThumb++;
			}
			$('thumb-'+autoThumb).fireEvent('click');
		}).periodical(8000)
		var thumbInt = 1;
	}
}

window.addEvent('domready', slideshowinit); 