//submenu

var contando = false;
var contando2 = false;



//var total = 3;
var _TOTALMENU = 6;
function mostraSubmenu(qual){
	fechaTodos();
	
	var menu = document.getElementById("sub"+qual);
	var link0 = document.getElementById("link"+qual);
	
	menu.style.visibility = "inherit";
	link0.style.color = "#FFCC00";

	if(contando){
		clearTimeout(tempo);
		contando = false;
	}
}

/* ISO to UTF8*/
function iso2utf8(string) {	
	var string = string.replace(/\r\n/g,"\n");
	var utftext = "";
	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		} else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		} else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}


function mostraLogin(){
	var login = document.getElementById("login_hajime");
	login.style.display = "block";
}

function fechaLogin(){
	var login = document.getElementById("login_hajime");
	login.style.display = "none";
}


function tempoFechaSubmenu(qual){
	tempo = setTimeout("fechaSubmenu("+qual+")", 500);
	contando = true;
	
	}
function fechaSubmenu(qual){
	var menu = document.getElementById("sub"+qual);
	var link_ = document.getElementById("link"+qual);
	link_.style.color = "#FFF";
	clearTimeout(tempo);
	contando = false;
	menu.style.visibility = "hidden";
}
	
function fechaTodos(){
	for(i=1;i<=_TOTALMENU;i++){
		var submenu = document.getElementById("sub"+i);
		var link_ = document.getElementById("link"+i);
		if(submenu.style.visibility!= "hidden")
		submenu.style.visibility = "hidden";
		link_.style.color = "#FFF";
	}
}

function mostraConteudo(qual,total){
	fechaAbas(total);
	
	var cont = document.getElementById("conteudo"+qual);
	cont.style.display = "";
	var aba = document.getElementById("aba"+qual);
	aba.style.background = "url(imagens/fundo_aba.jpg)";
	aba.style.width="119px";
	aba.style.fontWeight="600";
	}
	
function fechaAbas(total){
	for(i=1;i<=total;i++){
		var cont = document.getElementById("conteudo"+i);
		cont.style.display = "none";
		var aba = document.getElementById("aba"+i);
		aba.style.background = "";
		aba.style.width="auto";
		aba.style.fontWeight="100";
	}
}
	
function getCalendario(direcao,mes,ano) {
	
	$.ajax({
		   type: "POST",
		   url: "index.php?acao=calendario&modulo=principal",
		   data: "ano="+ano+"&mes="+mes+"&direcao="+direcao,
		   success: function(resposta){
			 			jQuery("#calendario").html(resposta);
						jQuery('.laranja').bt( {
								fill: '#FFF',
								cornerRadius: 10,
								strokeWidth: 0,
								shadow: true,
								shadowOffsetX: 3,
								shadowOffsetY: 3,
								shadowBlur: 8,
								shadowColor: 'rgba(0,0,0,.9)',
								shadowOverlap: false,
								noShadowOpts: {strokeStyle: '#999', strokeWidth: 2},
								positions: ['left', 'top']
							  });
					}
 		});

}

function iniciaCalendario() {
	
	$.ajax({
		   type: "POST",
		   url: "index.php?acao=calendario&modulo=principal",
		   data: "",
		   before: function() {
					$("#calendario").html("Carregando...");   
		   },
		   success: function(resposta){
			   			$("#calendario").html(resposta);
						$('.laranja').bt( {
								fill: '#FFF',
								cornerRadius: 10,
								strokeWidth: 0,
								shadow: true,
								shadowOffsetX: 3,
								shadowOffsetY: 3,
								shadowBlur: 8,
								shadowColor: 'rgba(0,0,0,.9)',
								shadowOverlap: false,
								noShadowOpts: {strokeStyle: '#999', strokeWidth: 2},
								positions: ['left', 'top']
							  });
					}
 		});

}

