jQuery(document).ready(

	/*
	This function gets loaded when all the HTML, not including the portlets, is
	loaded.
	*/

	function() {
		// tablas de peso y edad ---------------------------------------------
		var lnkTablaPeso = jQuery('#bt-tabla-recien-nacido-nino').length > 0;
		var lnkVirtualAuth = jQuery('#virtual-auth a').length > 0;
		if ( lnkTablaPeso || lnkVirtualAuth ) {
			var modal = new ModalElement({
			   opacity:'0.5',
			   fixed:false
			});
			
			jQuery('#bt-tabla-recien-nacido-nino').click(function(){
				modal.showElement('#tabla-recien-nacido-nino');
			});
			jQuery('#bt-tabla-recien-nacido-nina').click(function(){
				modal.showElement('#tabla-recien-nacido-nina');
			});
			jQuery('#bt-tabla-ninos-nino').click(function(){
				modal.showElement('#tabla-ninos-nino');
			});
			jQuery('#bt-tabla-ninos-nina').click(function(){
				modal.showElement('#tabla-ninos-nina');
			});
			jQuery('#bt-tabla-sobrepeso-nino').click(function(){
				modal.showElement('#tabla-sobrepeso-nino');
			});
			jQuery('#bt-tabla-sobrepeso-nina').click(function(){
				modal.showElement('#tabla-sobrepeso-nina');
			});
			jQuery('.close').click(function(){
				modal.hide();
			});
			jQuery('#virtual-auth a').click(function(){
				modal.showElement('#virtual-auth-text');
			});
		}
		
		// calendario de embarazo -----------------------------------------
		jQuery('td.clave').hover(
	
			function(e){
				
				var that = jQuery(this);
				
				var cita = that.find('.cita');
				
				var leftTop = jQuery('.tabla').offset().left + jQuery('.tabla').width();
				
				var layerLeft = cita.offset().left + cita.width() - 4;
				
				var left = (that.width() / 2) - 40 + 'px';
				
				cita.css('margin-left', left);
				
				var top = -(cita.get(0).offsetHeight + 10);
				
				cita.css('margin-top', top + 'px');
				
				if (!jQuery.browser.msie) {
					if (layerLeft > leftTop) {
						cita.css({
							marginLeft: -(275 - that.width()) + 'px',
							backgroundPosition: 'right bottom'
						});
					}
				}
				else {
					var top = jQuery('.tabla').offset().top;
					cita.css({
						position:'fixed',
						left : ( jQuery(window).width() / 2 ) + 70,
						top : (top - cita.height() ) + 50,
						background:'none'
						//backgroundPosition: 'center bottom'
					});
				}
			}, 
			function(){
				var cita = jQuery(this).find('.cita');
				cita.css({
					marginLeft: '0',
					backgroundPosition: '22px bottom'
				});
			}
		);
		
		// grafica de desarrollo ---------------------------------------
		if (jQuery('#grafica-desarrollo h3.uno').length) {
		
			var uno = jQuery('#grafica-desarrollo h3.uno').html();
			var dos = jQuery('#grafica-desarrollo h3.dos').html();
			var tres = jQuery('#grafica-desarrollo h3.tres').html();
			var cuatro = jQuery('#grafica-desarrollo h3.cuatro').html();
			jQuery('#grafica-desarrollo h3 span').remove();
			
			jQuery('#content-gd').parent().append(uno);
			jQuery('#content-gd').parent().append(dos);
			jQuery('#content-gd').parent().append(tres);
			jQuery('#content-gd').parent().append(cuatro);
			jQuery('span.uno').css({
				position: 'absolute',
				top: '45px',
				left: '80px'
			});
			jQuery('span.dos').css({
				position: 'absolute',
				top: '297px',
				left: '80px'
			});
			jQuery('span.tres').css({
				position: 'absolute',
				top: '462px',
				left: '80px'
			});
			jQuery('span.cuatro').css({
				position: 'absolute',
				top: '625px',
				left: '80px'
			});
		}

	}
);

// grafica de desarrollo
function gotoValue(mes) {
	jQuery('#grafica-desarrollo ul li').css('color', '#666');
	
	//mes = jQuery("#amount span").text();
	position = mes * 30; 
	
	jQuery('#marker').animate( {
		left: position
	}, 1000, function(){
		
		jQuery('#grafica-desarrollo ul li.num'+mes).css('color', '#fff');
		
		var markerPos = Number(jQuery('#marker').css('left').slice(0, -2));
		var displayW = Number(jQuery('#content-gd').css('width').slice(0, -2));
		var tableW = Number(jQuery('#grafica-desarrollo').css('width').slice(0, -2));

		var moveTo = markerPos - (displayW/2);
		jQuery('#content-gd').scrollTo({ top:0, left:moveTo}, 800);
	});
}

