/* Copyright (C) 2002-2011 by Home of the Brave
   Web http://home.of.the.brave.de
   E-Mail info@brave.de */
/* $Revision: 1.3 $ $Date: 2011/03/22 15:32:47 $ */


/*
 * Create image galleries from Flickr or page content.
 * dependencies: BodyEvents, jQuery, Galleria, Galleria.Flickr
 * owner: Simon.Leidig@brave.de
 *
 */

if (!window.GalleryBlocks) {
	window.GalleryBlocks = {
		create: function (opts) {
			BodyEvents.createDynamicBlock(GalleryBlocks.init,opts);
		},
		init: function (node,opts) {
			var s = $(node);
			var g = { autoplay: opts.interval > 0 ? opts.interval*1000 : false };
			s.css('height',( opts.height > 0 ? opts.height+70 : 370 )+'px');
			if (opts.type.substr(0,7) == 'flickr_') {
				var f = new Galleria.Flickr(opts.key).setOptions({
					max:		opts.max,
					size:		opts.size,
					sort:		opts.sort,
					description:opts.description
				});
				f['get'+opts.type.substr(7,1).toUpperCase()+opts.type.substr(8)].call(
					f, opts.search, function(d){
						g.data_source = d;
						GalleryBlocks.finish(s.galleria(g));
					}
				);
			}
			else BodyEvents.addInterval(
				GalleryBlocks.finish, 100, 50,
				s.append(s.parent().find('img.regular')).galleria(g)
			);
		},
		finish: function (s) {
			var t = s.find('.galleria-stage');
			if (t.size() == 0) return true;
			t.css('height',s.height()-70+'px');
			s.css('z-index','-10');
			return false;
		}
	};
	Galleria.loadTheme('/Scripts/Jquery/galleria/themes/anton/galleria.anton.js');
}

