
if (typeof _pcsg == 'undefined') {
	var _pcsg = {};
};

if (typeof _pcsg.Plugins == 'undefined') {
	_pcsg.Plugins = {};
};

_pcsg.Plugins.Gallery = {};

_pcsg.Plugins.Gallery.Sequence =
{
	load : function()
	{
		var o = document.getElementById('PCSG_gallery_sequence_sheets');

		if (!o) {
			return;
		};

		// Sheets auf Ajax umbauen
		var links = o.getElementsByTagName('a');

		for (var i = 0, len = links.length; i < len; i++)
		{
			links[i].onclick = function() {
				_pcsg.Plugins.Gallery.Sequence.get( this.getAttribute('alt') );
			};

			links[i].href = 'javascript: return false;'
		};
	},

	get : function(sheet)
	{
		var o = document.getElementById('PCSG_gallery_sequence_image');

		if (!o) {
			return;
		};

		o.style.height = o.offsetHeight +'px';

		var oLoader = document.createElement('div');
		oLoader.style.width  = o.offsetWidth +'px';
		oLoader.style.height = o.offsetHeight +'px';
		oLoader.className    = 'PCSG_gallery_loader';

		o.appendChild( oLoader );


		_Ajax.asyncPost('ajax_plugin_gallery_get', function(result, Ajax)
		{
			var oLoader = Ajax.getAttribute('oLoader');

			if (oLoader) {
				oLoader.parentNode.removeChild( oLoader );
			};

			var o = document.getElementById('PCSG_gallery_sequence');

			if (o)
			{
				o.innerHTML = result;
				_pcsg.Plugins.Gallery.Sequence.load();
			};

		}, {
			plugin  : 'gallery',
			project : _pcsg.Project.name,
			id      : _pcsg.Site.id,
			sheet   : sheet,
			oLoader : oLoader
		});
	}
};