var scroll;
var effect;
var initLeft;
function checkContinue() {
	if(!scroll)
		effect.cancel();
}
function thumb_right_start() {	// actually moves panel to the left, revealing to right
	var thumbpanel = document.getElementById('thumbpanel');
	var thumbmask = document.getElementById('thumbmask');
	scroll = true;
	var effectDistance = thumbpanel.offsetWidth-thumbmask.offsetWidth+thumbpanel.offsetLeft-initLeft;
	var effectTime = effectDistance / 100;
	//var effectDistance = initLeft-thumbpanel.offsetWidth+thumbmask.offsetWidth;
	//var effectTime = (thumbpanel.offsetLeft-effectDistance) / 100;
	if(effectDistance > 0)
		effect = new Effect.Move(thumbpanel, { x: -effectDistance, duration: effectTime, fps: 40, mode: 'relative', afterUpdate: checkContinue});
}
function thumb_stop() {
	scroll = false;
}
function thumb_left_start() {
	var thumbpanel = document.getElementById('thumbpanel');
	var thumbmask = document.getElementById('thumbmask');
	scroll = true;
	var effectDistance = initLeft-thumbpanel.offsetLeft;
	var effectTime = effectDistance / 100;
	if(effectDistance > 0)
		effect = new Effect.Move(thumbpanel, { x: effectDistance, duration: effectTime, fps: 40, mode: 'relative', afterUpdate: checkContinue});
}
function thumb_init() {
	initLeft = document.getElementById('thumbpanel').offsetLeft;
}
function displayPhoto(filename, width, height, id) {
	if(location.href.indexOf('portfolio.php') != -1) {
		var photo = document.getElementById('portfoliophoto');
		photo.style.display = "none";
		photo.src = "images/spacer.gif";
		photo.src = "photos/full/"+filename;
		photo.width = width;
		photo.height = height;
		photo.style.display = "inline";
	}
	else
		window.location = "portfolio.php?id="+id;
}
function createClientGallery() {
	$('submit').value = 'Creating...';
	$('submit').disabled = true;
	showLoading();
	new Ajax.Updater('response', 'client/create.php', {postBody:Form.serialize('client_gal_setup')+'&ajax=true', onSuccess:cg_reqSuccess, onComplete:hideLoading});
	return false;
}
function cg_reqSuccess() {
	setTimeout('cg_reqSuccessInternal()', 5);
}
function cg_reqSuccessInternal() {
	$('submit').value = 'Next →';
	$('submit').disabled = false;
	
	var response = $('response').innerHTML;
	if(response.indexOf('success(~)') > -1) {
		response = response.split('|');
		window.location = "admin.php?op=clientsetup&pg=4&email="+response[1]+"&pass="+response[2];
	}
	else {
		$('status').innerHTML = 'Error: '+response;
	}
}
function showLoading() {
	var loading = $('loading');
	if(loading) {
		loading.style.display = "inline";
	}
}
function hideLoading() {
	var loading = $('loading');
	if(loading) {
		loading.style.display = "none";
	}
}