function lazyload() {
	
	if (lazyloadThrottleTimeout) {
		clearTimeout(lazyloadThrottleTimeout);
	}
	lazyloadThrottleTimeout = setTimeout(function() {
		var scrollTop = window.pageYOffset;
		lazyloadImages = document.querySelectorAll('img.lazy');
		for (var i = 0, len = lazyloadImages.length; i < len; i++) {
			var img = lazyloadImages[i];
			var clientTop = document.documentElement.scrollTop;
			var clientBottom = document.documentElement.scrollTop + document.documentElement.clientHeight;
			var imgTop = img.offsetTop;
			var imgBottom = img.offsetTop + img.clientHeight;
			if (((imgTop > clientTop) && (imgTop < clientBottom))
				|| ((imgBottom > clientTop) && (imgBottom < clientBottom))) {
				img.src = img.getAttribute('data-src');
				removeClass(img, "lazy");
			}
		}
		if (lazyloadImages.length == 0) {
			window.detachEvent('onscroll', lazyload);
			window.detachEvent('onload', lazyload);
		}
	}, 20);
}

function removeClass(elem, toRemove) {
	oldClasses = elem.className.split(" ");
	newClasses = [];
	for (var i in oldClasses) {
		if (oldClasses[i] != toRemove) {
			newClasses.push(oldClasses[i]);
		}
	}
	elem.className = newClasses.join(" ");
}

var lazyloadImages = document.querySelectorAll('img.lazy');
var lazyloadThrottleTimeout;
window.attachEvent('onscroll', lazyload);
window.attachEvent('onload', lazyload);
window.attachEvent('onresize', lazyload);