//-----------------------------------  BANNER FLOAT HOME.   --------------------------------

$(document).ready(function() {

    var viewportwidth;
    var viewportheight;
    
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
          viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
    else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
           viewportheight = document.documentElement.clientHeight
    }

    // older versions of IE
    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
           viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
	
	$("a#esconde").fancybox({
	    'autoDimensions'    : false,
	    'width'             : viewportwidth-18,
		'height'			: viewportheight,
		'padding'           : 0,
		'margin'            : 0,
		'autoScale'			: false,
		'overlayShow'		: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'              : 'swf',
		'showCloseButton'   : false,
		'enableEscapeButton': true,
		'wmode'				: 'transparent'
	});
});
/**/

//-----------------------------------  Setando o tamanhanho das imagens da matérias.   --------------------------------
/*
$(function()
	{
		$('#imgDestaque').attr
		(				   
		   {height:"88", width:"98"} 			   
		)
					
	}
);
*/

//This code will start with a z-index of 1000, and decrement the z-index for each DIV element of the page by 10, giving the 
//first DIV a z-index of 1000, the second, 990, the third 980, and so on.


/*$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});*/

/*
$(document).ready(function(){
						   
	$('.dataAtualiza').html("Data de atualiza&ccedil;&atilde;o: 25/03/2009")
	   
	// Inserindo titulos nas paginas se acordo oom a seção
	var titulo = document.title
	var novo_titulo = $('#conteudo_internas').attr('title');
	document.title = novo_titulo + " - " +titulo;
}); 
*/


		/*jQuery(function(){
			//jQuery('ul.sf-menu').superfish();
		});*/
		
//-----------------------------------  Função que aumenta e diminui as fontes dos site   --------------------------------		
		
		$(document).ready(function(){
								   
		      
			   $('#font_maior').click(function(){
				  $('#conteudo_internas,#conteudo,h2,.Disclaimer').addClass('aumenta_fonte')
				  $('#conteudo_internas,#conteudo,h2,.Disclaimer').removeClass('diminui_fonte')
			   });
			   
			   $('#font_menor').click(function(){
				  $('#conteudo_internas,#conteudo,h2,.Disclaimer').removeClass('aumenta_fonte')
				  $('#conteudo_internas,#conteudo,h2,.Disclaimer').addClass('diminui_fonte')
			   });
		
		
		
		});


//-----------------------------------  Menu Acordeon da página de DIABETES   --------------------------------

function initMenu() {
	  $('#menu ul').hide(); // para transformar o Menu em Acordeon novamente descomente esta linha 
	  //$('#menu ul:first').show();
	  $('#menu li a').click( 
			function() 
		    {
				var checkElement = $(this).next();
				  if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				  return false;
				  }
					  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
						$('#menu ul:visible').slideUp('normal');
						checkElement.slideDown('normal');
						return false;
						}
			}
	  );
}
  
  


//-----------------------------------  Funções que ativa os menus nas seções correspondentes   --------------------------------

$(document).ready(function(){
            
			
			$('.menu_gente').find('a').each(function(){
				if( location.href.indexOf(this.href) != -1) {
				$(this).wrapInner("<div id='menu_gente_ativo_2'></div>");
				}
			});
			
			$('#menu_servicos').find('a').each(function(){
				if( location.href.indexOf(this.href) != -1) {
				$(this).wrapInner("<div id='menu_servicos_ativo'></div>");
				}
			});
	
});



//-----------------------------------  Modal para links externos         --------------------------------

$(document).ready(function () {
	$('a.confirm').click(function (e) {
		e.preventDefault();
		
		$(this).attr({ id:"link_externo"});

		confirm("Voc&ecirc; est&aacute deixando o site Diabetes. N&oacute;s Cuidamos.", function () {
			window.open($('#link_externo').attr('href'))
			location.reload(true)
		});
	});
});


function confirm(message, callback) {
	$('#confirm').modal({
		close:false,
		position: ["20%",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			dialog.data.find('.message').append(message);

			dialog.data.find('.yes').click(function () {
				if ($.isFunction(callback)) {
					callback.apply();
				}
				$.modal.close();
			});
		}
	});
}



//url = url.substring(url.lastIndexOf("/")+1,url.indexOf("?"));
//alert(id_menu)
//var url = location.href;



//-----------------------------------  Altedando a cor dos BCTs de acordo com a seção        --------------------------------
 

$(document).ready(function(){

	var class_menu = $('#menu_servicos').attr('class')
	var id_menu = $('#menu_servicos').attr('id')
	
	if (class_menu == "menu_gente")
	{
	   $('#bct_cont').addClass('LinkAzul_2')	
	}
	
	if (id_menu == "menu_servicos")
	{
	   $('#bct_cont').addClass('LinkAzul')	
	}

});





/*
 * SimpleModal 1.2 - jQuery Plugin
 * http://www.ericmmartin.com/projects/simplemodal/
 * Copyright (c) 2008 Eric Martin
 * Dual licensed under the MIT and GPL licenses
 * Revision: $Id: jquery.simplemodal.js 166 2008-12-04 16:54:04Z emartin24 $
 */
