﻿
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.swf.height;
		
		Loading.game.height     = '1';
        Loading.game.style.visibility = 'hidden';
        if(document.getElementById('rozmiar')) {
        	document.getElementById('rozmiar').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('<iframe id="wczytywanie_reklama" src="http://topgierki.pl/ramka.php" 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><div id="ladowanie_tekst">Ładowanie gry ... </div>');
		document.getElementById('wczytywanie_pomin').style.display = 'none';

        window.addEvent('domready', Loading.update);
        window.addEvent('load', Loading.finished);
    },

    finished: function() {
		document.getElementById('ladowanie_tekst').style.display = 'none';
		document.getElementById('wczytywanie_pomin').style.display = 'block';
        document.getElementById('wczytywanie_pomin').innerHTML = 'Gra została załadowana, kliknij aby rozpocząć!';
    },

    showGame: function() {
		document.getElementById('pole_suwak').style.display = 'block';
		document.getElementById('ladowanie_tekst').style.display = 'none';
        document.getElementById('wczytywanie_reklama').style.display = 'none';
        document.getElementById('wczytywanie_pasek').style.display   = 'none';
        document.getElementById('wczytywanie_pomin').style.display   = 'none';
		if(document.getElementById('rozmiar')) {
        	document.getElementById('rozmiar').style.visibility  = 'visible';
        }
        Loading.game.height = Loading.height;
        Loading.game.style.visibility = 'visible';
		if( Loading.swf ) {
			Loading.swf.style.visibility = 'visible';
			Loading.swf.height      = Loading.height;
			Loading.swf.zIndex      = 10;
		}
    }
}