var numMainImages = 20;
var numLoaded     = 0;
var images        = new Array();
var imgTimer;
var imgInterval   = 100;

var movie;

function showMainContent()
{
	document.getElementById("preloader").style.display   = "none";
	document.getElementById("mainContent").style.display = "inline";
	document.getElementById("topItemWrap").style.display = "inline";
}

function showPreloader()
{
	if (flashAvailable(8, 0, 0))
	{
		document.getElementById('preloaderMovie').style.display = 'inline';
	}

	document.getElementById("preloader").style.display   = "inline";
}

function loadHomeContent()
{
	 
	// create image array
	var imgArray  = new Array();
	imgArray[0]   = "../images/menu/my_products_roll.png";
	imgArray[1]   = "../images/menu/online_store_roll.png";
	imgArray[2]   = "../images/menu/product_registration_roll.png";
	imgArray[3]   = "../images/menu/support_roll.png";
	
	imgArray[4]   = "../images/roll_buttons/roll_awards.png";
	imgArray[5]   = "../images/roll_buttons/roll_educational.png";
	imgArray[6]   = "../images/roll_buttons/roll_freeg.png";
	imgArray[7]   = "../images/roll_buttons/roll_products.png";
	imgArray[8]   = "../images/roll_buttons/roll_producer.png";
	imgArray[9]   = "../images/roll_buttons/roll_rentals.png";
	
	imgArray[10]  = "../images/banners/banner_sonalksis2.png";
	imgArray[11]  = "../images/buttons/help_red2.png";
	imgArray[12]  = "../images/buttons/help_orange2.png";
	imgArray[13]  = "../images/buttons/button_login_big.png";
	imgArray[14]  = "../images/buttons/button_logout_big.png";
	imgArray[15]  = "../images/roll_buttons/roll_button.png";
	imgArray[16]  = "../images/symbol_sonalksis.png";
	imgArray[17]  = "../images/background_mailing_list.png";
	imgArray[18]  = "../images/roll_buttons/roll_button2.png";
	imgArray[19]  = "../images/menu/menu2.png";
	
	// preload images
	for (var i = 0; i < numMainImages; i++)
	{
		images[i]        = new Image();
		images[i].onLoad = imgLoaded();
		images[i].src    = imgArray[i];
	}
}

function imgLoaded()
{
	numLoaded++;
	
	if (numLoaded == numMainImages){ loadComplete(); }
}

function loadComplete()
{
	var completeImgs = 0;
	
	for (var i = 0; i < numMainImages; i++)
	{
		if (isImageOk2(images[i]))
		{
			completeImgs++;
		}
	}

	if (completeImgs >= numMainImages)
	{
		//completeImgs = 0;
		clearTimeout(imgTimer);
		showMainContent();
	}
	else
	{
		showPreloader();
		imgTimer = setTimeout(function(){loadComplete();}, imgInterval); 
	}
}

function isImageOk2(img) {
    // During the onload event, IE correctly identifies any images
    // that weren't downloaded as not complete. Others should too.
    // Gecko-based browsers act like NS4 in that they report this
    // incorrectly: they always return true.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth
    // and naturalHeight. These give the true size of the image. If
    // it failed to load, either of these should be zero.

    
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}


