// JavaScript Document
jQuery(document).ready(initLightbox);

function initLightbox (){
	var selector = window['colorboxChildrenSelector']!==undefined ? colorboxChildrenSelector : 'li';
	// For groups
	if (jQuery(".lightbox").length>0) jQuery('.lightbox').each(function (index, element){
		jQuery(element).find(selector).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%', href:getGalleryHref});
	
	var videos = jQuery( '.videoBox' );
	if ( videos.length > 0 ) videos.each( function ( index , element ){
		var content		= jQuery( element ).find( '.lightboxContent' );
		var contentHtml = content.html();
		void content.remove();		
		jQuery( element ).colorbox({ maxHeight:'100%', maxWidth:'100%', html:contentHtml });
	} );
}
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');
}
