var Gallery = new Class({

	initialize: function(){
		
	},
	
	show: function( eventID ){
		this.log('starting gallery');
		
		var req = new Request.HTML({url:'?show_gallery='+eventID, 
			onSuccess: function(var1, var2, var3, var4) {
				if(var1.responseHTML  != 'fail'){
					gallery.log('gallery found, show');
					gallery.overlay = new Overlay();
					overlay.show();
					gallery.container = new Element('div').setProperties({'id': 'panel-holder'}).injectInside(document.body);

					$('panel-holder').set('html',var3);
					/*
					var script = new Element('script').setProperties({'type': 'text/javascript', 'id': 'gallery-script'});
					$('panel-holder').adopt(script);
					//$('gallery-script').set('text',var4);
					*/
					var myEffect = new Fx.Morph('panel-holder', {duration: 'normal', transition: Fx.Transitions.Quad.easeIn});
					myEffect.start({
						'-moz-opacity': [0,1],
						'-khtml-opacity': [0,1],
						'opacity': [0,1]
					});
				}else{
					gallery.log('bad id');
				}
			},
			onFailure: function() {
				gallery.log('failed getting html');
			}
		});
		req.send();
		
	},
	
	showImage: function( file ){
		gallery.log('show image:'+ file);
		$('gallery-image').set('text', '');
		$('gallery-image').set('html', '<img src="'+file+'" />');
	},
	
	next: function(){
		if(current_image == (galleryImages.length-1)){
			current_image = 0;
			gallery.showImage(galleryImages[current_image]);
		}else{
			current_image++;
			gallery.showImage(galleryImages[current_image]);
		}
		
	},
	
	prev: function(){
		if(current_image == 0){
			current_image = galleryImages.length-1;
			gallery.showImage(galleryImages[current_image]);
		}else{
			current_image--;
			gallery.showImage(galleryImages[current_image]);
		}
	},
	
	exit: function(){
		this.overlay.destroy();
	},
	
	log: function( msg ){
		try{
			console.log( msg );
		}catch(e){
			// skip its prob just not running firebug
		}
	}
});

var gallery = new Gallery();