function contaClique(idBanner) {
	$.ajax({
				   type: "POST",
				   url: "index.php?acao=clique&modulo=principal",
				   data: "ID="+idBanner,
				   beforeSend: function() {
		
				   },
				   success: function(resposta){
				   }
								
	});	
}
function enviaNewsletter() {
	var nome = document.forms['newsletter'].nome.value;
	var email = document.forms['newsletter'].email.value;
	if (nome == "") {
		$.jGrowl('Favor digitar o seu nome!');	
	} else if (email == "" || !checaEmail(email)) {
		$.jGrowl('Favor verificar o email digitado!');	
	} else {
		$.ajax({
			   type: "POST",
			   url: "index.php?acao=cadastranewsletter&modulo=principal",
			   data: "nome="+nome+"&email="+email,
			   beforeSend: function() {
						jQuery.jGrowl("Aguarde....",{life:800});
	
			   },
			   success: function(resposta){
							jQuery.jGrowl(resposta);
	
			   }
							
			});
	}

}

function enviaEnquete() {
	var opcao = document.forms['ENQUETE'].ID_PERGUNTA_ENQUETE;
	var opcaoSelecionada = null;
	for(var i=0;i<opcao.length;i++) {
		if (opcao[i].checked) {
			var opcaoSelecionada = opcao[i].value;
		}
	}
	if (opcaoSelecionada != null) {
		$.ajax({
				   type: "POST",
				   url: "index.php?acao=votarenquete&modulo=principal",
				   data: "ID_PERGUNTA="+opcaoSelecionada,
				   beforeSend: function() {
							$.jGrowl("Aguarde....",{life:800});
		
				   },
				   success: function(resposta){
								$.jGrowl(resposta);
		
				   }
								
				});
	}
}


///destaque
var _DESTAQUES = 4;
var _NUMEROVIDEOSCANALCBJ = 4;
var _INICIODESTAQUE = 1;
var _INICIONUMEROVIDEOSCANALCBJ = 1;

var _DESTAQUEATUAL = _INICIODESTAQUE;
var _TIMELOOP = null;
var _TIMELOOPCANALCBJ = null;

var _VIDEOCANALCBJATUAL = _INICIONUMEROVIDEOSCANALCBJ;


function mostraDestaque(qual){
	fechaDestaques();
	var preview = document.getElementById("preview"+qual);
	preview.style.display = "block";
}

function marcaDestaque(qual) {
	var linkS = document.getElementById("link"+qual);
	linkS.className = "marcanumero";
}

function fechaDestaque(qual){
	var preview = document.getElementById("preview"+qual);
	
	preview.style.display = "none";
}

function fechaDestaques(){
	if(contando2){
		clearTimeout(tempo2);
		contando2 = false;
		}
	for(i=1;i<=_DESTAQUES;i++){
		var preview = document.getElementById("preview"+i);
		preview.style.display = "none";
	}
}

function marcaFoto(qual) {
	fechaFotos();
	document.getElementById("foto"+qual).style.display = "block";
	document.getElementById("tarja"+qual).style.display = "block";
	document.getElementById("preview"+qual).style.display = 'none';
	
	clearInterval(_TIMELOOP);	

}

function abreFoto(qual){
		fechaFotos();
		var foto = document.getElementById("foto"+qual);
		var tarja = document.getElementById("tarja"+qual);
		var preview = document.getElementById("preview"+qual);
		preview.style.display = "none";
		tarja.style.display = "block";
		foto.style.display = "block";
}

function fechaFotos(){
	for(i=1;i<=_DESTAQUES;i++){
		var foto = document.getElementById("foto"+i);
		var tarja = document.getElementById("tarja"+i);
		foto.style.display = "none";
		tarja.style.display = "none";
	}
}
function tempoFechaPreview(qual){
	var contando2 = true;
	tempo2 = setTimeout("fechaDestaque("+qual+")", 500);
	}


function muda(mDest) {
	
	abreFoto(mDest);
	marcaDestaque(mDest);
	
	if (_DESTAQUEATUAL == _DESTAQUES) {
		_DESTAQUEATUAL = _INICIODESTAQUE;
	} else {
		_DESTAQUEATUAL++;
	}
}	


