var Loading = {
    height: null,
	loaded: false,
	interval: 100,
	ladowanie:null,
	zaladowana:null,
	dluzej:null,
    update: function() {
		
		if ($('loading_box_progress_bar')) {
            progress = parseInt($('loading_box_progress_bar').getStyle('width'));
			
            if (progress < 100) {
                $('loading_box_progress_bar').setStyle({width: progress+1+'%'});
                $('loading_box_progress_percent').innerHTML = progress+1+'%';				
                setTimeout(Loading.update, Loading.interval);
            } else if(Loading.loaded==true) {
                Loading.showGame();				
			} else {
            	Loading.interval = 100; 
            	$('loading_box_progress_bar').setStyle({width: '1%'});
				$('skip_loading').innerHTML = '<a href="javascript:void(0)" onclick="Loading.showGame()">'+Loading.dluzej+'</a>';
            	//$('skip_loading').innerHTML = "Trwa ładowanie... czekaj... (gra może ładować się kilka minut)";
            	setTimeout(Loading.update, Loading.interval);
            }
        }
    },
		
    begin: function(ads,cls,ladowanie, zaladowana, dluzej) {
		Loading.height = $('ramka').getStyle('height');
		Loading.cls = cls;
		Loading.ladowanie = ladowanie;
		Loading.zaladowana = zaladowana;
		Loading.dluzej = dluzej;
		
        document.getElementById('ramka').style.height     = '0px';
        document.getElementById('ramka').style.visibility = 'hidden';

 //href="javascript:void(0)" onclick="Loading.showGame()">''
		document.write('<iframe id="'+cls+'" src="'+ads+'" frameborder="0" scrolling="no" align="center" valign="middle"></iframe>');
        document.write('<div id="loading_box_progress"><div id="loading_box_progress_bar"></div><div id="loading_box_progress_percent">0%</div></div>');
        document.write('<div id="skip_loading">'+Loading.ladowanie+'</div>');

        //document.write('<iframe id="'+cls+'" src="'+ads+'" frameborder="0" scrolling="no" style="width:346px;height:290px;"></iframe>');
        //document.write('<br><br><div id="loading_box_progress" style="border: 0px solid #00cc00; width: 200px;"><div style="border: 1px solid #FF9900;height:10px;"><div align="left" id="loading_box_progress_bar" style="border: 0px solid #FF9900;width:0px;height:10px;background-color: #FF9900;float:left;"></div></div><div id="loading_box_progress_percent">0%</div></div>');
        //document.write('<a id="skip_loading" href="javascript:void(0)" onclick="Loading.showGame()">'+Loading.ladowanie+'</a>');

        Element.observe('ramka','load', Loading.finished )
        document.observe('dom:loaded', Loading.update);
       
    },

    finished: function() {
		
        $('skip_loading').innerHTML = '<a href="javascript:void(0)" onclick="Loading.showGame()">'+Loading.zaladowana+'</a>';
        Loading.loaded = true;
    },

    showGame: function() {
		document.getElementById(Loading.cls).style.display = 'none';
        document.getElementById('loading_box_progress').style.display = 'none';
        document.getElementById('skip_loading').style.display = 'none';
		//document.write('wysokosc gry:' + Loading.height);

        document.getElementById('ramka').style.height = Loading.height;
        document.getElementById('ramka').style.visibility = 'visible';
    }
}

