// JavaScript Document
window.onload = init();

function include(file) {
	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById('lastLoadedCmds');
	if (old) head.removeChild(old);

	script = document.createElement('script');
	script.src = file;
	script.type = 'text/javascript';
	script.defer = true;
	script.id = 'lastLoadedCmds';
	void(head.appendChild(script));
}

function init() {
	var progress = document.getElementById('progress');
	start_timer(progress);
}

function start_timer(progress) {
	var t = 0;
	var e = t;
	var handle = setInterval(function() {
		if(t == wait) {
			clearInterval(handle);
			//remove_bar();
			include("cmp.php?complete&amp;");
		}else {
			show_bar(progress);
			t += 1;
    		e = 124 / wait;
			add_percentage(progress, e, t);
		}
	}, 1000);
}

function show_bar(progress) {
	progress.style.display = "block";
}

function add_percentage(progress, size, sec) {
	progress.style.background = "url(lib/percentImageBack.png)";
	progress.style.width = Math.round(size * sec) + "px";
	if(sec == 30) { progress.style.width = "120px"; }
	var seconds = document.getElementById("seconds");
	seconds.innerHTML = Math.round((100 / wait) * sec, 2) + "%";
}	
