function loadOverlay(overlay, src) { if (overlay == "#loader") { $('#loader .description img').hide(); var container = $('#loader img'); container.removeClass('on-deck'); var exists = false; for (var i = 0, n = container.length; i < n; i++) { if ($(container[i]).attr('src') == src) { exists = true; var j = i; } } //If the image is not loaded, load it if (!exists) { var img = new Image(); var width = ''; var height = ''; $(img).load(function() { $(this).hide().addClass('on-deck'); $('#loader .description').append(this); $.ajax({ success: function(html) { $('#loader img.on-deck').fadeIn(1000); if (img.width > 700) { img.height = (img.height * 700) / img.width; img.width = 700; } } }); }).attr('src', src).attr('height', img.height); } else { // If the image is already loaded, skip creating a new Image $(container[j]).addClass('on-deck'); $('#loader img.on-deck').fadeIn(1000); } } if ($(overlay).hasClass('video')) { var target = $(overlay).find(".description a").attr('href').match(/v=(.+)/)[1]; if (target.match(/^(.+?)&/) != null) { target = target.match(/^(.+?)&/)[1]; } //$('
').prependTo($(overlay).find('.description')); $('
').prependTo($(overlay).find('.description')); $(overlay).find('.description a').hide(); centerOverlay(overlay); }; if ($(overlay + ':visible')) { $(overlay).fadeIn(1000).addClass('overlay-active'); $("#overlayBg").fadeIn(950); } } function disableOverlay() { var overlay = $('div.overlay:visible'); overlay.fadeOut(550).removeClass('overlay-active'); if ($(overlay).hasClass('video')) { $('#playing-video').remove(); $(overlay).find('.description a').show(); } $("#overlayBg").fadeOut(550); } function centerOverlay(overlay) { var overlay = $(overlay); var windowWidth = $(window).width(); var windowHeight = $(window).height(); var overlayHeight = overlay.height(); var overlayWidth = overlay.width(); overlay.css({ "position": "absolute", "top": $(window).scrollTop() + windowHeight/2 - overlayHeight/2 - 4, "left": windowWidth/2-overlayWidth/2 - 4 }); $("#overlayBg").css({ height: $(document).height() }); } $(function() { $(".trigger").click(function(event) { event.preventDefault(); centerOverlay(this.hash); loadOverlay(this.hash); }); $(".trigger-label").click(function(event) { event.preventDefault(); centerOverlay('#loader'); loadOverlay('#loader', $(this).attr('href')); }); $(".close").click(function(event) { event.preventDefault(); disableOverlay(this); }); $("#overlayBg").click(function() { disableOverlay(this); }); $(window).resize(function() { centerOverlay('.overlay-active'); }); });