jQuery(document).ready(function(){
	jQuery('#view_slideshow').bind('click', start_gallery_slideshow);
});
var start_gallery_slideshow = function() {
	//Fix - get search data
	var keyWords = jQuery('input[name=simple_keywords][type=hidden]');
	var search = jQuery(keyWords[0]).val();
	var sData = {
		'collection_id' : ss_collection,
		'album_id' : ss_albumid,
		'act' : 'alb_img_list',
		'simple_keywords' : search
	};

	// hide open dropdown when slideshow is clicked
	jQuery(this).parents('.dropdown').removeClass('open');

	jQuery.ajax({
		type : 'POST',
		url : '/intranet/gallery/json_album.php',
		data : sData,
		dataType : 'json',
		success : function(image_list) {
			if(!image_list.is_error) {
				//Force removal of previous entry if one
				jQuery('#' + ss_liveid).remove();
				//Create empty div
				var h_div = jQuery("<div />", {
					'id' : ss_liveid,
					'style' : 'display: none'
				});
				var f_link = null;
				for(var i = 0; i < image_list.count; i++) {
					var this_image = image_list.images[i];
					var tmp_img = jQuery('<a />', {
						'class' : ss_liveid,
						'href' : '/intranet/gallery/thumbnail.php?prefix=medium&id=' + this_image.id,
						'title' : this_image.title,
						'data-lightbox' : 'gallery',
						'iid' : this_image.id
					}).appendTo(h_div);
					if(!f_link) {
						var f_link = tmp_img;
					}
				}
				h_div.prependTo(jQuery('body'));

				f_link.trigger('click');
			}
		}
	});
	return false;
};