function galleryPopInit(containerId) {

	// find the gallerylinks
	if (containerId) {
		var mpGalleryboxes = $$('#' + containerId + ' .gallerypopthis');
	} else {
		var mpGalleryboxes = $$('.gallerypopthis');
	}
	var mpGalleryLength = mpGalleryboxes.length;
	
	//console.log('amount of gallery pop-ups found: ' +mpGalleryLength);
	
	for (i=0;i<mpGalleryLength;i++) {
	
		// onclick
		mpGalleryboxes[i].addEvent('click',function(event) {
			// stop the link off
			event.stop();
			// pop up gallery
			galleryPopLoad (this);
			
		})
	
	}
	

}

function galleryPopLoad (linkObj,galleryUrl) {

	fireEvent('orientationchange');

	// kill the gallery content
	$('galleryPopup').set('html','');
	
	// get the url
	if (!galleryUrl) {
		var galleryUrl = linkObj.getProperty('href') + '?ajax=1';
	}
	galleryUrl = galleryUrl + '?ajax=1';
	
	// move gallery in
	new Fx.Morph($('galleryPopup'),{'unit':'%'}).start({ 'height':100 }).chain(function(){
		
		// load in page
		new Request.HTML({  
			method: 'get',
			url: galleryUrl,
			onSuccess: function() {
				mindPopInit();
				
				// close gallery pop-up
				$$('.mp_pop_close').addEvent('click', function() {
					
					galleryPopClose();
					return false;
				});
				
			},
			onFailure: function() {
			},
			evalScripts: true,
			update: $('galleryPopup')
		}).send()
		
	});
	

}

function galleryPopClose () {
	new Fx.Morph($('galleryPopup'),{'unit':'%'}).start({ 'height':0 }).chain(function(){
		$('galleryPopup').set('html','');
	});
}
