

function slideshowLoadAssets(c) {
	/*
	Asset.css('/assets/css/slideshow.css');

	Asset.javascript('/assets/js/slideshow/slideshow.js', {
		onLoad: function() {
			Asset.javascript('/assets/js/slideshow/slideshow.kenburns.js', {
				onLoad: function() {
					c.callChain();
				}
			});
		}
	});
	*/
	c.callChain();
}

function slideshowSetpos() {
	var container = $('divGallerySlideshow');
	if(!container || container.getStyle('display') == 'none') return;

	container.setStyles({
		left: ( ($(document.body).getWidth() / 2) - (600/2) ) + $(document.body).getScroll().x,
		top: (( ($(document.body).getHeight() / 2) - (500/2) ) * .9) + $(document.body).getScroll().y
	});
}
window.addEvents({
	resize: slideshowSetpos,
	scroll: slideshowSetpos
});

function slideshowLoad(galleryalbum_id) {
	if(window._slideshowLoaded) return;
	window._slideshowLoaded = true;

	var container = $('divGallerySlideshow');
	if(!container) {
		container = new Element('div', {
			id: 'divGallerySlideshow',
			'class': 'shadow'
		}).inject($(document.body));
	};

	container.empty();
	window.gallerySlideshow = null;
	window._ssoverlay = null;

	var c = new Chain();
	c.chain(function() {
		slideshowLoadAssets(c);
	}).chain(function() {
		new Request({
			method: 'post',
			url: '/site/gallery/x-load-slideshow?galleryalbum_id='+galleryalbum_id,
			onComplete: function(r) {
				try { r = JSON.decode(r); } catch(e) { };
				c.callChain(r);
			}
		}).send();
	}).chain(function(data) {
	
		container.setStyles({
			display: 'block',
			opacity: 0
		});	
		slideshowSetpos();

		window.gallerySlideshow = new Slideshow.KenBurns('divGallerySlideshow', data, {
			captions: true,
			controller: true,
			thumbnails: false,
			hu: '/assets/upload/gallery/',
			delay: 8000,
			duration: 1000,
			width: 700,
			height: 500,
			//pan: [100, 100],
			//zoom: 30,
			pan: [0,0],
			zoom: [0,0],
			linked: false
		});

		window._ssoverlay = new Overlay({ duration: 500, close_on_click: false });
		container.setStyle('z-index', 122);
		$$('.divOverlay').setStyle('z-index', 121);
		window._ssoverlay.show();

		new Fx.Tween(container, {
			duration: 500,
			onComplete: function() {
				c.callChain();
			}
		}).start('opacity', 1);

	}).chain(function() {

		var z = new Element('div', { styles: { position: 'relative' }}).inject(container);

		new Element('img', {
			src: '/assets/images/slideshow/closebox.png',
			styles: {
				zIndex: 20000,
				cursor: 'pointer',
				position: 'absolute',
				left: container.getWidth() - 30,
				top: ( container.getHeight() * -1 )
			},
			events: {
				click: function() {
					window._ssoverlay.hide();
					new Fx.Tween(container, {
						duration: 300,
						onComplete: function() {
							window.gallerySlideshow.destroy();
							container.empty();
							window._ssoverlay = null;
							window._slideshowLoaded = false;
						}
					}).start('opacity', 0);
				}
			}
		}).inject(z);

	}).callChain();


}



