var bar_length = 500;
var bar_height = 8;
var wait = 10000;
var more = 0;
var doneyet = 0;


function setup_bar()
{
	window_width = bar_length + 4;
	window_height = bar_height + 4;
	
	if (document.all) // if IE
	{
		bar_height2 = bar_height - 2; 
		bar_width2 = bar_length + 3;
	}
	else
	{
		bar_height2 = bar_height;
		bar_width2 = bar_length + 1;
	}
	var n_width = ((screen.width-window_width)/2);
	var n_height = ((screen.height-window_height)/2);
	document.write('<div id="bar_window" style="top: ' + ((screen.height - window_height)/2-50) + 'px'
		+ ';left: ' + ((screen.width - window_width)/2) + 'px'
		+ ';width: ' + window_width + 'px'
		+ ';height: ' + window_height + 'px'
		+ ';">');
	document.write('<div id="empty_bar" style="width: ' + bar_width2 + 'px'
		+ ';height: ' + bar_height + 'px'
		+ ';">');
	document.write('</div>');
	document.write('<div id="bar" style="max-width: ' + bar_width2 + 'px'
		+ ';height: ' + bar_height2 + 'px'
		+ ';">');
	document.write('</div>');
	document.write('<table id="percent_tb" width="504" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" valign="top">please wait, loading contents</td>');
	document.write('<td width="100" align="right" valign="top"><div id="percent">0%</div></td>');
	document.write('</tr></table>');
	
	document.write('</div>');
	
		
}

function progress_bar()
{

/* the following document element retreives the number of
images on the HTML document */
var image_count = document.getElementsByTagName("img").length;

/* the following variable gets an array of all the images
in the document */
var image_array = document.getElementsByTagName("img");

var bar_part = Math.round(bar_length / image_count);

var bar_perc = Math.round(100 / image_count);
	
	var new_width = 0;
	var j = 0;
	var percent = 0;
	
	for (var i = 0; i < image_count; i++)
	{
		if (image_array[i].complete)
		{
			percent = percent + bar_perc;
			new_width = new_width + bar_part;
			j++;
		}
	}
if (new_width <= parseFloat(document.getElementById('bar').style.width)
		&& new_width < (j*bar_part + bar_part))
	{
		more = more + .50;
		new_width = new_width + Math.round(more);	 
		percent = percent + Math.round(more);
	}
	else
		more = 0; 
	
	if (percent > 100) { percent = 100; }
	
	document.getElementById('percent').innerHTML = percent + '%';
	document.getElementById('bar').style.width = new_width + 'px';
	
	if (j < image_count || j == 0 || doneyet == 0)
		setTimeout('progress_bar();', 500); 
	else
		setTimeout('close_bar();', 500);
	}




function close_bar(){
	$(document).ready(function() {
			$("#bar_window").fadeOut(1000);
			$("#MaskBack").fadeOut(1000);
	});
}

if(document.readyState)	
{
	document.onreadystatechange=checkstate;
}
else if (document.addEventListener)
{
	document.addEventListener("DOMContentLoaded", saydone, false);
}

	
function checkstate()
{
	if (document.readyState=="complete" ||
		document.readyState=="complete")
		doneyet = 1;

}

function saydone()
{
	doneyet = 1;
}
setTimeout('saydone();', wait);


setup_bar();
progress_bar();

