function loadingCheck()
{
    if( document.images.length == 0 )
	return;

    var loaded=0;
    for( var i=0; i < document.images.length; i++ )
    {
	if( document.images[i].complete )
	    loaded++;
    }
    // preloading does not work in opera
    // weird bug: only x-4 imgs (of x) preload
    if( ( loaded >= document.images.length-1 ) || ( navigator.userAgent.indexOf('Opera') > -1 ) )
    {
	window.clearInterval( loadingTimerID );

	fadeDone();
    }
}

var isFadeDone = false;
var browserIsIE = false;
function fadeDone( clicked )
{
    if( !isFadeDone ) // preventing multiple clicks on flower
    {
	var duration = ( clicked ? 0.5 : 1.8 );
	new Effect.Fade( loadingID, { duration: duration } );
	if( browserIsIE )
	    new Effect.Appear( pageID, { duration: duration } );
	else
	    pageID.style.display = 'block';
	new Effect.Appear( mainID, { duration: duration, afterFinish: function() { bodyID.style.overflow = 'auto'; } } );
	isFadeDone = 1;
    }
}

function display_loading() {
    // getting ids
    bodyID = document.getElementsByTagName( "body" )[0];
    mainID = document.getElementById( "main" );
    pageID = document.getElementById( "page" );
    loadingID = document.getElementById( "loading" );
    notsupID = document.getElementById( "notsupportedbrowser" );

    if( navigator.userAgent.indexOf('Firefox') == -1 )
    {
	if( navigator.userAgent.indexOf('MSIE') > -1 )
	{
	    // getting ie version
	    var verPos = navigator.userAgent.indexOf('MSIE')+5;
	    if( ( navigator.userAgent.substring( verPos, verPos+1 ) < 7 ) && ( navigator.userAgent.indexOf('AMBrowser') < 0 ) )
	    {
		new Effect.Appear( notsupID, { duration: 1 } );
		return;
	    }
	    browserIsIE = true;
	}
    }
    new Effect.Appear( loadingID, { duration: 0.5, afterFinish: function() {
	    loadingTimerID = window.setInterval( "loadingCheck();", 1 ); 
	} } );
}

var bodyID = 0;
var mainID = 0;
var pageID = 0;
var loadingID = 0;
var notsupID = 0;
