onLoad(function(){
	var bL = document.getElementById('galBtnL');
		disableSelection(bL);
		bL.onclick=slidePrev;
	var bR = document.getElementById('galBtnR');
		disableSelection(bR);
		bR.onclick=slideNext;
	ajax('gallery.php', 'spo_gallery', function(){ var gal = document.getElementById('spo_gallery').getElementsByTagName('IMG'); sparo.galleryLen = gal.length; startAuto(); });
});

/*
 * Gallery Controls
 */
sparo.galleryAt = 0;
function slideNext() {
	stopAuto();
	if(sparo.galleryAt < sparo.galleryLen-1) {
		if(sparo.galleryAt === 0){ document.getElementById('galBtnL').style.display = ''; }
		sparo.galleryAt++;
		moveTo(document.getElementById('spo_gallery'), sparo.galleryAt * -620, null, 4);
		if(sparo.galleryAt === sparo.galleryLen-1){ document.getElementById('galBtnR').style.display = 'none'; }
	}
}
function slidePrev() {
	stopAuto();
	if(sparo.galleryAt > 0) {
		if(sparo.galleryAt === sparo.galleryLen-1){ document.getElementById('galBtnR').style.display = ''; }
		sparo.galleryAt--;
		moveTo(document.getElementById('spo_gallery'), sparo.galleryAt * -620, null, 4);
		if(sparo.galleryAt === 0){ document.getElementById('galBtnL').style.display = 'none'; }
	}
}
function slideAuto() {
	if(sparo.galleryAt < sparo.galleryLen-1) {
		if(sparo.galleryAt === 0){ document.getElementById('galBtnL').style.display = ''; }
		sparo.galleryAt++;
		moveTo(document.getElementById('spo_gallery'), sparo.galleryAt * -620, null, 4);
		if(sparo.galleryAt === sparo.galleryLen-1){ document.getElementById('galBtnR').style.display = 'none'; stopAuto(); setTimeout(returnHome, 6000); }
	}
}
function startAuto() {
	sparo.autoScroll = setInterval(slideAuto, 6000);
}
function stopAuto() {
	if(sparo.autoScroll){
		clearInterval(sparo.autoScroll);
		sparo.autoScroll = null;
	}
}
function returnHome() {
	moveTo(document.getElementById('spo_gallery'), 0, null, 4);
	document.getElementById('galBtnL').style.display = 'none';
	document.getElementById('galBtnR').style.display = '';
	sparo.galleryAt = 0;
}






