(function() {
var revealing;
var revealed;
$(function() {
// Render any code samples on the page.
prettyPrint();
var margin = parseInt($('#content').css('margin-top'));
var height = $(document.body).height();
$(window).on('scroll', function(event) {
var offscreen = window.scrollY;
var onscreen = window.innerHeight;
// console.log(offscreen + " + " + onscreen + " ( = " + (onscreen + offscreen) + ") >=? " + height + " + " + margin + " - " + ($('reveal').getHeight() / 2) + " ( = " + (height + margin - $('reveal').getHeight() / 2) + ")");
if (!revealed) {
if (offscreen + onscreen >= height + margin - $('#reveal').height() / 2) {
if (!revealing) {
// console.log("Going to reveal!");
$('<img>').attr({
'src': '../../images/load.gif',
'alt': 'Loading…'
}).appendTo('#reveal');
revealing = setTimeout(function() {
// reveal = null;
$('#solution').fadeIn(500, function() {
revealed = true;
if ($('#reveal').get(0)) {
$('#reveal').get(0).remove();
}
});
}, 3000);
} else {
// console.log("Still going to reveal...");
}
} else if (revealing) {
// console.log("Stopping the reveal.");
clearTimeout(revealing);
revealing = null;
if ($('#reveal').get(0)) {
$('#reveal').get(0).remove();
}
}
}
});
});
})();