Shadowbox.init({
    language:			"en",
    overlayOpacity:		"1",
    viewportPadding:	"15",
    continuous:			true,
    onFinish:			function(){ jQuery('#sb-body-inner img').one('click',Shadowbox.close); },
	onOpen:			function(){ ajaxToGallery(); }
});

function ajaxToGallery(id, action, permalink, path, logo){	
	jQuery.getJSON(THICKBOX2PDF_URL + 'addToGallery.php', { id: id, action: action, permalink: permalink, path: path, logo: logo }, function(json){
		jQuery(".lbCounter").text('(' + json.count + ')');
		if(json.result == 'removed'){
			if(json.id == 'all' || json.count == 0){
				jQuery("#content").html('<p>you have no images in your lightbox!</p>');
			} else {
				jQuery("#post-" + json.id).remove(); // remove the single post
			}
			jQuery(".tipsy").hide(); // hide the tipsy DIV
		}
	});
}

function addToGallery(id, permalink, path, logo){
	ajaxToGallery(id, 'add', permalink, path, logo);
}

function removeFromGallery(id){
	ajaxToGallery(id, 'remove');
}

function addFromShadowbox(elm){
	var image_abs_path = jQuery('#sb-content').attr('src');
	var lightbox_element = lightbox_json[image_abs_path];
	addToGallery(lightbox_element[0], lightbox_element[1], lightbox_element[2], lightbox_element[3]);
}