/********************************************************/
/* myLightbox by Mark Hoschek - http://mark-hoschek.de/ */
/********************************************************/
myLightboxSettings = new Object();
myLightboxSettings['vertical_align'] = 30; // 'center' or number of pixels from top
myLightboxSettings['next_link'] = '[»]';
myLightboxSettings['next_link_title'] = 'next';
myLightboxSettings['previous_link'] = '[«]';
myLightboxSettings['previous_link_title'] = 'previous';
myLightboxSettings['close_link'] = '[x]';
myLightboxSettings['close_link_title'] = 'close';
myLightboxSettings['html_box'] = '
';
myLightboxSettings['html_background'] = '';
// 0 means disabled; 1 means enabled;
var popupStatus = 0;
// loading popup with jQuery magic!
function loadPopup()
{
//loads popup only if it is disabled
if(popupStatus==0)
{
$("body").append(myLightboxSettings['html_background']);
$("body").append(myLightboxSettings['html_box']);
$("#mylightbox-background").css({
"opacity": "0.7"
});
$("#mylightbox-background").fadeIn("fast");
$("#mylightbox").fadeIn("fast");
// center popup on window resize:
$(window).bind('resize', function() {
centerPopup($("#mylightbox").width(),$("#mylightbox").height());
});
// close on click on close button:
$("#mylightbox-close").click(function(){
disablePopup();
});
// close on click on background:
$("#mylightbox-background").click(function(){
disablePopup();
});
// close on ESC key
$(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
disablePopup();
}
});
popupStatus = 1;
}
}
function disablePopup()
{
//if(popupStatus==1){
$("#mylightbox").fadeOut("fast", remove);
$("#mylightbox-background").fadeOut("fast", remove);
popupStatus = 0;
delete myLightboxCurrentWidth;
//}
}
// callback function to remove box and background:
function remove()
{
$(this).remove();
}
function centerPopup(width, height)
{
if(myLightboxSettings['vertical_align']=='center')
{
var top = $(window).scrollTop()+$(window).height()/2-height/2;
}
else
{
var top = $(window).scrollTop()+myLightboxSettings['vertical_align'];
}
var left = $(window).width()/2-width/2;
if(top<0) top=0;
if(left<0) left=0;
$("#mylightbox").css({
//"width":imgWidth+'px',
//"width":imageWidth+'px',
//"height":+'px',
"position": "absolute",
"top": top+'px',
//"top": top+"px",
"left": left+'px'
});
//only need force for IE6
$("#mylightbox-background").css({
"height": $(window).height()
});
}
function doit(e,t)
{
e.preventDefault();
// get mylightbox links, image sources, titles (alt) and descriptions (title):
var myLightboxLinks = new Array();
var srcs = new Array();
var titles = new Array();
var descriptions = new Array();
var authors = new Array();
//$(".mylightbox").each(function(i) // get all links with class="mylightbox"
$("a[data-lightbox]").each(function(i) // get all links with rel="mylightbox"
{
if($(this)[0] === $(t)[0]) mylightboxCurrent = i;
myLightboxLinks.push($(this));
srcs.push($(this).attr('href'));
titles.push($(this).find('img').attr('title'));
descriptions.push($(this).find('img').attr('data-description'));
authors.push($(this).find('img').attr('data-author'));
});
var numberOfImages = myLightboxLinks.length;
var src = srcs[mylightboxCurrent];
var title = titles[mylightboxCurrent];
var description = descriptions[mylightboxCurrent];
var author = authors[mylightboxCurrent];
// determine previous and next image:
if(numberOfImages>1)
{
if(typeof(myLightboxLinks[mylightboxCurrent+1])!='undefined')
{
var next = myLightboxLinks[mylightboxCurrent+1];
}
else
{
var next = myLightboxLinks[0];
}
if(typeof(myLightboxLinks[mylightboxCurrent-1])!='undefined')
{
var prev = myLightboxLinks[mylightboxCurrent-1];
}
else
{
var prev = myLightboxLinks[numberOfImages-1];
}
}
loadPopup();
if(typeof(myLightboxCurrentWidth)!='undefined') $("#mylightbox").css({"width":myLightboxCurrentWidth+'px'});
$("#mylightbox #mylightbox-title").html('');
$("#mylightbox-photo").html('');
$("#mylightbox-description").html('');
if(typeof(myLightboxCurrentWidth)=='undefined') centerPopup($("#mylightbox").outerWidth(), $("#mylightbox").outerHeight());
var objImagePreloader = new Image();
objImagePreloader.onload = function()
{
$("#mylightbox #mylightbox-title").html(title);
$("#mylightbox-photo").hide();
/*if(typeof(next)!='undefined')
{
$("#mylightbox-photo").html('
');
$("#mylightbox-next-img").click(function(e){ doit(e,next); });
}
else
{
$("#mylightbox-photo").html('
');
}
*/
$("#mylightbox-photo").html('
');
// previous and next buttons:
if(typeof(prev)!='undefined' && typeof(next)!='undefined')
{
$("#mylightbox-photo").append(''+myLightboxSettings['previous_link']+'');
$("#mylightbox-photo").append(''+myLightboxSettings['next_link']+'');
$("#mylightbox-prev").click(function(e) { doit(e,prev); });
$("#mylightbox-next").click(function(e) { doit(e,next); });
if(typeof Hammer == 'function')
{
var hammertime = $("#mylightbox-photo").hammer();
hammertime.on("swipeleft", function(e) { doit(e,next); });
hammertime.on("swiperight", function(e) { doit(e,prev); });
}
}
else
{
//$("#mylightbox-prev").remove();
//$("#mylightbox-next").remove();
}
$("#mylightbox-description").html(description);
$("#mylightbox-author").html(author);
$("#mylightbox-photo").fadeIn("fast");
myLightboxCurrentWidth = objImagePreloader.width;
$("#mylightbox").css({"width":myLightboxCurrentWidth+'px'});
centerPopup($("#mylightbox").outerWidth(), $("#mylightbox").outerHeight());
};
objImagePreloader.src = src;
}
$(function()
{
$("a[data-lightbox]").click(function(e){
doit(e,this);
});
});