/**
 * @author Simone Villas Boas [sydi.net], Spark 
 * 
 */

// verificar se tem #posicao na url da pagina
// escrever botoes de prev/next com o link do #hash 
// colocar o scroll na altura indicada (numero 1, 2, 3, etc)
//
/*
<div id="pgnav" class="nav">
				<span id="prev"><a href="#1" id="prevLnk" class="disable" onclick="return goUp(this);"><< anterior</a></span> | 
				<span id="next"><a href="#3" id="nextLnk" onclick="return goDown(this);">próximo >></a></span>
</div>
*/

rewriteButtons = function()
{
	var pgContainer = document.getElementById('pagCont');
	pgContainer.innerHTML = "<div id=\"pgnav\" class=\"nav\">"+
	"<span id=\"prev\"><a id=\"prevLnk\" href=\"#\"  onclick=\"return false;\" onmouseover=\"scrollayer('innerScroller',-10,100)\" onmouseout=\"stopScroll()\">&lt;&lt; anterior</a></span> | "+
	"<span id=\"next\"><a  id=\"nextLnk\" href=\"#\" onclick=\"return false;\" onmouseover=\"scrollayer('innerScroller',10,100)\" onmouseout=\"stopScroll()\">próximo &gt;&gt;</a></span></div>";
	
}

/*
 * DHTML micro API
 * http://www.quirksmode.org/js/dhtmloptions.html#versiona
 * 
 */

function getObj(name)
{
	if (document.getElementById && document.getElementById(name))
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all && document.all[name])
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers && document.layers[name])
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
	
}

/*
 * 
 * PPK Old Scrolling layer
 * http://www.quirksmode.org/js/layerscroll.html
 * 
 */

var clipTop = 0;
var clipWidth = 320;
var clipBottom = 282;
var topper = 0;
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj('innerScroller');
	if (document.layers)
	{
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if (document.getElementById || document.all)
	{
		lyrheight = x.obj.offsetHeight;
		x.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
	}
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	else{
		//console.log('está no topo? ');
	}
	
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper + 'px';
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	time = setTimeout('realscroll()',theTime);
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

/*
 * If text is bigger than area, init scroll, and create buttons
 */
window.onload = function(){
	var x = new getObj('innerScroller');
	if (x.obj && x.obj.offsetHeight > 282)
	{
		init();
		rewriteButtons();
	}
}





 
