﻿// JScript File

document.observe('dom:loaded',function() {
    var loader;
    var run=0;
    var imgLoad = $$('body')[0].adjacent('img');
    var imgLoadC = imgLoad.length;
    var dimen = document.viewport.getDimensions();
    loader = $('lmLoader1');
    /*loader = new Element('div',{id:'lmLoader1'}).setStyle(
        { 'backgroundColor' : 'white',
             'height' : dimen.height + 'px',
             'width': dimen.width + 'px',
             'zIndex': 20000,
             'position':'fixed'});
    $$('body')[0].insert({'top':loader});*/
    
    imgLoad.each(function(img) {
        if (!img.complete) {
            img.observe('error',lmPicCheck);
            img.observe('load',lmPicCheck);
         } else
            imgLoadC--;
    });
    lmPicCheck();
    
    function lmPicCheck(event) {
        if (event)
            imgLoadC--;
        if (imgLoadC == 0) {
            document.fire('img:loaded');
            loader.remove();
        }
    }
    
/*    function lmPicCheck(pe) {
        run++;
        pe.stop();
        var loaded = true;
        $$('body')[0].adjacent('img').each(function(img) {
            if (!img.complete) {
                if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
                }
                loaded = false;
            }
        });
        if (!loaded && run<10) {
            new PeriodicalExecuter(lmPicCheck, 0.2); 
        } else {
            document.fire('img:loaded');
            loader.remove();
        }
    }*/
});