$(document).ready(function(){
	var _showGalleryLinks = $('a.show-gallery');
	
	_showGalleryLinks.each(function(i, link){
		var _rel = this.rel;
		$(link).attr('rev','#gallery'+i);

		$.ajax({
			url: _rel,
			dataType: (jQuery.browser.msie) ? 'text' : 'xml',
			success: function(xmlData){
				var data;
				if ( typeof xmlData == 'string') {
					data = new ActiveXObject( 'Microsoft.XMLDOM');
					data.async = false;
					data.loadXML( xmlData);
				} else {
					data = xmlData;
				}
				var _result = '<ul id="gallery'+i+'" class="hideGallery">';
				$('image',data).each(function(i, _item){
					_result += '<li><a href="'+$(_item).text()+'">'+$(_item).text()+'</a></li>';
				});
				_result += '</ul>';
				
				$('body').append(_result);
				
				$('#gallery'+i).customLightbox();
				
			}
		});
		
		$(link).click(function(){
			$(this.rev).find('a:first').trigger('click');
			return false;
		});
		
	});
});

