pln.events.addListener(document,'__documentReady', null, initLightbox);
function initLightbox (){
	// For groups
	if (jQuery(".lightbox").length>0) jQuery('.lightbox').each(function (index, element){
		jQuery(element).find('li').colorbox({rel:'group'+index, maxHeight:'100%', maxWidth:'100%', href:getGalleryHref});
	});
	
	// For unique elements
	if (jQuery('.singlelightbox').length>0) jQuery('.singlelightbox').colorbox({maxHeight:'100%', maxWidth:'100%'});
}

function getGalleryHref (){
   // If the link is an <A>, get the href
   if (this.tagName=='A') return this.getAttribute('href');
   // If it's a parent of the <A>, get the first link that exists
   var firstlink = this.getElementsByTagName('a')[0];
   if (firstlink) return firstlink.getAttribute('href');
}
