﻿/*=========================
 preveiw
==============================*/

// TODO rename to Preveiw
function MPreview () {
	this._allLoaded = false;
	this.images = $('.prev_left_div img, .prev_right_div img');
	this._lazyLoadTimeout = null;
	this._module = $('#preview');
}

MPreview.prototype = {
	
	lasyLoad: function() {
		if (!this._allLoaded) {
			clearTimeout(this._lazyLoadTimeout);
			var that = this, windowScrollTop = $(window).scrollTop();
			this._lazyLoadTimeout = setTimeout(function() {
				that.images.each(function() {
					var el = $(this), top = el.offset().top - windowScrollTop;
					if (el.is('[data-src]') && top > -70 && top < that._module.height() + 100 ) {
						el.attr('src', el.data('src')).removeAttr('data-src');
					}
				});
				
				if (!that.images.filter('[data-src]').length) that._allLoaded = true;
			}, 0);		
		}		
	}
};
