var mode = 1;
var hidePast = 1;
var columns = 2;
var progs = new Array();
var lens = new Array();
function drawChannel(id)
{
	if (!progs[id])
		return false;
	d = new Date();
	var now = d.getHours()*100 + d.getMinutes();
	if (now <= 500)
		now += 3000;
	mainDiv = document.getElementById('programm' + id);
	for (i in mainDiv.childNodes) {
		while (mainDiv.childNodes[i].firstChild)
			mainDiv.childNodes[i].removeChild(mainDiv.childNodes[i].firstChild);
	}
	cNode = 0
	cDiv = mainDiv.childNodes.item(cNode++);
	div = hidePast ? -1 : parseInt(lens[id] / columns);
	i = 0
	current = 0
	prevTime = 0
	for (time in progs[id]) {
		if (mode && !current && time > now) {
			current = 1
			if (hidePast) {
				appendProgram(prevTime, progs[id][prevTime]);
				div = parseInt((lens[id] - i) / columns);
				i = 0;
			}
			if (cDiv.lastChild)
				cDiv.lastChild.className = 'current';
		}
		if (i++ == div) {
			cDiv = mainDiv.childNodes.item(cNode++);
			i = 0
		}
		prevTime = time;
		if ((hidePast && current) || !hidePast) {
			appendProgram(time, progs[id][time]);
		}
	}
	if (mode && !current) {
		if (hidePast)
			appendProgram(time, progs[id][time]);
		if (cDiv.lastChild)
			cDiv.lastChild.className = 'current';
	}
}

function appendProgram(time, name)
{
	if (!name)
		return;
	tmp = pSample.cloneNode(true);
	cDiv.appendChild(tmp);
	tmp.id = null;
	tmp.firstChild.innerHTML = get2digits(parseInt(time / 100) % 30) + ':' + get2digits(parseInt(time % 100));
	tmp.lastChild.innerHTML = name;
}

function get2digits(val) {
	if (val < 10)
		val = '0' + val;
	return val;
}