function scroll_init(id, largura, altura, controles) {
	var tag = _get(id);	
	if (tag) {
		var div1 = document.createElement('div');	
		var div2 = document.createElement('div');	
		div1.style.width = largura + 'px';
		div1.style.height = altura + 'px';
		div1.style.overflow = 'hidden';	
		div1.appendChild(div2);	
		if (tag.hasChildNodes()) {
			while (tag.hasChildNodes())
				div2.appendChild(tag.removeChild(tag.firstChild))
			tag.appendChild(div1);
		}
		else {
			tag.parentNode.replaceChild(div1, tag);
			div2.appendChild(tag);
		}
		tag.style.display = '';
		if (controles && largura >= (window.opera ? 2000 : div2.scrollWidth) && altura >= div2.scrollHeight) {
			controles = controles.split(/\W/);
			for (var i in controles)
				_get(controles[i]).style.visibility = 'hidden';
		}
	}
}

function scroll_start(id, horizontal, vertical) {
	var tag = _get(id);
	var div1, div2;
	if (tag.hasChildNodes())
		div2 = (div1 = tag.firstChild).firstChild;
	else
		div1 = (div2 = tag.parentNode).parentNode;
	var largura = (window.opera ? 2000 : div2.scrollWidth) - parseInt(div1.style.width);
	var altura = div2.scrollHeight - parseInt(div1.style.height);
	if (tag.scroll_timer) window.clearInterval(tag.scroll_timer);
	tag.scroll_timer = window.setInterval(function() {
		var esquerda = parseInt(div2.style.marginLeft) || 0;
		var topo = parseInt(div2.style.marginTop) || 0;
		if (largura < 0 || esquerda - horizontal >= 0)
			horizontal = esquerda;
		else if (largura + esquerda - horizontal < 0)
			horizontal = largura + esquerda;
		if (altura < 0 || topo - vertical >= 0)
			vertical = topo;
		else if (altura + topo - vertical < 0)
			vertical = altura + topo;
		div2.style.marginLeft = esquerda - horizontal + 'px';
		div2.style.marginTop = topo - vertical + 'px';
	}, 100);
}
function scroll_stop(id) {
	var tag = _get(id);
	if (tag.scroll_timer) window.clearInterval(tag.scroll_timer);
	tag.scroll_timer = '';
}
function _get(id) {
	return document.getElementById && document.getElementById(id) || document.all && document.all[id];
}

