function tvblock(args) {
		var halt;
		var items = $(args.stack).find(".item");
		var length = items.length + 1;
		var index = 1;
		var list_items;

		args.stack.style.width = (length * 436) + "px";
		build_list();
		timer_halt_start();

		function build_list() {
			for (var i = 1; i < length; i++) {
				var span = document.createElement("span");
				if (i == index)
					span.className = "number locked";
				else
					span.className = "number";
				span.innerHTML = i;

				$(span).click(function() {
					go(this.innerHTML * 1);
				});

				args.numbers.appendChild(span);
			}
			list_items = args.numbers.getElementsByTagName("span");

			$(args.next).click(function() {
				go(index + 1);
			});
			$(args.previous).click(function() {
				go(index - 1);
			});


		}

		function timer_halt_start() {
			halt = setTimeout(function(){go(index + 1)}, args.times.halt);
		}
		function timer_halt_stop() {
			clearTimeout(halt);
		}

		function slide(str) {
			$(args.stack).animate({"left": str}, args.times.slide, "linear", timer_halt_start);
		}
		function go(i) {
			timer_halt_stop();

			if (i >= length) {
				var distance = 0;
				str = "0px";
				i = 1;
			}
			else {
				if (i < 1)
					i = 5;

				var distance = i - index;

				if (distance > 0)
					str = "+="+ (distance * 436) +"px";
				else
					str = "-="+ ((distance * 436) * -1) +"px";
			}
			slide(str);

			list_items[index-1].className = "number";
			list_items[i-1].className = "number locked";

			index = i;
		}
}
$(document).ready(function() {
	var tv = new tvblock({
		stack: document.getElementById("tvblock-stack"),
		previous: document.getElementById("tvblock-prev"),
		next: document.getElementById("tvblock-next"),
		numbers: document.getElementById("tvblock-numbers"),
		times: {
			slide: 280,
			halt: 5000
		}
	});
});
function getElementsByClassName(node, classname) {
	var elements = [];
	var re = new RegExp('(^| )' + classname + '( |$)');
	var children = node.getElementsByTagName("div");
	for (var i = 0, j = children.length; i < j; i++)
		if (re.test(children[i].className)) elements.push(children[i]);
	return elements;
}
