var Loading = {
    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( section ) {
        var psaie = !!(document.all && (!window.opera));
    	if(document.getElementById('game')) {
    		Loading.game = document.getElementById('game');
    	} else {
    		return;
    	}
    	if(document.getElementById('swf') && !psaie) {
    		Loading.swf = document.getElementById('swf');
    	}

        Loading.game.style.display = 'none';
        if(document.getElementById('zmiana_rozmiaru')) {
        	document.getElementById('zmiana_rozmiaru').style.display = 'none';
        }
        if( Loading.swf && !psaie ) {
        	Loading.swf.style.display = 'none';
        	Loading.swf.onload = function() { Loading.finished(); }
         } else {
       		Loading.game.onload = function() { Loading.finished(); }
       	}

		var los = Math.random();
		if(los > 0.2)
			document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/google300px.html" frameborder="0" scrolling="no"></iframe>');
		else if (los <= 0.2 && los > 0.05 && section == 'gry')
			document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/farm300px.html" frameborder="0" scrolling="no"></iframe>');
		else if (los <= 0.05 && section == 'gry')
			document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/nov300px.html" frameborder="0" scrolling="no"></iframe>');
		else if (los <= 0.2 && section == 'ubieranki')
			document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/farm300px.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() {
    	progress = document.getElementById('wczytywanie_pasek_kolor').style.width;
        progress = parseInt(progress);
        if(progress > 50)
        	document.getElementById('wczytywanie_pomin').innerHTML = 'Gra została załadowana, kliknij aby rozpocz±ć!';
        else
        	setTimeout(Loading.finished, 250);
    },

    showGame: function() {
        var psaie = !!(document.all && (!window.opera));
        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.display = '';
        }
        document.getElementById('game').style.display = '';

        if (psaie) {
                flashObjects = document.all.tags('OBJECT');
                for (psii=0;psii<flashObjects.length;psii++) {
                        if (flashObjects[psii].wmode!= null) {
                                if ((flashObjects[psii].wmode).toLowerCase() == 'opaque') {
                                        var playFlash = false;
                                        if (flashObjects[psii].IsPlaying())
                                                playFlash = true;
                                        flashObjects[psii].wmode = 'window'
                                        if (playFlash)
                                                flashObjects[psii].Play();
                                }
                        }
                } //end for
        } //end if

        if( document.getElementById('swf') ) {
        	document.getElementById('swf').style.display = '';
        }
    }
}


var Loading2 = {
	    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(Loading2.update, 350);
	            } else {
	                Loading2.showGame();
	            }
	        }
	    },

	    begin: function( section ) {
	        var psaie = !!(document.all && (!window.opera));
	    	if(document.getElementById('game')) {
	    		Loading2.game = document.getElementById('game');
	    	} else {
	    		return;
	    	}
	    	if(document.getElementById('swf') && !psaie) {
	    		Loading2.swf = document.getElementById('swf');
	    	}

	        Loading2.game.style.display = 'none';
	        if(document.getElementById('zmiana_rozmiaru')) {
	        	document.getElementById('zmiana_rozmiaru').style.display = 'none';
	        }
	        if( Loading2.swf && !psaie ) {
	        	Loading2.swf.style.display = 'none';
	        	Loading2.swf.onload = function() { Loading2.finished(); }
	         } else {
	       		Loading2.game.onload = function() { Loading2.finished(); }
	       	}

			var los = Math.random();
			if(los > 0.2)
				document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/google300px.html" frameborder="0" scrolling="no"></iframe>');
			else if (los <= 0.2 && los > 0.1 && section == 'gry')
				document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/farm300px.html" frameborder="0" scrolling="no"></iframe>');
			else if (los <= 0.1 && section == 'gry')
				document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/nov300px.html" frameborder="0" scrolling="no"></iframe>');
			else if (los <= 0.2 && section == 'ubieranki')
				document.write('<br/><iframe id="wczytywanie_reklama" src="http://www.jeja.pl/rkl/farm300px.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('<p id="wczytywanie_pomin">Ładowanie gry ... </p>');

	        window.addEvent('domready', Loading2.update);
	        window.addEvent('load', Loading2.finished);
	    },

	    finished: function() {
	        //document.getElementById('wczytywanie_pomin').innerHTML = 'Gra została załadowana, kliknij aby rozpocz±ć!';
	    },

	    showGame: function() {
	        var psaie = !!(document.all && (!window.opera));
	        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.display = '';
	        }
	        document.getElementById('game').style.display = ''

	        if (psaie) {
	                flashObjects = document.all.tags('OBJECT');
	                for (psii=0;psii<flashObjects.length;psii++) {
	                        if (flashObjects[psii].wmode!= null) {
	                                if ((flashObjects[psii].wmode).toLowerCase() == 'opaque') {
	                                        var playFlash = false;
	                                        if (flashObjects[psii].IsPlaying())
	                                                playFlash = true;
	                                        flashObjects[psii].wmode = 'window'
	                                        if (playFlash)
	                                                flashObjects[psii].Play();
	                                }
	                        }
	                } //end for
	        } //end if

	        if( document.getElementById('swf') ) {
	        	document.getElementById('swf').style.display = '';
	        }
	    }
	}