var title = null;

function nlbAjax() {
	jQuery.getJSON('json/nlbContent.json', function(data) {
		var content = data;
		jQuery.each(content, function(i, c) {
			if (title == c.title) {
				$('#nlHeading').attr({
					'src': c.src,
					'alt': c.title
				});
				$('#nlbsbContent').html(c.html);
			}
		});
	});
}

function niceLightbox(path) {
	$(path).click(function() {
		var pageSize = getPageSize();
		var getScroll = getScrollXY();
		title = $(this).attr('title');
		if (/*notSafari && */notIphone && notIpad) {	// Desktop/jQuery version
			$("#screen").css({
				'height': pageSize[1] + 'px',
				'opacity': '0.8'
			}).fadeIn(500);
		} else {	// iPhone/iPad CSS3 version
			$("#screen").css({
				'height': pageSize[1] + 'px'
			}).show().attr('class', 'scrOpac80');
		}
		$("#nLWrapper").css({
			'top': getScroll[1] + 'px'
		}).show();
		if (/*notSafari && */notIphone && notIpad) {	// Desktop/jQuery version
			$('#niceLightbox').css({
				'width': '1px',
				'height': '1px',
				'margin': '0',
				'opacity': '0.0'
			}).animate({
				'width': '620px',
				'height': '450px',
				'margin-top': '-225px',
				'margin-left': '-310px',
				'opacity': '1.0'
			}, 500, function() {
				$('#nlHeading').fadeIn(500);
				$('#nlbScrollbox').fadeIn(500);
				$('#nlbClose').fadeIn(500);
			});
		} else {	// iPhone/iPad CSS3 version
			$('#niceLightbox').show().attr('class', 'nlbEnd');
			setTimeout('$("#nlHeading").show().attr("class", "scrOpac100"); $("#nlbScrollbox").show().attr("class", "scrOpac100"); $("#nlbClose").show().attr("class", "scrOpac100");', 500);
		}
		nlbAjax();
		return false;
	});
}

function closeNiceLightbox() {
	if (/*notSafari && */notIphone && notIpad) {	// Desktop/jQuery version
		$('#nlHeading').fadeOut(500);
		$('#nlbScrollbox').fadeOut(500);
		$('#nlbClose').fadeOut(500, function() {
			$('#screen').fadeOut(500, function() {
				$('#screen').hide();
			});
			$("#nLWrapper").fadeOut(500, function() {
				$('#nLWrapper').hide();
			});
			$('#niceLightbox').animate({
				'width': '1px',
				'height': '1px',
				'margin-top': '0',
				'margin-left': '0',
				'opacity': '0.0'
			}, 500, function() {
				$('#niceLightbox').hide();
			});
		});
	} else {	// iPhone/iPad CSS3 version
		$('#nlHeading').attr('class', 'scrOpac0');
		$('#nlbScrollbox').attr('class', 'scrOpac0');
		$('#nlbClose').attr('class', 'scrOpac0');
		setTimeout('$("#nlHeading").css("display", "none"); $("#nlbScrollbox").css("display", "none"); $("#nlbClose").css("display", "none"); $("#screen").attr("class", "scrOpac0"); $("#niceLightbox").attr("class", "nlbStart");', 500);
		setTimeout('$("#screen").css("display", "none"); $("#nLWrapper").css("display", "none"); $("#niceLightbox").css("display", "none");', 1000);
	}
}
