/* How to: Add a slideshow gallery to a page:
	1. include this javascript file.
	2. Add the element <trusd:gallery></trust:gallery> wherever you want the gallery to appear.
	3. The trusd:gallery element can have the following Attributes:
		- min: (int) Minimum number of slideshows to show
		- max: (int) Maximum number of slideshows to show
*/

$(document).ready(function() {
	$.each($(".trusd\\:gallery"), function(key, val) {
		var galleryContainer = $(val);
		var gallery = drawGallery(galleryContainer);
		
		$.getJSON("/newsroom/slideshows/?do=getGalleryJSON&min=" + galleryContainer.attr("min") + "&max=" + galleryContainer.attr("max"), function(msg) { $.each(msg, function(key, val) { if(val) { drawSlideshow(gallery, val); } }); });
		//$.ajax({ url: "/newsroom/slideshows/?do=getGalleryJSON&min=" + galleryContainer.attr("min") + "&max=" + galleryContainer.attr("max"), success: function(msg) { alert(msg); }, error: function(xr, status, err) { alert("error"); } });
	});
		
});

/* These functions can be overloaded to create custom html. */

// galleryEle is the <trusd:gallery> element.
function drawGallery(galleryEle) {
	var ele = galleryEle;
	
	var gallery = $("<div class='gallery'></div>");
	ele.before(gallery);
	ele.remove();
	return gallery;
}

function drawSlideshow(gallery, ss) {
	var ele = gallery;
	ele.append("<img src='" + ss["path"] + "thumbs/" + ss["images"][0] + "' />");
	$.each(ss["images"], function(key, val){
	});
}
