$.fn.x = function(n) {
	var result = null;
	
	this.each(
		function() {
			var o = this;
			
			if (n === undefined) {
				var x = 0;
				
				if (o.offsetParent) {
					while (o.offsetParent) {
						x += o.offsetLeft;
						o = o.offsetParent;
					}
				}
				
				if (result === null) {
					result = x;
				} else {
					result = Math.min(result, x);
				}
			
			} else {
				o.style.left = n + 'px';
			}
		}
	);
	
	return result;
};
			
$.fn.y = function(n) {
	var result = null;
	
	this.each(
		function() {
			var o = this;
		
			if (n === undefined) {
				var y = 0;
				
				if (o.offsetParent) {
					while (o.offsetParent) {
						y += o.offsetTop;
						o = o.offsetParent;
					}
				}
				
				if (result === null) {
					result = y;
				} else {
					result = Math.min(result, y);
				}
			} else {
				o.style.top = n + 'px';
			}
		}
	);
	
	return result;
};





$(
	function() {	
		$("#header .menu-primario ul li a.ativo").each(
			function () {	
				$("#header .menu-primario .menu-primario-linha").animate({
					width: $(this).width(),
					marginLeft: $(this).parent().x() - $(this).parent().parent().x()
				}, 1000);
			}
		);
		
		$("#header .menu-primario ul li a").mouseenter (
			function () {
				$("#header .menu-primario .menu-primario-linha").stop();
				$("#header .menu-primario .menu-primario-linha").animate({
					width: $(this).width(),
					marginLeft: $(this).parent().x() - $(this).parent().parent().x()
				}, 1000);
			}
		);
		
		$("#header .menu-primario ul").mouseleave (
			function () {
				menuAtivo = $("#header .menu-primario ul li a.ativo");
				
				if (menuAtivo.parent().x()) {
					$("#header .menu-primario .menu-primario-linha").stop();
					$("#header .menu-primario .menu-primario-linha").animate({
						width: menuAtivo.width(),
						marginLeft: menuAtivo.parent().x() - menuAtivo.parent().parent().x()
					}, 1000);
				}
			}
		);
		
		

		$("input[type=file]").filestyle({ 
			image: form_inputFile_botao,
			imageheight : 24,
			imagewidth : 64,
			width : 100
		}); 
	}
);


var booExibirBotaoExcluir = false;

function exibir_registro_excluir(strID, booExcluir) {
	$(strID + ' > .registro .btn_excluir').css('display', '');
	$(strID + ' > .nenhum_registro').css('display', 'none');
	
	if ((!booExcluir && $(strID + ' > .registro').size() == 1) || (booExcluir && $(strID + ' > .registro').size() <= 2)) {
		if (!booExibirBotaoExcluir) {
			$(strID + ' > .registro .btn_excluir').css('display', 'none');
		}
	}
	
	if ((!booExcluir && $(strID + ' > .registro').size() == 0) || (booExcluir && $(strID + ' > .registro').size() <= 1)) {
		$(strID + ' > .nenhum_registro').css('display', '');
	}
}

function duplicar_registro(strID,strURL){
	$.post(strURL,
		function(data) {
			$(strID).append(data);
			$(strID + ' > .registro:last-child').css('display', 'none').slideDown('normal');
			exibir_registro_excluir(strID, false);
		}
	);
}

function remover_registro(strID, strID_registro) {
	exibir_registro_excluir(strID, true);
	
	$(strID_registro).slideUp('normal',
		function() {
			$(this).remove();
		}
	);
}



function profissional_segmento(numSegmento, strID) {
	if (!(numSegmento == '') && numSegmento == 0) {
		$(strID + ' div.segmento').slideDown('normal');
	} else {
		$(strID + ' div.segmento').slideUp('normal');
	}
}

function forma_contato(numFormaContato, strID) {
	if (!(numFormaContato == '') && numFormaContato == 0) {
		$(strID + ' div.forma-contato').slideDown('normal');
	} else {
		$(strID + ' div.forma-contato').slideUp('normal');
	}
}





var arrAtributos = new Array();

function alterarAtributo(pStrID,pStrAtributo,pStrValorPadrao,pStrNovoValor,pBooForcarAlteracao) {
	if ($("#" + pStrID) && pStrAtributo) {		
		if (!arrAtributos[pStrID]) arrAtributos[pStrID] = new Array();
		if (!arrAtributos[pStrID][pStrAtributo]) arrAtributos[pStrID][pStrAtributo] = new Array();
		
		if (!arrAtributos[pStrID][pStrAtributo][2] || pBooForcarAlteracao) {
			arrAtributos[pStrID][pStrAtributo][0]	= $("#" + pStrID).attr(pStrAtributo);
			
			if (pStrValorPadrao) arrAtributos[pStrID][pStrAtributo][0] = pStrValorPadrao;
					
			arrAtributos[pStrID][pStrAtributo][1]	= pStrNovoValor;
			arrAtributos[pStrID][pStrAtributo][2]	= true;
			
			if ($("#" + pStrID).attr(pStrAtributo) == pStrValorPadrao) $("#" + pStrID).attr(pStrAtributo,pStrNovoValor);
		}
	}
}

function restaurarAtributo(pStrID,pStrAtributo,pBooForcarRestauracao,pBooAceitarNull) {	
	if ($("#" + pStrID) && pStrAtributo) {
		if (arrAtributos[pStrID]) {
			if (arrAtributos[pStrID][pStrAtributo]) {
				var strValor = $("#" + pStrID).attr(pStrAtributo);
				
				if ((arrAtributos[pStrID][pStrAtributo][2] && ((!strValor && !pBooAceitarNull) || strValor == arrAtributos[pStrID][pStrAtributo][1])) || pBooForcarRestauracao) {
					$("#" + pStrID).attr(pStrAtributo,arrAtributos[pStrID][pStrAtributo][0]);
					
					arrAtributos[pStrID][pStrAtributo][0]	= "";
					arrAtributos[pStrID][pStrAtributo][1]	= "";
					arrAtributos[pStrID][pStrAtributo][2]	= false;
				}
			}
		}
	}
}