/////////////
// No Label //
//////////////
noLabel = {
	init: function(){
		$(".noLabel").each(function(){
			$(this).addClass("vazio");
			noLabel.buffer[$(this).attr("id")] = $(this).val();
			$(this).unbind('focus',noLabel.foco).unbind('blur',noLabel.desfoco).bind('focus',noLabel.foco).bind('blur',noLabel.desfoco);
		}).parents("form:eq(0)").unbind('submit',noLabel.formulario).bind('submit',noLabel.formulario);
	},
	
	buffer: {},
	
	foco: function(obj){
		obj = typeof($(obj).attr("id")) == "undefined" ? this : obj;
		if($(obj).hasClass("vazio")){
			if($(obj).is("textarea")){
				$(obj).html("");
			}else{
				$(obj).val("");
			}
			$(obj).removeClass("vazio");
		}
	},
	
	desfoco: function(){
		if($.trim($(this).val()) == ""){
			if($(this).is("textarea")){
				$(this).html(noLabel.buffer[$(this).attr("id")]);
			}else{
				$(this).val(noLabel.buffer[$(this).attr("id")]);
			}
			$(this).addClass("vazio");
		}
	},
	
	formulario: function(){
		$(".vazio",this).each(function(){
			noLabel.foco(this);
		});
		return true;
	}
}

$(document).ready( function(){
	noLabel.init();
	
/////////////////////////////
// Form Mask
////////////////////////////

	$('.cpf').mask('999.999.999-99');
	$('.data').mask('99/99/9999');
	$('.cep').mask('99999-999');
	$('.fone').mask('(99) 9999-9999');
	$('.cnpj').mask('99.999.999/9999-99');
	$('.money').maskMoney();
	$('.modelo').mask('9999/9999');
	
/////////////////////////////////////////////////
// troca Notícias destaques / Noticias listas
///////////////////////////////////////////////
	
	$('.linkNoticias').toggle(function(){
		$(this).text('Ver Notícias em Destaque');
		$('.destaqueNoticias').hide();
		$('.listaNoticias').show();
		
	},function(){
		$(this).text('Listar Todas as Notícias');
		$('.destaqueNoticias').show();
		$('.listaNoticias').hide();
	});
	
////////////////////////////////
// lista Destaques
//////////////////////////////

	$('.destaqueNoticias ul').each(function(){
		var obj = $(this);
		var qtd = $('li',obj).length;
		$(this).css('width',(qtd*178)+'px')
	});
	
//////////////////////////////////
// Adicionar Especializações
//////////////////////////////////////////////

	$('.addEspec').click(function(){
		var qt = $('.especializacao').length;
		var novaEspec = $('.especializacao:eq(0)').clone()
		
		$('input, select',novaEspec).each(function(){
			var newId = $(this).attr('id') + '_' + qt;
			var newName = $(this).attr('name') + '_' + qt;
			$(this).val('').attr({'id':newId, 'name':newName});
			$(this).parents('div.especializacao').addClass('novaEspecializacao');
			$(this).siblings('.excluirEspec').css('display','inline');
		});
		$('.quebraEspec').before(novaEspec);
	});
	
//Excluir Especialização
	$('.excluirEspec').live('click',function(){
		$(this).parents('.novaEspecializacao').remove();
	});
	
//////////////////////////////////
// Adicionar Experiencia Profissional
//////////////////////////////////////////////

	$('.addExper').click(function(){
		var qt = $('.experiencia').length;
		var novaExper = $('.experiencia:eq(0)').clone()
		
		$('input, select, textarea',novaExper).each(function(){
			var newId = $(this).attr('id') + '_' + qt;
			var newName = $(this).attr('name') + '_' + qt;
			$(this).val('').attr({'id':newId, 'name':newName});
			$(this).parents('div.experiencia').addClass('novaExperiencia');
			$(this).siblings('.excluirExper').css('display','inline');
		});
		$('.quebraExper').before(novaExper);
	});
	
//Excluir Especialização
	$('.excluirExper').live('click',function(){
		$(this).parents('.novaExperiencia').remove();
	});
	
});
