﻿$(window).load(function () {
	$(function(e){
		var boxen = [];
		//find all links w/ rel="lightbox[gallery_name]" or just rel="lightbox" it works both ways
		$('a[rel*=lightbox]').each(function() {
			//push only unique lightbox[gallery_name] into boxen array
			if ($.inArray($(this).attr('rel'),boxen)) {
				boxen.push($(this).attr('rel'));
			}
		});
		
		var baseDir = $('input#qsUtilsBaseDir').val();
		
		//for each unique lightbox group, apply the lightBox
		$(boxen).each(function(i,val) { 
			$('a[rel='+val+']').lightBox({
				imageLoading: baseDir + '/img/lightbox/lightbox-ico-loading.gif',
				imageBtnClose: baseDir + '/img/lightbox/custom-btn-close.png',
				imageBtnPrev: baseDir + '/img/lightbox/custom-btn-left.png',
				imageBtnNext: baseDir + '/img/lightbox/custom-btn-right.png',
				imageBlank: baseDir + '/img/lightbox/lightbox-blank.gif'
			}); 
		});
	});
	
	$('div.galleryLink a').click(function(){
	 //$.fn.lightBox()._set_image_to_view();
		var parentid = $(this).parents('div.galleryBox').attr('id');
		$('#' + parentid + " .lightboxlink").trigger('click');
		
		$('div#lightbox-nav').append('<div id="lightbox-secNav-img">' + $('div#lightbox-secNav').html() + '</div>');
		return false;
	});
});
