var TR,L,T,tables,Idle;

function idleScreen() {

	document.getElementById(tables[T]).style.display = 'none';

	T++;
	if(T==L) {
		T=0;
	}
	document.getElementById(tables[T]).style.display = '';
}

function SizeWindow() {

	$('.remove').remove();
	tables = new Array();
	var w=$(window).width(),
	h=$(window).height(),
	f = 1,
	saveTR = '',
	i;
	
	TR = document.getElementsByTagName('tr');
	L=TR.length;
	T=0;
	f=1;
	for(i=0;i<L;i++) {	
		while($("#"+TR[i].className).innerWidth()<w){
			$("#"+TR[i].className).css("font-size", f+'px');
			f++;
		}	
		while($("#"+TR[i].className).innerHeight()>h){
			f--;
			$("#"+TR[i].className).css("font-size", f+'px');
		}

		if(saveTR != TR[i].className) {
			tables.push(TR[i].className);
			while(document.getElementById(tables[T]).scrollWidth>w) {
				f--;
				$("#"+TR[i].className).css("font-size", f+'px');
			}	
			$("#"+tables[T]).css("height", h).css("width", w).css("display", "none");
			saveTR = TR[i].className;
			T++;
		}
	}

	L=tables.length;
	if(L>0) {
		T=0;
		$("#"+tables[T]).css("display", "");
	}
	if(IsParent) {
		parent.HideBox()
		parent.hide(parent.document.getElementById('hidden'),false);
	}
	$(".redcenter").css("background-color", "#FFC0C0");
	
	idle = setInterval("idleScreen()",interval);

}

$(document).ready(function() {
	SizeWindow();
});	


function UserInput(key) {

	if(key == '1' || key == '+') {
		$("#"+tables[T]).css("display", "none");
		T++;
		if(T==L) {
			T=0;
		}
		$("#"+tables[T]).css("display", "");
	}
	else if(key == '0' || key == '-') {
		$("#"+tables[T]).css("display", "none");
		T--;
		if(T<0) {
			T=L-1;
		}
		$("#"+tables[T]).css("display", "");
	}
	else {
		if(IsParent) {
			parent.hide(parent.document.getElementById('hidden'),true);
			parent.idle.Running = false;
			parent.document.body.focus();
			parent.document.getElementById('asp').contentWindow.location.replace('empty\\empty.htm'); 
		}
	}
}

function KeyMouse(e) {

	var k,
    evt = e || window.event,
    pressedKeyCode = evt.charCode || evt.keyCode; 

	if(evt.button == 0 && !IsParent) {
		k = '+';
	}
	else {
		k = window.String.fromCharCode(pressedKeyCode);
	}		
	UserInput(k);
}
