 cookie = function(name, value, options) {
 if (typeof value != 'undefined') { // name and value given, set cookie
 options = options || {};
 if (value === null) {
 value = '';
 options.expires = -1;
 }
 var expires = '';
 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
 var date;
 if (typeof options.expires == 'number') {
 date = new Date();
 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
 } else {
 date = options.expires;
 }
 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
 }
 // CAUTION: Needed to parenthesize options.path and options.domain
 // in the following expressions, otherwise they evaluate to undefined
 // in the packed version for some reason...
 var path = options.path ? '; path=' + (options.path) : '';
 var domain = options.domain ? '; domain=' + (options.domain) : '';
 var secure = options.secure ? '; secure' : '';
 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
 } else { // only name given, get cookie
 var cookieValue = null;
 if (document.cookie && document.cookie != '') {
 var cookies = document.cookie.split(';');
 for (var i = 0; i < cookies.length; i++) {
 var cookie = jQuery.trim(cookies[i]);
 // Does this cookie string begin with the name we want?
 if (cookie.substring(0, name.length + 1) == (name + '=')) {
 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
 break;
 }
 }
 }
 return cookieValue;
 }
}; 
 
 $(document).ready(function(){
	//menu selecionado/	
	var menu_selecionado = cookie("menu"); 

	if($("#menu-doctorclin ul li a#institucional").attr("id") == menu_selecionado){
		$("#menu-doctorclin ul li a#institucional").siblings('ul').css("display","block");		
	}else{
		$("#menu-doctorclin ul li a#institucional").siblings('ul').css("display","none");
	}	
 	//menu principal
	$("#menu-doctorclin ul li a#institucional").click(function(e) {
		e.preventDefault();
		
		var menu_valor = cookie("menu");		
		
		if(menu_valor=='institucional'){
			if($('#menu-doctorclin ul li a#institucional').siblings('ul:hidden')) {
				cookie("menu",'undefined');
				$("#menu-doctorclin ul li a#institucional").siblings('ul').css("display","block");					
			}			
			
		}else{				
			cookie("menu",'institucional');			
		}		
		$(this).siblings('ul').slideToggle();
	});
		
	

	//mapa
	$("ul.siteMapa li.menu_mapa", $(this)).each(function(i) {
		$(this).click(
			function(e) {
				//condição q somente o link pai tem o 'poder' de abrir e sumir seus filhos e netos
				if($(e.target).is('ul.siteMapa li a:first-child')) {
					$(this).find('ul').slideToggle();
					return false;
				}
		});
	});
	
	//script responsavel pra quebrar a linha da celula maldita no ie
	$("div.bloco ul.doctor_odonto_texto_credenciadas li table tr td a").text(function() {		
		var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer")
			{
				var qtd = $(this).text().length;
				var inicio = $(this).text().slice(0,44);
				var fim = $(this).text().slice(44,qtd);
				$(this).html(inicio + "\n"  + fim);
			}
	});
	
	$("div.bloco ul.doctor_medicina_texto_credenciadas li table tr td a").text(function() {		
		var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer")
			{
				var qtd = $(this).text().length;
				var inicio = $(this).text().slice(0,44);
				var fim = $(this).text().slice(44,qtd);
				$(this).html(inicio + "\n"  + fim);
			}		
	});
	
	$("div.bloco ul.doctor_plano_texto_credenciadas li table tr td a").text(function() {
		var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer")
			{
				var qtd = $(this).text().length;
				var inicio = $(this).text().slice(0,44);
				var fim = $(this).text().slice(44,qtd);
				$(this).html(inicio + "\n"  + fim);
			}
	});
	
	
	$("#doctormedicina_texto_noticia li:last").css('border','none')
	
});
