$(document).ready( function(){
	
	//DESTAQUES
	
		$('.chd_imagem')
		.after('<div id="chd_panel" class="chd_panel">')
		.cycle({ 
			fx:     'fade', 
			speed:  'slow', 
			timeout: 5000, 
			pager:  '#chd_panel' 
		});		
	
	//ABAS
		
		var artista_nome = $('h3').text();
		
		//verifica
		if( artista_nome == 'Nenê Trio' ){
			
			$('.cha_02').addClass('cha_ativo');
			$('.cha_bordinha').show().css({ 'left':'481px' });
			
		} else if ( artista_nome == 'Regra de Três' ){
			
			$('.cha_03').addClass('cha_ativo');
			$('.cha_bordinha').show().css({ 'left':'720px' });
			
		} else if ( artista_nome == 'Triálogo' ){
			
			$('.cha_04').addClass('cha_ativo');
			
		} else {
			
			$('.cha_01').addClass('cha_ativo');
			
		}
		
		$('.cha_div').hover( function(){

			var altura = $(this).outerHeight();
			
			if( $(this).hasClass('cha_ativo') == true ){
				
				//faz nada
				
			} else {

				//$('.cha_ativo').removeClass('cha_ativo');
			
			}
			
			if( altura == 91 ){
				
				//faz nada
				
			} else {
				
				$(this).css({ 'padding-bottom':'3px', 'margin-top':'0px' });
				
			}
			
		}, function(){
			
			$(this).css({ 'padding-bottom':'0px', 'margin-top':'3px' });
			
		});

	
	//ARTISTA
	
		//ABAS BIOGRAFIA E FOTOS
	
		$('.cln_a').click( function(){
			
			//se clicar no que já está ativo
			if( $(this).hasClass('cln_ativo') == true ){
				
				//não continua
				return false;
			
			}
			
			//tira classe ativo do antigo
			$('.cln_ativo').removeClass('cln_ativo');
			
			//coloca classe ativo no novo
			$(this).addClass('cln_ativo');
			
			//se tiver classe bio
			if( $(this).hasClass('cln_bio') == true ){
				
				//esconde fotos
				$('.clm_fotos').fadeOut(150);
				
				//mostra bio
				$('.clm_biografia').fadeIn(150);
				
			} else {
				
				//se tiver classe fotos
				
				//esconde bio
				$('.clm_biografia').fadeOut(150);
				
				//mostra fotos
				$('.clm_fotos').fadeIn(150);
			
			}
									
		});
		
		//GALERIA DE FOTOS
		
		//mostra imagem inicial
		$('.clmfc_div img').animate({ opacity : 1 });
		
		//estabelece o indice
		clmfful_a_index='0';
		
		//verifica os links da navegacao
		function verificaLinks(){
			
			var total = $('.clmfful_a').length-1;
			
			$('.clmfh_a').removeClass('clmfh_dst clmfh_prevdst clmfh_nextdst');
			
			if( clmfful_a_index == 0 ){
				
				//se for a primeira
				$('.clmfh_prev').addClass('clmfh_dst clmfh_prevdst');
			
			} else if ( clmfful_a_index == total ){
			
				//se for a última
				$('.clmfh_next').addClass('clmfh_dst clmfh_nextdst');
			
			} else {
			
				//faz nada
			
			}
			
		}
		
		//verifica se a foto está aparecendo na tela
		function verificaTop(){
		
			var scrolltop = $(window).scrollTop();
			var top = $('.clmf_header').offset().top;
			
			if( scrolltop > top ){
			
				$(window).scrollTop(top);
			
			}
		
		}
		
		//quando clica em uma imagem
		$('.clmfful_a').click( function(){
			
			var index = $(".clmfful_a").index(this);
			clmfful_a_index=index;
			
			verificaLinks();
			
			verificaTop();
			
			//pega src
			var src = $(this).find('img').attr('src');
			
			//quebra o src
			var src_split = src.split('_');
			
			//pega altura
			var altura = $('.clmfc_div').height();
			
			//atribui altura
			$('.clmfc_div').height(altura);
			
			//remove imagem
			$('.clmfc_div img').fadeOut(200).remove();
			
			//adiciona loading
			$('.clmfc_div').addClass('load');
			
			//adiciona nova imagem
			$('.clmfc_div').html('<img src="admin/uploads/fotos/foto_'+src_split[1]+'" />');
			
			//quando a imagem estiver pronta
			$('.clmfc_div img').load( function(){
				
				//pega nova altura
				var nova_altura = $('.clmfc_div').find('img').height();
				
				//adiciona nova altura
				//$('.clmfc_div').height(nova_altura+30);
				$('.clmfc_div').stop().animate({ 'height' : nova_altura+30 });
				
				//remove load
				$('.clmfc_div').removeClass('load');
				
				//mostra imagem
				$(this).animate({ opacity : 1 }, 200);
				
			});
			//$('.clmfc_div img').attr('src', 'admin/uploads/fotos/foto_'+src_split[1]);
						
			//pega descricao
			var descricao = $(this).attr('title');
			
			//atribui nova descricao
			$('.clmf_content p').html(descricao);
			
		});
		
		$('.clmfh_a').click( function(){
			
			var index = clmfful_a_index;
			
			//conta número de As
			var maximo = $('.clmfful_a').length-1;
			
			//se apertar no botão anterior
			if( $(this).hasClass('clmfh_prev') == true ){
				
				//se index for 0 não executa
				if( index == 0 ){
					return false;
				}
				
				index--;
				clmfful_a_index=index;
				
			} else {
			//se apertar no próximo	
			
				//se index for igual ao máximo não executa
				if( index == maximo ){
					return false;	
				}
				
				index++;
				clmfful_a_index=index;
			
			}
			
			verificaLinks();
			
			//pega src
			var src = $('.clmfful_a').eq(index).find('img').attr('src');
			
			//quebra o src
			var src_split = src.split('_');
			
			//pega altura
			var altura = $('.clmfc_div').height();
			
			//atribui altura
			$('.clmfc_div').height(altura);
			
			//remove imagem
			$('.clmfc_div img').fadeOut(200).remove();
			
			//adiciona loading
			$('.clmfc_div').addClass('load');
			
			//adiciona nova imagem
			$('.clmfc_div').html('<img src="admin/uploads/fotos/foto_'+src_split[1]+'" />');
			
			//quando a imagem estiver pronta
			$('.clmfc_div img').load( function(){
				
				//pega nova altura
				var nova_altura = $('.clmfc_div').find('img').height();
				
				//adiciona nova altura
				//$('.clmfc_div').height(nova_altura+30);
				$('.clmfc_div').stop().animate({ 'height' : nova_altura+30 });
				
				//remove load
				$('.clmfc_div').removeClass('load');
				
				//mostra imagem
				$(this).animate({ opacity : 1 }, 200);
				
			});			
			//$('.clmfc_div img').attr('src', 'admin/uploads/fotos/foto_'+src_split[1]);
			
			//pega descricao
			var descricao = $('.clmfful_a').eq(index).attr('title');
			
			//atribui nova descricao
			$('.clmf_content p').html(descricao);
			
			
		});
	
	// CONECTS
		
		//TWITTER
		/*
		getTwitters('insertTwitter', {
			id: 'borandabrasil', 
			count: 1, 
			withFriends: true, // currently disabled due to change in Twitter API
			enableLinks: true, 
			ignoreReplies: true,
			template: '<p class="ct_post">%text% <a href="http://twitter.com/%user_screen_name%/statuses/%id%/" class="ct_time" target="_blank">%time%</a></p><a href="http://www.twitter.com/%user_screen_name%" title="Siga %user_screen_name% no Twitter!" class="ct_autor" target="_blank">%user_name% <span>(%user_screen_name%)</span></a>'
		});   */
	
	//POPUPS
	
		//ENTER
		
		$('.pop_up').bind('keypress', function(e){
			var code = (e.keyCode ? e.keyCode : e.which);
			 if(code == 13) { //Enter keycode
			   $(this).find('.pop_footer').find('.bt01').eq(0).click();
			 }
		});
	
		//POP SUGESTÕES
		
		$('.wemail').click(function() { 
			$.blockUI({ message: $('#pop_sugestoes'), css: { width: '520px' } }); 
		});	
		
		//POP NEWSLETTER
		
		$('.pop_newsletter').click(function() { 
			$.blockUI({ message: $('#pop_newsletter'), css: { width: '520px' } }); 
		});
			
			//
			
			$('.crn_form input').bind('keyup keypress', function(){													
				var valor = $(this).val();
				$('.pop_news .pop_email input').val(valor);
			});
			
			//enviar newsletter
			
			$('.enviarNewsletter').click( function(){
				
				var sexo = '';
    
				if($('#masculino').attr('checked') == true){
					
					sexo = 1;
					
				}else{
					
					sexo = 0;
					
				}
				
				if($("#nome").val() == ''){
					
					alert("Informe o nome.");
					return false;
					
				}
				
				 if($("#email").val() == ''){
					
					alert("Informe o email.");
					return false;
					
				}
				
				if($("#email").val() != $("#confirma_email").val()){
					
					alert("E-mails não conferem.");
					return false;
					
				}
				
				$.post('admin/actions/newsletter_cadastrar.php',
					
					{nome:$('#nome').val(),
					nascimento:$('#nascimento').val(),
					sexo:sexo, 
					email:$('#email').val(),
					pais:$('#pais').val(),
					cep:$('#cep ').val()},
					
				function(data){
					
					if(data){
						
						alert("Cadastrado com sucesso");
						$.unblockUI();
						$("#name_new").val("Seu E-mail:");
						$('#pop_newsletter input').each( function(){
							$(this).val('');
						});
						
					}else{
						
						alert("Erro. Tente novamente.");
						
					}
												  
				});
				
			});
		
		//FECHAR POPUP
		
		$('.fecharPop').click( function(){
			$.unblockUI(); 
			return false;								
		});
	
	//META TAGS
	//alteraMeta();
		
});




