///////////// INLINE SLIDESHOW ////////////

indicatorWidth = 79;

autoScrolling = false;
function initSlideshow() {
	// find slideshow items
	
}

iig = 0;
savedPhotoNum = '';
function launchImage(auto) {
	viewableImageNum = savedPhotoNum;
	if (!viewableImageNum) viewableImageNum = 0;
	imgUrl = document.getElementById('iig_img'+viewableImageNum).src;
	imgUrl = imgUrl.replace('http://www.unleashed.org.au','');
	imgUrl = imgUrl.replace('http://localhost','');
	if (imgUrl.indexOf('?')!=-1) {
		imgUrl = imgUrl.substr(imgUrl.indexOf('?')+1)
		imgUrl = imgUrl.substr(imgUrl.indexOf('i=')+2)
		imgUrl = imgUrl.substr(0,imgUrl.indexOf('&'))
	}
	if (imgUrl.indexOf('[')!=-1) {
		caption = imgUrl.substr(imgUrl.indexOf('[')+1);
		caption = caption.replace(']','');
		imgUrl = imgUrl.substr(0,imgUrl.indexOf('['));
		imgUrl += '/cap/'+caption+'.jpg';
	}
	imgUrl = "/resources/view"+imgUrl;
	window.open(imgUrl);
}
function nextImage(auto) {
	if (!auto) toggleAutoPlaySlideshow('pause');
	if (!auto || slideshowInterval) {
		newIig = iig+1;
		if (!document.getElementById('iig_div'+newIig)) newIig = 0;
		savedPhotoNum = newIig;
		fadeOut('iig_img'+iig,'fadeInPhoto();');
	}
}
function autoNextImage() {
	if (ssiInt) clearInterval(ssiInt);
	ssiInt = null;
	nextImage(1);
	ssi = 0;
	ssiInt = setInterval(incrementSlideshowIndicator,ssiIntSpeed);
}
function prevImage() {
	toggleAutoPlaySlideshow('pause');
	newIig = iig-1;
	if (newIig < 0) newIig = (galleryPhotoNum-1);
	savedPhotoNum = newIig;
	fadeOut('iig_img'+iig,'fadeInPhoto();');
}

function fadeInPhoto() {
	fadeIn('iig_img'+savedPhotoNum);
	showPhoto();
}

function showPhoto(photoNum) {
	if (!photoNum && photoNum!==0) photoNum = savedPhotoNum;
	iigOld = iig;
	iig = photoNum;
	if (document.getElementById('iig_div'+iigOld)) document.getElementById('iig_div'+iigOld).className = '';
	if (document.getElementById('iig_div'+iig)) document.getElementById('iig_div'+iig).className = 'selected';
	iigOld = iig;
}
function flashPhoto(photoNum) {
	toggleAutoPlaySlideshow('pause');
	showPhoto(photoNum);
	if (!document.getElementById('iig_img'+photoNum).getAttribute('opa')) blinkImg(photoNum,6);
	window.location = "#slideshow";
}
function blinkImg(picId,blinkCnt) {
	elImg = document.getElementById('iig_img'+picId);
	opa = (elImg.getAttribute('opa')==50) ? 100 : 50;
	elImg.setAttribute('opa', opa);
	setOpacity('',opa,elImg);
	blinkCnt--;
	if (blinkCnt) {
		setTimeout("blinkImg('"+picId+"','"+blinkCnt+"')",100);
	} else elImg.removeAttribute('opa');
}

// slideshowAutoInt = '';
function slideshowAutoNext() {
	if (slideshowInterval) {
		// if (slideshowAutoInt) clearInterval(slideshowAutoInt);
		// slideshowAutoInt = null;
		// slideshowAutoInt = setInterval(autoNextImage,(slideshowInterval*1000));
		
		if (ssiInt) clearInterval(ssiInt);
		ssiInt = null;
		ssiInt = setInterval(incrementSlideshowIndicator,ssiIntSpeed);
	}
}
ssi = 0;
ssiInt = '';
ssiIntSpeed = 200;
function incrementSlideshowIndicator() {
	if (slideshowInterval) {
		ssiInc = indicatorWidth*(ssiIntSpeed/(slideshowInterval*1000));
		ssi += ssiInc;
		if (ssi <= indicatorWidth) {
			newWidth = Math.round(ssi)+1;
		} else {
			ssi=0;
			newWidth = 1;
			if (ssiInt) clearInterval(ssiInt);
			ssiInt = null;
			autoNextImage();
		}
		if (document.getElementById('slideshow_indicator')) document.getElementById('slideshow_indicator').style.width = newWidth+'px';
	} else {
		ssi=0;		
		if (ssiInt) clearInterval(ssiInt);
		ssiInt = null;
	}
}
if (slideshowInterval) startMeUp += "slideshowAutoNext();";



function toggleAutoPlaySlideshow(instruction) {
	if (originalSlideshowInterval) {
		if (!instruction) instruction = (slideshowInterval) ? 'pause' : 'play';
		if (instruction=='pause') {
			slideshowInterval = 0;
			// if (slideshowAutoInt) clearTimeout(slideshowAutoInt);
			// slideshowAutoInt = null;
			if (ssiInt) clearInterval(ssiInt);
			ssiInt = null;
			document.getElementById('slideshow_hover').className = 'paused';
		} else {
			slideshowInterval = originalSlideshowInterval;
			document.getElementById('slideshow_hover').className = 'playing';
			slideshowAutoNext();
		}
		ssi = 0;
		document.getElementById('slideshow_indicator').style.width = '1px';
	}
}

