var Gallery = {

	images : [],

	current : 0,

	init : function(images, base){
		images = images.split(',');
		for(i=0; i<images.length; ++i){
			this.images[i] = new Image();
			this.images[i].src = base + images[i];
		}
	},

	next : function(){
		if(this.current + 2 > this.images.length){
			this.current = 0;
		} else {
			this.current = this.current + 1;
		}
		$('cimage').src = this.images[this.current].src;
		$('pTitle').update(GALLERY_TITLE + ' ' + (this.current + 1));
	},

	prev : function(){
		if(this.current - 1 < 0){
			this.current = this.images.length - 1;
		} else {
			this.current = this.current - 1;
		}
		$('cimage').src = this.images[this.current].src;
		$('pTitle').update(GALLERY_TITLE + ' ' + (this.current + 1));
	},

	show : function (item){
		if(this.images.length>1){
			MY_IMAGE = '<img class="pointer" onclick="Gallery.next()" id="cimage" alt="'+GALLERY_BT_NEXT+'" title="'+GALLERY_BT_NEXT+'"/>';
			content = '<table cellpadding="0" cellspacing="0" id="gallery" class="gallery"><tr><td align="center" valign="middle">'+MY_IMAGE+'</td></tr></table>';
			content += '<table class="buttons" cellpadding="4" cellspacing="0"><tr><td>'+
				'<a href="javascript://" onclick="Gallery.prev(); return false;" class="ok">'+GALLERY_BT_PREV+'</a>'+
				'</td><td><a href="javascript://" onclick="Gallery.next(); return false;" class="cancel">'+GALLERY_BT_NEXT+'</a>'+
			'</td></tr></table>';
		} else {
			MY_IMAGE = '<img id="cimage" alt="" title=""/>';
			content = '<table cellpadding="0" cellspacing="0" id="gallery" class="gallery"><tr><td align="center" valign="middle">'+MY_IMAGE+'</td></tr></table>';
			content += '<table class="buttons" cellpadding="4" cellspacing="0"><tr><td>'+
				'<a href="javascript://" onclick="hideOverlay(); return false;" class="ok">'+GALLERY_BT_CLOSE+'</a>'+
			'</td></tr></table>';
		}
		$('messageContainer').update(getPopinContainer('', content));
		showOverlay();
		this.current = item || 0;
		$('cimage').src = this.images[this.current].src;
		$('pTitle').update(GALLERY_TITLE + ' ' + (this.current + 1));
	},
	
	play : function (){
		content = '<table cellpadding="0" cellspacing="0" id="gallery" class="gallery"><tr><td align="center" valign="middle" id="videoPlayer">&nbsp;</td></tr></table>';
		content += '<table class="buttons" cellpadding="4" cellspacing="0"><tr><td>'+
			'<a href="javascript://" onclick="hideOverlay(); return false;" class="ok">'+GALLERY_BT_CLOSE+'</a>'+
		'</td></tr></table>';	
		$('messageContainer').update(getPopinContainer('', content));
		showOverlay();
		$('pTitle').update(VIDEO_TITLE);
		xajax_playVideo();
	}

}
