$(document).ready(function(){

	$('a[href^=http]').click( function() { window.open(this.href); return false; });
	
	$('#subMenus div.sub li:first-child').css('border-top','none');
	$('#subMenus div.sub li:last-child').css('border-bottom','none');
	
	$('[href=#validar]').click(function(){
		$(this).parents('form').find('.validar').validar({corborda : '#dfba30'});	
	})
	
	$('#rodape input').focusOnOut({corativo:'#e1e1e1',corinativo:'#b2b2b2'});
	
	$('#menu a.sub').hover(function(){
		id = $(this).attr('href');
		$(id).show();
	},function(){
		$(id).hide();
	})
	
	$('#subMenus .sub').hover(function(){
		$(this).show();
		$('#menu a[href=#'+$(this).attr('id')+']').addClass('ativo');
	},function(){
		$(this).hide();
		$('#menu a[href=#'+$(this).attr('id')+']').removeClass('ativo');
	})
	
	$('#topo a[href=#buscarap]').click(function(){
		$('#busca').toggle();
		$(this).toggleClass('ativo');
	})
	$('#busca').mouseleave(function(){$('#topo a[href=#buscarap]').toggleClass('ativo');})
	
	$('a.voltar').hover(function(){
		$(this).stop().animate({backgroundPosition:'1px 1px', paddingRight:'0'},250)
	},function(){
		$(this).stop().animate({backgroundPosition:'59px 1px', paddingRight:'14px'},250)
	})
	
	$("#rodape form").submit(function(e){
		e.preventDefault();
		cadastroExe();
	})
	
	$('#subMenus #se, #subMenus #sp').each(function(){
		padding = 10;
		id = $(this).attr('id');
		link = $('#menu a[href=#'+id+']');
		tamEleX = (link.width()) / 2;
		posEleX = link.position('#topo').left;
		widthEle = ($(this).width()) / 2;
		left = (tamEleX + posEleX) - widthEle + padding;
		//$(this).css('left',left)
	})
		
});

function cadastroExe(){
	valEmail = $('#rodape input[name=email]').val();
	if(valEmail != ''){
		
		$.ajax({
			type: 'post',
			data: 'email='+valEmail,
			url:'cadastroEmailExe.php',
			success: function(retorno){
				if(retorno == 2){
				$('#msgerro').empty().append('<p>Este e-mail j&aacute; est&aacute; cadastrado em nossa base de dados. Verifique e tente novamente.</p>')
				$('#erroo').slideDown();
				setTimeout("$('#erroo').slideUp()" , 5500)
			}
			if(retorno == 1){$('#rodape form').fadeOut(350, function(){ $('#rodape form').next().fadeIn(450)})}
			}
		})
	}else{
		$('#rodape input[name=email]').validar();
		}
}
