
	var GalleryClass = {
		url: URL_ROOT + 'cms/gallery/gallery_submit.php',	// script where data is sent/received via HTTP class		
			
		deleteItem: function (gallery_id, item_id, button) {
			var choice = window.confirm('Really delete this gallery item?');
			if (choice) {
				HTTP.connect({
					url: this.url,
					action: 'delete_item',
					data: 'gallery_id=' + gallery_id + '&item_id=' + item_id,
					waiting: button,
					update: 'gallery_' + gallery_id
				});		
			}
		},

		addFolder: function (gallery_id, button) {
			folder_id = 2;
			HTTP.connect({
				url: this.url,
				action: 'add_folder',
				data: 'gallery_id=' + gallery_id + '&folder_id=' + folder_id,
				waiting: button,
				update: 'gallery_' + gallery_id
			});		
		},

		addItem: function (event, gallery_id, button) {	// A wrapper function to call the media chooser
			this.gallery_id = gallery_id;
			this.button = button;
			FileClass.fileChooser(event, button, GalleryClass.saveItem);
		},
	
		saveItem: function (media_id) {	// callback after selecting in chooser
			HTTP.connect({
				url: GalleryClass.url,
				action: 'add_item',
				data: 'gallery_id=' + GalleryClass.gallery_id + '&media_id=' + media_id,
				waiting: GalleryClass.button,
				update: 'gallery_' + GalleryClass.gallery_id
			});		
		},

		editCaption: function (event, gallery_id, item_id, button) {	// A wrapper function to call the media chooser
			this.gallery_id = gallery_id;
			this.item_id = item_id;
			this.button = button;

			if (!event) var e = window.event;// Capture this mouse movment for IE
			var x = Box.pointerX(event);
			var y = Box.pointerY(event);
			this.callback = GalleryClass.saveCaption;

			HTTP.connect({
				url: GalleryClass.url,
				action: 'fetch_caption',
				data: 'gallery_id=' + GalleryClass.gallery_id + '&item_id=' + item_id,
				waiting: GalleryClass.button,
				after: function (caption) {
					var inside = '<div align="center">'
					+ '<textarea id="captionEdit" style="border:1px solid gray;width:95%">' + caption + '</textarea>'
					+ '<input type="button" class="edit_button" value="Save" onclick="GalleryClass.saveCaption(document.getElementById(\'captionEdit\').value);"></div>';
					Box.open({ x:x, y:y, e:e, title:'Edit Caption', width:300, height:200, content: inside });
				}
			});		

//			Box.open({ x:x, y:y, e:e, title:'Edit Caption', width:300, height:200, content: inside });
		},




		saveCaption: function (caption) {	// callback after selecting in chooser
			caption = escape(caption);
			Box.close();
			HTTP.connect({
				url: GalleryClass.url,
				action: 'save_caption',
				data: 'gallery_id=' + GalleryClass.gallery_id + '&item_id=' + GalleryClass.item_id + '&caption=' + caption,
				waiting: GalleryClass.button,
				update: 'gallery_' + GalleryClass.gallery_id
			});
		},

		editClick: function (event, gallery_id, item_id, button) {	// A wrapper function to call the media chooser
			this.gallery_id = gallery_id;
			this.item_id = item_id;
			this.button = button;
			FileClass.fileChooser(event, button, GalleryClass.saveClick);
		},

		saveClick: function (media_id) {	// callback after selecting in chooser
			Box.close();
			HTTP.connect({
				url: GalleryClass.url,
				action: 'save_click',
				data: 'gallery_id=' + GalleryClass.gallery_id + '&item_id=' + GalleryClass.item_id + '&media_id=' + media_id,
				waiting: GalleryClass.button,
				update: 'gallery_' + GalleryClass.gallery_id
			});
		},

		changeType: function (gallery_id, type, button) {	// callback after selecting in chooser
			if (!type) return;
			HTTP.connect({
				url: this.url,
				action: 'change_type',
				data: 'gallery_id=' + gallery_id + '&type=' + type,
				waiting: button,
				update: 'gallery_' + gallery_id
			});
		},

		mediaClick: function (media_id) {
			video_launch(media_id);
		},

		popup: function (gallery_id, file) {
			popup('/modules/gallery/gallery_view.php?gallery_id=' + gallery_id + '&file=' + file, 'gallery', 730, 900);
		}
	}
