﻿var Loading = {
    height: null,
    game:   null,
    swf:    null,

    update: function() {
        if (document.getElementById('wczytywanie_pasek_kolor')) {
            progress = document.getElementById('wczytywanie_pasek_kolor').style.width;
            progress = parseInt(progress);

            if (progress < 100) {
                document.getElementById('wczytywanie_pasek_kolor').style.width   = progress+1+'%';
                document.getElementById('wczytywanie_pasek_procenty').innerHTML = progress+1+'%';
                setTimeout(Loading.update, 150);
            } else {
                Loading.showGame();
            }
        }
    },

    begin: function() {
    	if(document.getElementById('game')) {
    		Loading.game   = document.getElementById('game');
    	} else {
    		return;
    	}
    	if(document.getElementById('swf')) {
    		Loading.swf   = document.getElementById('swf');
    	}
        Loading.height = Loading.game.height;
		Loading.height = parseInt(Loading.height);

        Loading.game.height     = '1';
        Loading.game.style.visibility = 'hidden';
        if(document.getElementById('zmiana_rozmiaru')) {
        	document.getElementById('zmiana_rozmiaru').style.visibility  = 'hidden';
        }
        if( Loading.swf ) {
        	Loading.swf.height      = '1';
        	Loading.swf.style.visibility  = 'hidden';
        	Loading.swf.onload = function() { Loading.finished(); }
         } else {
       		Loading.game.onload = function() { Loading.finished(); }
       	}

        document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.giercownia.pl/googlebox.html" frameborder="0" scrolling="no"></iframe>');
        document.write('<div id="wczytywanie_pasek"><div id="wczytywanie_pasek_kolor" style="width:0%;"></div><div id="wczytywanie_pasek_procenty">0%</div></div>');
        document.write('<a id="wczytywanie_pomin" href="javascript:void(0)" onclick="Loading.showGame()">Ładowanie gry ... </a>');

        window.addEvent('domready', Loading.update);
        window.addEvent('load', Loading.finished);
    },

    finished: function() {
        document.getElementById('wczytywanie_pomin').innerHTML = 'Gra została załadowana, kliknij aby rozpocząć!';
    },

    showGame: function() {
        document.getElementById('wczytywanie_reklama').style.display = 'none';
        document.getElementById('wczytywanie_pasek').style.display   = 'none';
        document.getElementById('wczytywanie_pomin').style.display   = 'none';
        if(document.getElementById('zmiana_rozmiaru')) {
        	document.getElementById('zmiana_rozmiaru').style.visibility  = 'visible';
        }
        Loading.game.height = Loading.height;
        Loading.game.style.visibility = 'visible';

        if( Loading.swf ) {
			Loading.swf.height = Loading.height;
        	Loading.swf.style.visibility = 'visible';
        }
    }
}