(function($){var ie6=$.browser.msie&&parseInt($.browser.version)==6&&!window['XMLHttpRequest'],ieQuirks=$.browser.msie&&!$.boxModel,w=[];$.modal=function(data,options){return $.modal.impl.init(data,options);};$.modal.close=function(){$.modal.impl.close();};$.fn.modal=function(options){return $.modal.impl.init(this,options);};$.modal.defaults={iframe:true,opacity:70,overlayId:'simplemodal-overlay',overlayCss:{},containerId:'simplemodal-container',containerCss:{},dataCss:{},zIndex:1000,close:true,closeHTML:'<a class="modalCloseImg" title="Close"></a>',closeClass:'simplemodal-close',position:null,persist:false,onOpen:null,onShow:null,onClose:null};$.modal.impl={opts:null,dialog:{},init:function(data,options){if(this.dialog.data){return false;}this.opts=$.extend({},$.modal.defaults,options);this.zIndex=this.opts.zIndex;this.occb=false;if(typeof data=='object'){data=data instanceof jQuery?data:$(data);if(data.parent().parent().size()>0){this.dialog.parentNode=data.parent();if(!this.opts.persist){this.dialog.orig=data.clone(true);}}}else if(typeof data=='string'||typeof data=='number'){data=$('<div/>').html(data);}else{alert('SimpleModal Error: Unsupported data type: '+typeof data);return false;}this.dialog.data=data.addClass('simplemodal-data').css(this.opts.dataCss);data=null;this.create();this.open();if($.isFunction(this.opts.onShow)){this.opts.onShow.apply(this,[this.dialog]);}return this;},create:function(){w=this.getDimensions();if(this.opts.iframe||ie6){this.dialog.iframe=$('<iframe src="javascript:false;"/>').css($.extend(this.opts.iframeCss,{display:'none',opacity:0,position:'fixed',height:w[0],width:w[1],zIndex:this.opts.zIndex,top:0,left:0})).appendTo('body');}this.dialog.overlay=$('<div/>').attr('id',this.opts.overlayId).addClass('simplemodal-overlay').css($.extend(this.opts.overlayCss,{display:'none',opacity:this.opts.opacity/100,height:w[0],width:w[1],position:'fixed',left:0,top:0,zIndex:this.opts.zIndex+1})).appendTo('body');this.dialog.container=$('<div/>').attr('id',this.opts.containerId).addClass('simplemodal-container').css($.extend(this.opts.containerCss,{display:'none',position:'fixed',zIndex:this.opts.zIndex+2})).append(this.opts.close?$(this.opts.closeHTML).addClass(this.opts.closeClass):'').appendTo('body');this.setPosition();if(ie6||ieQuirks){this.fixIE();}this.dialog.container.append(this.dialog.data.hide());},bindEvents:function(){var self=this;$('.'+this.opts.closeClass).bind('click.simplemodal',function(e){e.preventDefault();self.close();});$(window).bind('resize.simplemodal',function(){w=self.getDimensions();self.setPosition();if(!ie6){self.dialog.iframe.css({height:w[0],width:w[1]});self.dialog.overlay.css({height:w[0],width:w[1]});}});},unbindEvents:function(){$('.'+this.opts.closeClass).unbind('click.simplemodal');$(window).unbind('resize.simplemodal');},fixIE:function(){$.each([this.dialog.iframe,this.dialog.overlay,this.dialog.container],function(i,el){var s=el[0].style;s.position='absolute';if(i<2){s.setExpression('height','document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + "px"');s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"');}else{s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (t = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');}});},getDimensions:function(){var el=$(window);var h=$.browser.opera&&$.browser.version>'9.5'&&$.fn.jquery<='1.2.6'?document.documentElement['clientHeight']:el.height();return[h,el.width()];},setPosition:function(){var top=0,left=0,hCenter=(w[0]/2)-(this.dialog.container.height()/2),vCenter=(w[1]/2)-(this.dialog.container.width()/2);if(this.opts.position&&this.opts.position.constructor==Array){top+=this.opts.position[0]||hCenter;left+=this.opts.position[1]||vCenter;}else{top+=hCenter;left+=vCenter;}this.dialog.container.css({left:left,top:top});},open:function(){if(this.dialog.iframe){this.dialog.iframe.show();}if($.isFunction(this.opts.onOpen)){this.opts.onOpen.apply(this,[this.dialog]);}else{this.dialog.overlay.show();this.dialog.container.show();this.dialog.data.show();}this.bindEvents();},close:function(){if(!this.dialog.data){return false;}if($.isFunction(this.opts.onClose)&&!this.occb){this.occb=true;this.opts.onClose.apply(this,[this.dialog]);}else{if(this.dialog.parentNode){if(this.opts.persist){this.dialog.data.hide().appendTo(this.dialog.parentNode);}else{this.dialog.data.remove();this.dialog.orig.appendTo(this.dialog.parentNode);}}else{this.dialog.data.remove();}this.dialog.container.remove();this.dialog.overlay.remove();if(this.dialog.iframe){this.dialog.iframe.remove();}this.dialog={};}this.unbindEvents();}};})(jQuery);
/*-------------    FIM confirm    --------------------------------*/

function calculaIMC()
{
	pesoValueIMC = document.getElementById("imc_peso").value.replace(",",".").replace(/^\s+|\s+$/g, '');	
	alturaValueIMC = document.getElementById("imc_altura").value.replace(",",".").replace(/^\s+|\s+$/g, '');

	if (isNaN(pesoValueIMC) || isNaN(alturaValueIMC) || pesoValueIMC == "" || alturaValueIMC == "")
	{
		alert('Preencha os campos com valores numéricos.');
		document.getElementById("formIMC").reset();
		document.getElementById("imc_peso").focus();
		return;
	}

	valueIMC = pesoValueIMC / (alturaValueIMC * alturaValueIMC);
	document.getElementById("imc_msg").innerHTML = 'IMC: ' + valueIMC.toFixed(2).replace(".",",");
	
	if (valueIMC >= 40) document.getElementById("imc_msg").style.color = "#FF0000";
	else if (valueIMC < 18.5 || valueIMC >= 25) document.getElementById("imc_msg").style.color = "#FF9900";
	else document.getElementById("imc_msg").style.color = "#009900";	
}
