var tweenBySize = 130;
if (window.addEventListener) window.addEventListener("DOMMouseScroll", wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

/*function $(i) { return document.getElementById(i) }*/

function handle(i) {
	try {
		if (i < 0) scrollbar.tweenBy(tweenBySize);
		else       scrollbar.tweenBy(-tweenBySize);
	} catch (e) {}  
}

function wheel(event) {
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta / 120; 
		if (window.opera) delta *= -1;
	} else if (event.detail) {
		delta = -event.detail / 3;
	}
	if (delta)
		handle(delta);
}

function slideShow(bGoNext) {
	if (bGoNext) {
		iPic++;
		// Volta ao primeiro thumb
		if (iPic == aPic.length) iPic = 0;
	} else { // back
		iPic--;
		// Avanca ao ultimo thumb
		if (iPic < 0) iPic = aPic.length - 1;
	}
	$("slide-pic").src = aPic[iPic].src;
	return false;
}

function nI(src) {
	var i = new Image();
	i.src = src;
	return i;
}

function trocaAba(number, noScroll, width, height) {
	var aPai = $("box-form").childNodes;
	for (i = 0, j = 1; i < aPai.length; i++)
		if (aPai[i].nodeName == "DIV" && aPai[i].id.indexOf("passo") != -1) {
			$("passo" + j).style.display = "none";
			j++;
		}

	var aAba = $("abas").childNodes;
	for (i = 0, j = 1; i < aAba.length; i++)
		if (aAba[i].nodeName == "A" && aAba[i].id.indexOf("aba") != -1) {
			$("aba" + j).className = "";
			j++;
		}

	var imgHeight = (j > 3) ? 80 : 64;

	$("abas").style.backgroundPosition = "0px -" + (imgHeight * (number - 1)) + "px";	
	$("aba" + number).className = "selected";
	$("passo" + number).style.display = "block";

	if (!noScroll) carregaScroll(width, height, "-Passo", number);
}

function carregaScroll(width, height, prefixo, number) {
	scroller    = new jsScroller($("Scrollbar-Content" + prefixo + number), width, height);
	scrollbar   = new jsScrollbar($("Scrollbar" + prefixo + number), scroller, true);
	scrollTween = new jsScrollerTween(scrollbar, true);
	scrollbar._scrollDist = 2;
}

function abreRegulamento() {
	if ($("fRegulamento").checked) $("fRegulamento").checked = (is.ie); else $("fRegulamento").checked = !(is.ie);
	
	var w = 426;
	var h = 438;
	var u = "../../br/mostre_ritmo/popup-regulamento.asp";
	var l = (screen.availWidth-w) / 2;
	var t = (screen.availHeight-h) / 2;
	
	window.open(u,'Regulamento','left='+l+',top='+t+',width='+w+',height='+h+',scrollbar=no,resize=no,statusbar=no');
}

function abreCorreios() {
	var w = (is.ie) ? 356 : 353;
	var h = (is.ie) ? 360 : 303;
	var u = "../../br/mostre_ritmo/popup-correios.html";
	var l = (screen.availWidth-w) / 2;
	var t = (screen.availHeight-h) / 2;
	
	window.open(u,'Consulta','left='+l+',top='+t+',width='+w+',height='+h+',scrollbar=no,resize=no,statusbar=no');
}

function abrePecas() {
	var w = (is.ie) ? 535 : 535;
	var h = (is.ie) ? 367 : 367;
	var u = "../../br/sobre/pecas/1.html";
	var l = (screen.availWidth-w) / 2;
	var t = (screen.availHeight-h) / 2;
	
	window.open(u,'Peça','left='+l+',top='+t+',width='+w+',height='+h+',scrollbar=no,resize=no,statusbar=no');
}

function addTabScroll(id) {
	var aInput = $(id).getElementsByTagName("input");
	for (i = 0; i < aInput.length; i++)
		if (aInput[i].type.indexOf("text") != -1 || aInput[i].type.indexOf("radio") != -1 || aInput[i].type.indexOf("checkbox") != -1)
			aInput[i].onfocus = new Function("tabScrollbar(this)");
			
	var aInput = $(id).getElementsByTagName("select");
	for (i = 0; i < aInput.length; i++)
		aInput[i].onfocus = new Function("tabScrollbar(this)");
}

function exibirswf(swf,width,height)
{
	document.write('<object type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" data="' + swf + '">');
	document.write('<param name="movie" value="' + swf + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + swf + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent"></embed>');
	document.write('</object>');
}

function tabScrollbar(obj) {
	var t = 0;
	do {
		t += obj.offsetTop  || 0;
		obj = obj.offsetParent;
		if (obj) {
			p = obj.style.position;
			if (p == 'relative' || p == 'absolute') break;
		}
	} while (obj && obj.className != "Scroller-Container");//
	scrollbar.tweenTo(t);
}