//Tamanho da letra (barra de acessibilidade)
fs = 100;		// Tamanho padrão
fmin = 10;		// Tamanho mínimo
fmax = 500;		// Tamanho máximo
fstep = 10;		// Intervalos em % entre zoom-in e zoom-out

function tamLetra(n) {
	if (n == 1) fs = 100;
	if (n == 2 && fs > fmin) {
		fs = fs - fstep;
	}
	if (n == 3 && fs < fmax) fs = fs + fstep;
	$('cnt').setStyle('font-size', fs + '%');
}

/* Enquete */
window.addEvent('domready', function() {
	stopFormEvent();
	window.backupEnquete = ($('enquete_body') ? $('enquete_body').innerHTML : '');
	window.sendCaptchaStatus = false;
	window.ajaxLocation = window.location.protocol + '//' + window.location.hostname;
	
	if ($$('.agregadores').length > 0) {
		$$('.agregadores')[0].getElements('a').each(function(el) {
			el.addEvent('click', function(ev) {
				new Event(ev).stop();
				lnk = el.getProperty('href');
				if (lnk != '' && lnk != 'javascript:;') {
					this.tam = el.getProperty('dir');
					if (this.tam === null) {
						this.tam = [640, 480];
					} else {
						this.tam = this.tam.split('x');
					}
					socialBookmarking = window.open(lnk, 'Social Bookmarking');
				}
			});
		});
	}
});
function stopFormEvent() {
	if ($chk($('frm_enquete'))) {
		$('frm_enquete').addEvent('submit', function(ev) {
			new Event(ev).stop();
			votarEnquete(this);
		});
	}
}
function restoreEnquete() {
	if ($('enquete_body')) {
		$('enquete_body').set('html', window.backupEnquete);
		stopFormEvent();
	}
}
function votarEnquete(f) {
	$('btn_votar').setProperties({
		'value':'Aguarde...',
		'disabled':'disabled'
	});
	new Request({
		url:window.ajaxLocation,
		data:'enquete=true&opcao=' + $$('#frm_enquete input[type=radio]').filter(function(item){return item.get('checked')})[0].get('value'),
		method:'get',
		evalScripts:true,
		onSuccess:function(r) {
			$('enquete_body').set('html', r);
		}
	}).send();
}
function sendCaptcha() {
	if (!window.sendCaptchaStatus) {
		backValue = $('btn_sendCaptcha').getProperty('value');
		$('btn_sendCaptcha').setProperties({
			'value':'Aguarde...',
			'disabled':'disabled'
		});
		window.sendCaptchaStatus = true;
		f = $('form_captcha_enquete');
		new Request({
			url:window.ajaxLocation,
			data:f.toQueryString(),
			method:'post',
			evalScripts:true,
			onSuccess:function(r) {
				r = r.trim().split('::');
				status = r[0];
				r = r[1];
				if (status == 'erro') {
					$('captchaResponse').set('html', r);
					$('btn_sendCaptcha').setProperty('value', backValue);
					$('btn_sendCaptcha').removeProperty('disabled');
				} else {
					$('enquete_body').set('html', status);
				}
				window.sendCaptchaStatus = false;
			}
		}).send();
	}
}
function resultadosEnquete() {
	$('lnk_verResultados').set('html', 'Aguarde...');
	$('lnk_verResultados').onclick = function(){}
	new Request({
		url:window.ajaxLocation,
		data:'resultados_enquete=true',
		method:'get',
		onSuccess:function(r) {
			$('enquete_body').set('html', r);
		}
	}).send();
}

window.addEvent('domready', function() {
	if (window.location.href.test('#comentarios')) {
		new Fx.Scroll(window, {transition:Fx.Transitions.Cubic.easeOut}).toElement('sentComments');
	}
	
	/* Carregando contador */
	if ($$('#contador span').length > 0) {
		new Request({
			url:'/',
			data:'carrega_contador=true',
			method:'post',
			onSuccess:function(r) {
				$$('#contador span')[0].set('html', r);
			}
		}).send();
	}
});