function switchthumbs(from, to)
{
	$('#set'+from).fadeOut('fast',function(){ $('#set'+to).fadeIn('fast'); });
}
function loadphoto(photo_url)
{
	$('#photo_img').html('<img src="/uploads/gallery/'+photo_url+'" />');
}
$(document).ready(function() {
	var album_id = $('#album_id').attr('value');
	if(album_id == '')
	{
		alert('Error: no album ID found!');
	}
	$('#userfile').uploadify({
		'uploader'		: '/global/images/uploadify/uploadify.swf',
		'script'		: '/gallery/upthefile/'+album_id,
		'fileDataName'	: 'userfile',
		'cancelImg'		: '/global/images/uploadify/cancel.png',
		'auto'			: true,
		'multi'			: true
	});
	$('#allphotos').sortable({
		items: '.photo',
		opacity: 0.5,
		placeholder: 'ui-state-highlight',
		forcePlaceholderSize: true,
		revert: true,
		tolerance: 'pointer',
		update: function() { getorder(); }
	});
});
function onAllComplete()
{
	alert('yay');
}
function getorder()
{
	// alert('yo!');
}
function makethumb()
{
	var photo_id = $('input:radio:checked').attr('value');
	var album_id = $('#album_id').attr('value');
	if(photo_id)
	{
		$('#photooptions').hide();
		$('#doingstuff').show();
		$.ajax({
			type: "POST",
			url: "/gallery/makealbumthumb/",
			dataType: "html",
			data: {	photo_id: photo_id, album_id: album_id },
			error: function() { alert('Oh oh! Spanner in the works!\n\nReally sorry, but something went wrong! Try refreshing the page and try again.'); },
			success: function(thumb) {
					$('#album-thumb-'+album_id).html(thumb);
				}
		});
		$('#photooptions').show();
		$('#doingstuff').hide();
	}
	else
	{
		alert('Select a photo first');
	}
}
function deletethumb()
{
	var photo_id = $('input:radio:checked').attr('value');
	if(photo_id)
	{
		$('#image-'+photo_id+' .image').fadeOut('fast');
		$.ajax({
			type: "POST",
			url: "/gallery/deletethumb",
			data: {	photo_id: photo_id },
			error: function() { alert('Oh oh! Spanner in the works!\r\rReally sorry, but something went wrong! Try refreshing the page and try again.'); $('#image-'+photo_id+' .image').show(); },
			success: function() {
					$('#image-'+photo_id).fadeOut('slow', function(){ $('#image-'+photo_id).remove(); });
				}
		});
	}
	else
	{
		alert('Select a photo first');
	}
}
