function in_array(needle, haystack)
{
	for (key in haystack)
	{
    		if (haystack[key] === needle) return true;
	}

	return false;
}

function load_game()
{
      	jQuery('#playonline_promo_container').hide();
        jQuery('#playonline_container').show();
}

function set_promo(data)
{
	var obj = document.getElementById('playonline_promo');
	if (obj) jQuery(obj).html(data);
}

function generate_promo(swf_preloader, count)
{
	var html = '';
	var rand = new Array();
	var size = swf_preloader.length;

	if (count > size) count = size;

	while (rand.length < count)
	{
    		ind = Math.floor(Math.random()*size);

    		if (!in_array(ind, rand))
    		{
        		rand.push(ind);
        		html  += '<div class="promo_img">' + swf_preloader[ind] + '</div>';
    		}
	}

	html += '<div class="clear"></div>';

	return html;
}

function start_preloader()
{
	var obj = document.getElementsByTagName('object');

	if (obj)
	{
		jQuery(obj[0]).parent().wrap('<div id="playonline_container"></div>');
		jQuery('<div id="playonline_promo_container"><div id="playonline_promo"></div></div>').insertBefore('#playonline_container');

		width  = jQuery('#playonline_container').width();
		height = jQuery('#playonline_container').height();

		jQuery('#playonline_promo_container').width(width);
		jQuery('#playonline_promo_container').height(height);

		jQuery('#playonline_promo_container').css('display', 'table-cell');
		jQuery('#playonline_container').hide();

		setTimeout(load_game, 10000);
	}

}


