function picturezoomlightbox_gotoindex(indexname) { $(".picturezoomlightbox-enabled").each(function() { var buf = $(this).attr("picturezoomlightbox-index"); if ((buf !== undefined) && (buf == indexname)) { picturezoomlightbox_open($(this), 0); return false; } }); } function picturezoomlightbox_open(element, openflag) { var imageurl = ""; if ($(element).is("div")) { bg_url = $(element).css("backgroundImage"); bg_url = /^url\((['"]?)(.*)\1\)$/.exec(bg_url); bg_url = bg_url ? bg_url[2] : ""; // If matched, retrieve url, otherwise "" imageurl = bg_url; } else if ($(element).is("img")) { if (typeof($(element).attr("src")) != "undefined") { imageurl = $(element).attr("src"); } } if (imageurl != "") { if (openflag) { $("#medialightbox-overlay").css("display", "block"); $("#medialightbox-overlay").width($(document).width()); $("#medialightbox-overlay").height($(document).height()); $("#medialightbox-loading").css("display", "block"); $("#medialightbox-loading").offset({top:($(window).scrollTop() + 20)}); } var image = new Image(); image.onload = function() { var panelwidth = $(window).width() - 40; var panelheight = $(window).height() - 40; var imagewidth = panelwidth; var imageheight = Math.round(imagewidth * (image.height/image.width)); if (imageheight > panelheight) { var imageheight = panelheight; var imagewidth = Math.round(imageheight * (image.width/image.height)); } if (panelwidth > imagewidth) { panelwidth = imagewidth; } if (panelheight > imageheight) { panelheight = imageheight; } panelwidth = panelwidth + 2; panelheight = panelheight + 2; var buf = "
"; if (typeof($(element).attr("title")) != "undefined") { buf = buf + "
" + $(element).attr("title") + "
"; } $("#medialightbox-panel").css({opacity:0}); $("#medialightbox-panel").css("display", "block"); $("#medialightbox-panel").css("border", "1px solid #ffffff"); $("#medialightbox-panel").css({width:panelwidth}); $("#medialightbox-panel").css({height:panelheight}); $("#medialightbox-panel").html(buf); $("#medialightbox-panel").css({top:(($(window).height() - $("#medialightbox-panel").height())/2)}); $("#medialightbox-panel").css({left:(($(window).width() - $("#medialightbox-panel").width())/2)}); if (typeof($(element).attr("title")) != "undefined") { var height = $("#medialightbox-caption > div").height(); $("#medialightbox-caption").css({top:(height * -1)}); } $("#medialightbox-loading").css("display", "none"); $("#medialightbox-panel").animate({opacity:1}, 500); $("#medialightbox-closeicon").css("display", "block"); var indexname = $(element).attr("picturezoomlightbox-index"); var previndexname = ""; var nextindexname = ""; if (indexname !== undefined) { var fields = indexname.split(/-/); var seqname = fields[0]; var seqindex = parseInt(fields[1]); $(".picturezoomlightbox-enabled").each(function() { indexname = $(this).attr("picturezoomlightbox-index"); if (indexname !== undefined) { var fields = indexname.split(/-/); if ((fields[0] == seqname) && (fields[1] == (seqindex-1).toString())) { previndexname = seqname + "-" + (seqindex-1); } else if ((fields[0] == seqname) && (fields[1] == (seqindex+1).toString())) { nextindexname = seqname + "-" + (seqindex+1); } } }); } if (previndexname != "") { $("#medialightbox-leftarrow").css("display", "block"); $("#medialightbox-leftarrow").css({top:(($(window).height() - $("#medialightbox-leftarrow").height())/2)}); $("#medialightbox-leftarrow").css({left:0}); $("#medialightbox-leftarrow").off("click").on("click", function() { picturezoomlightbox_gotoindex(previndexname); }); } else { $("#medialightbox-leftarrow").css("display", "none"); } if (nextindexname != "") { $("#medialightbox-rightarrow").css("display", "block"); $("#medialightbox-rightarrow").css({top:(($(window).height() - $("#medialightbox-leftarrow").height())/2)}); $("#medialightbox-rightarrow").css({left:($(window).width() - $("#medialightbox-leftarrow").width())}); $("#medialightbox-rightarrow").off("click").on("click", function() { picturezoomlightbox_gotoindex(nextindexname); }); } else { $("#medialightbox-rightarrow").css("display", "none"); } } if (imageurl.substring(0, 4) != "http") { image.src = "http://www.hairhints.com" + imageurl; } else { image.src = imageurl; } } }