function marcaCanalCbj(mDest) {
	fechaTodosCanalCbj();
	document.getElementById("imagem_video_"+mDest).style.display = 'block';
	document.getElementById("legenda_video_"+mDest).style.display = 'block';
	document.getElementById("marcador_video_"+mDest).className = 'seletor_ativo';

	clearInterval(_TIMECANALCBJ);	

}

function fechaTodosCanalCbj() {
	for(i=1;i<=_NUMEROVIDEOSCANALCBJ;i++){
			document.getElementById("marcador_video_"+i).className = 'seletor_inativo';
			document.getElementById("imagem_video_"+i).style.display = "none";;
			document.getElementById("legenda_video_"+i).style.display = "none";
	}	
}

function mostraVideo(mDest) {

	for(i=1;i<=_NUMEROVIDEOSCANALCBJ;i++){
			document.getElementById("marcador_video_"+i).className = 'seletor_inativo';
			document.getElementById("imagem_video_"+i).style.display = "none";;
			document.getElementById("legenda_video_"+i).style.display = "none";
	}
	document.getElementById("imagem_video_"+mDest).style.display = 'block';
	document.getElementById("legenda_video_"+mDest).style.display = 'block';
	document.getElementById("marcador_video_"+mDest).className = 'seletor_ativo';
}

function flipCanalCbj(mDest) {
	mostraVideo(mDest);
	if (_VIDEOCANALCBJATUAL == _NUMEROVIDEOSCANALCBJ) {
		_VIDEOCANALCBJATUAL = _INICIONUMEROVIDEOSCANALCBJ;
	} else {
		_VIDEOCANALCBJATUAL++;
	}
}

function tempo(){
    _TIMELOOP = setInterval("muda(_DESTAQUEATUAL)",4000);
}

function executarFlipCanalCbj(){
    _TIMECANALCBJ = setInterval("flipCanalCbj(_VIDEOCANALCBJATUAL)",4000);
}

function ondestaque(x,legenda,link){ // ex p1 ou p2, etc..
   d = x.substring(2,1); // 1 ou 2 ou 3 ou 4 ou 5 ou 6
   tmp = false;
   clearInterval(_timeLoop);
   muda(d);
}

function enviarOrkut(titulo, subtitulo, link, imgParentSelector){
    var params = {};
    params[google.orkut.share.Field.TITLE] = titulo;
    params[google.orkut.share.Field.DESTINATION_URL] = link;
    imgs = [];
    $( imgParentSelector+' img').each(function() {
        imgs.push($(this).attr('src'));
    });
    params[google.orkut.share.Field.CONTENT] = subtitulo;
    params[google.orkut.share.Field.THUMBNAIL] = imgs;
    var connection = new google.orkut.share.Connection(params);
    connection.send('orkut.com', {}); 
}

function buscaTermo() {
	document.forms['busca_termo'].action = '?acao=busca&modulo=busca';
	document.forms['busca_termo'].submit();
	
}


function getPeso(classeId,pesosSelecionados,modulo,idConteiner) {

	$.ajax({
		   type: "POST",
		   url: "index.php?acao=getpeso&classe="+classeId+"&modulo="+modulo,
		   data: "pesos="+pesosSelecionados,
		   success: function(resposta){
			 			$('#'+idConteiner).html(resposta);
					}
						
 		});
}

function getClasseSelecaoBrasileira(classeId) {
	location.href = "?acao=selecaobrasileira&modulo=judonacional&classe="+classeId;
}



window.onload = function() {
	f = document.forms[0];
	if (document.getElementById('dv_pesos_selecaobrasileira') != null) {
		getPeso(f.pesosselecionados.value,'selecaobrasileira','dv_pesos_selecaobrasileiro');
	}
	if (document.getElementById('calendario') != null) {
		iniciaCalendario();
		tempo();
	}
	
	if (document.getElementById('canal_cbj') != null) {
		executarFlipCanalCbj();
		
		$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});

	}

}

			   

//fim submenu
