//===============================LOADING SUBMENU======================================
function abre(este)
{
	if(o(este).style.display == "none")
	{
		o(este).style.display = "block";
	}
	else
	{
		o(este).style.display = "block";
	}
}
function fecha(este)
{
	if(o(este).style.display == "block")
	{
		o(este).style.display = "none";
	}
	else
	{
		o(este).style.display = "none";
	}
}

//===============================FUNÇÕES JQUERY======================================
	var moving = false;
	var n=0;
	
    $(document).ready(function(){
	
		//prettyPhoto
		$("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_square'});
		
		if(document.getElementById("legenda"))
		document.getElementById("legenda").innerHTML = $("#fotos_interna ul li img:eq(0)").attr('alt');
		
		$(window).load(function(){				   
			$("#fotos_interna ul").height($("#fotos_interna ul li:eq(0)").height());
			
		});
		
		var n=0;
		//next 		
		$(".next").click(function(){
			
			if(!moving)
			{
				
				ulw = $(this).parent().find("ul").width();
				liw = $(this).parent().find("ul li").width();
				minleft = liw-ulw;

				//se a posição for maior que o total o botão trava
				if(parseInt($(this).parent().find("ul").css("left"))>minleft)
				{
					moving = true;
					n++;
					lih = $(this).parent().find("ul li:eq("+n+")").height();
					document.getElementById("legenda").innerHTML = $(this).parent().find("ul li img:eq("+n+")").attr('alt');
					
					$(this).parent().find("ul").animate({left: '-='+liw,height: lih}, 1000, '', function(){ moving = false;});
					
				}

			}
		});
		
	    //prev
		$(".prev").click(function(){
						
			if(!moving)
			{

				//se a posição for menor que 0 o botão trava
				if(parseInt($(this).parent().find("ul").css("left"))<0)
				{	
					moving = true;
					n--;
					lih = $(this).parent().find("ul li:eq("+n+")").height();
					document.getElementById("legenda").innerHTML = $(this).parent().find("ul li img:eq("+n+")").attr('alt');
					
					$(this).parent().find("ul").animate({left: '+='+liw,height: lih}, 1000, '', function(){ moving = false; });

				}
			}
		});
		
		//forms
		$("#fazer_comentario").click(function(){
			$("#form_depoimento").slideToggle("slow");
		});
		
		$("#indicar_news").click(function(){
			$("#form_indicar_news").slideToggle("slow");
		});
		
		$("#area_login").click(function(){
			$("#fazer_login").fadeIn("fast");
		});
		
		$("#fechar_resposta").click(function(){
			$("#resposta_form").fadeOut("fast");
		});
		
		$("#fechar_evento").click(function(){
			$("#evento_box").fadeOut("fast");
		});
		
		$("#fechar").click(function(){
			$("#fazer_login").fadeOut("fast");
		});
		
		$("#esqueci_lnk").click(function(){
			$("#esqueci").slideToggle("slow");
		});
		
		$("#titulo_mais").click(function(){
			$("#mais_info").slideToggle("slow");
		});
		
		$("#titulo_interesses").click(function(){
			$("#interesses").slideToggle("slow");
		});
		
		$("#novo_topico").click(function(){
			$("#form_novo_topico").slideToggle("slow");
		});
		
		//máscaras
		$(".data").mask("99/99/9999");
		$(".tel").mask("9999-9999");
		
		//agenda
		$.datepicker.regional['pt-BR'] = {
			closeText: 'Fechar',
			prevText: '&#x3c;Anterior',
			nextText: 'Pr&oacute;ximo&#x3e;',
			currentText: 'Hoje',
			monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho',
			'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
			monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun',
			'Jul','Ago','Set','Out','Nov','Dez'],
			dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'],
			dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
			dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
			weekHeader: 'Sm',
			dateFormat: 'dd/mm/yy',
			firstDay: 0,
			isRTL: false,
			showMonthAfterYear: false,
			yearSuffix: ''};
		$.datepicker.setDefaults($.datepicker.regional['pt-BR']);
	
		$.ajax({
		  url: 'envios/dates.php',
		  dataType: "json",
		  success: function(data) 
		  {
			dateList = data;	

			$("#datepicker").datepicker({ //ADICIONAMOS A FUNÇÃO PELO ID DO CONTAINER
			
			beforeShowDay: function(dateToShow){ 
					  
			return [($.inArray($.datepicker.formatDate('dd/mm/yy', dateToShow),dateList) >= 0), ""];  		//FORMATA A DATA A E PEGA OS DIAS A SEREM MOSTRADOS
			},
			
			onSelect: function(dateText, inst) 
			{ 
				getXmlAjax('xml/agenda.xml.php?dt='+dateText,"exibeEvento","","");
			}
			
			});
			
		  }
		});
		
		//Personaliza o tamanho das fontes
		$("#box_font a").click(function(){
										
			var font=$("#txt_noticia").css('font-size');
			var acao=$(this).attr('id'); 
			var fonte = font.replace("px","");
			
			if(acao=="maior")
			{
				if(fonte<16)
				{
					var tamanho = parseInt(fonte)+1; 
					$("#txt_noticia").css('font-size',tamanho+'px'); 
				}
			}  
			
			if(acao=="menor")
			{  
				if(fonte>12)
				{  
					var tamanho = fonte-1;  
					$("#txt_noticia").css('font-size',tamanho+'px');  
				}
			}
		});
		
    });	
	
	//Imprimir páginas
function Imprimir(){
	if (window.print) {
		window.print();
	}
	else {
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGTH=0 CLASSID="CLSID:8856F961-340A-11D0-A96B00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	WebBrowser1.ExecWB(6, 2);
	WebBrowser1.outerHTML = " ";
	}
}

