
$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) {
	$(pager).find('li').removeClass('activeLI')
		.filter('li:eq('+currSlideIndex+')').addClass('activeLI');
};

$(document).ready(function(){
	$('#slideshow').cycle({
		timeout: 6000,
		pager:  '#nav',
		pagerAnchorBuilder: function(idx, slide) {
			return '<li><a href="#"><img src="' + slide.src + '" width="50" height="38" /></a></li>';
		},
		before: function() {  
			$('#caption').html(this.alt); 
		} 
	});

	$("#opinar").click(function () {
	
		$("#formEnquete").send({
			dataType:"html",
			success:function(jason){
				$("#enquete").html("");
				$("#enquete").html($(jason));
			}
		});
	});
});

$.fn.send = function(opts)
{
	opts = opts || {};
	var default_opts = {			
		dataType : 'json',			
		success : null,
		error: null			
	};

	var enabled_opts = $.extend(default_opts, opts);

	$.ajax({
		url: $(this).attr('action'),
		type: $(this).attr('method'),
		dataType: enabled_opts.dataType,
		data: $(this).serialize(),
		success: enabled_opts.success,
		error: enabled_opts.error
	});
}

/* Config */
var tempoAlternar = 4000;
var tempoAddLetra = 50;
var cfgLimitChar = 80;

/* Fim Config */

var nitens = 0;
var atual = 0;

var totChar;
var limitChar;
var maxChar;
var minChar;
var TextoComp;

function addLetra(){
	maxChar++;
	cMax = maxChar;
	minChar = maxChar - limitChar;
	if (minChar < 0) minChar = 0;
	if (cMax > limitChar) cMax = limitChar;
	

	texto = TextoComp.substr(minChar, cMax);
	
	if (maxChar==totChar){
		document.getElementById('ult').innerHTML = '<a href="noticia.php?id=' + IDNot + '" title="">' + texto + '</a>';
		window.setTimeout('mudaItem()', tempoAlternar);
	}else {
		document.getElementById('ult').innerHTML = '<a href="noticia.php?id=' + IDNot + '" title="">' + texto + '_</a>';
		window.setTimeout('addLetra()', tempoAddLetra);
	}
}

function escreveItem(id){
	totChar = itens[id].length;
	limitChar = cfgLimitChar;
	maxChar = 0;
	minChar = -cfgLimitChar;
	TextoComp = itens[id];
	IDNot = idnot[id];
	addLetra();
}

function mudaItem(){
	if (document.getElementById('ult') != null){
		if (atual > nitens) atual=0;
		novoItem = atual++;
		escreveItem(novoItem);
	}
}

function excluiItem(msg, destino){
	if (confirm('Deseja excluir: ' + msg + ' ?')){
		window.location=destino;
	}
}

function pergunta(msg, destino){
	if (confirm(msg)){
		window.location=destino;
	}
}

function mudaStatusBar(){
    setTimeout("erase()",0);
}

function erase(){
   window.status="rccto.org.br";
}

erase();

function abrir(pagina,nome,largura,altura,parametros) {
	//pega a resolução do visitante
	w = screen.width;
	h = screen.height;
	//divide a resolução por 2, obtendo o centro do monitor
	meio_w = w/2;
	meio_h = h/2;
	//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
	altura2 = altura/2;
	largura2 = largura/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	//alert('height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+''+parametros);
	window.open(pagina,'','height=' + altura + ', width=' + largura + ', top='+meio1+', left='+meio2+''+parametros); 
}

function combo_reload(targ,selObj,restore){ // onChange="combo_reload('seloTempo',this,2)"
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}

function doEmail(pStr) // onBlur="doEmail(this.value); return false;"
{
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/; 
	if (reEmail.test(pStr)) {
		return true;
	} else if (pStr != null && pStr != "") {
		alert("'"+pStr + "'\nNÃO é um endereço de e-mail válido.");
		document.form1.email.value="";
		document.form1.email.focus();
		return false;
	}
} // doEmail

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
	countfield.value = maxlimit - field.value.length;
}

function Campo(id){
	return document.getElementById(id);
}

