

//tooltip appearance delay [milliseconds]
afs.delay = 400;


//tooltip summaries indexed by glossary <dt id>
afs.tips = {
	'Adhesions' : ['Adhesions', 'Bands of scar tissue caused by surgical procedures, endometriosis, or infections. Adhesions connect two organs together, affecting normal reproductive function.'],
	'Antagon' : ['Antagon', 'A GnRH (gonadotropin releasing hormone) antagonist (drug used to block the action of GnRH) that can prevent a premature LH surge, and is sometimes prescribed in ovulation induction therapies ...'],
	'AygestinNorethindroneAcetate' : ['Aygestin (Norethindrone Acetate)', 'Aygestin is a form of progestin, a synthetic substance that chemically resembles progesterone, that may be prescribed in ovulation induction therapies to inhibit ovulation and quiet the ovaries in advance of egg stimulation using injectable hormones ...'],
	'ClomipheneCitrateSeraphene' : ['Clomiphene Citrate (Seraphene/Clomid)', 'Clomiphene citrate is an oral medication that induces ovulation by blocking estrogen receptors. This artificial estrogen effect causes your body to believe estrogen is low, triggering the production of more follicle-stimulating hormone (FSH) and luteinizing hormone (LH) ...'],
	'CorpusLuteum' : ['Corpus Luteum', 'After a woman ovulates, the fluid filled sac in which the egg matures (the follicle) becomes the corpus luteum. It continues to produce androgen, estrogen, and progesterone, hormones that prepare the uterine lining to accept and nurture the fertilized egg.'],
	'Endometriosis' : ['Endometriosis', 'A disease in which tissue from the uterine lining grows outside of the uterus. When this tissue "sheds" during a menstrual cycle, blood and tissue collects in the abdomen.'],
	'Fibroid' : ['Fibroid', 'Also known as a myoma or leiomyoma, a benign (noncancerous) tumor found in the wall of the uterus. Fibroids are extremely common; more than 40% of all women develop fibroids, and most do not cause symptoms or require treatment ...'],
	'Follicle-StimulatingHormoneFSH' : ['Follicle-Stimulating Hormone (FSH)', 'A hormone, secreted by the anterior pituitary gland, which promotes the development of ova in the female and testicular function in the male. In women, FSH stimulates the ovary to ripen a follicle during the menstrual cycle ...'],
	'HumanChorionicGonadotropinhCG' : ['Human Chorionic Gonadotropin (hCG)', 'A hormone produced following ovulation which aids the corpus luteum in the production of progesterone, required to prepare the uterine lining for implantation of the fertilized egg ...'],
	'HumanMenopausalGonadotropinhMG' : ['Human Menopausal Gonadotropin (hMG)', 'A hormone used to stimulate the development of multiple follicles. Injectable human menopausal gonadotropin, also known as menotropin, is a purified preparation of the naturally occurring hormones follicle-stimulating hormone (FSH) and luteinizing hormone (LH) ...'],
	'InVitroFertilizationIVF' : ['In Vitro Fertilization (IVF)', 'An assisted reproductive technology that involves ovulation induction and the surgical removal of eggs from the woman\'s ovaries, which are then combined with sperm in a laboratory dish to facilitate fertilization ...'],
	'InjectableFertilityMedications' : ['Injectable Fertility Medications', 'Medications given by injection in fertility treatments such as ovulation induction and IVF, which may include the following drugs ...'],
	'IntracytoplasmicSpermInjectionICSI' : ['Intracytoplasmic Sperm Injection (ICSI)', 'A micromanipulation procedure, ICSI is used most commonly in cases of severe male infertility. It involves injection of a single sperm directly into the core of an egg. In order to undergo ICSI, a couple must follow the same steps as for in vitro fertilization (IVF) ...'],
	'Lupron' : ['Lupron', 'The brand name for Leuprolide acetate, a GnRH analog. Lupron suppresses the brain\'s secretion of LH and FSH. It is used in preparation for cycles of treatment with ovulation induction drugs (hMG and/or FSH) for IVF ...'],
	'MicroSort' : ['MicroSort&reg;', 'A method used to select a baby\'s sex or gender by separating X-bearing (female) sperm from Y-bearing (male) sperm. The MicroSort technology is based on the difference in size between an X chromosome and the much smaller Y chromosome ...'],
	'OralContraceptives' : ['Oral Contraceptives', 'Although typically prescribed to prevent pregnancy, oral contraceptives may be prescribed to IVF cycling patients to inhibit ovulation and quiet the ovaries in advance of egg stimulation using injectable hormones ...'],
	'OvarianCyst' : ['Ovarian Cyst', 'A fluid-filled sac inside the ovary. An ovarian cyst may be found in conjunction with ovarian disorders, tumors of the ovary, and endometriosis.'],
	'PolycysticOvarianSyndromePCOS' : ['Polycystic Ovarian Syndrome (PCOS)', 'A genetically-linked hormonal imbalance that prevents ovulation. PCOS may also cause overproduction of estrogen, abnormal thickening of the uterine lining, very heavy and/or irregular periods, as well as acne and facial hair ...'],
	'Polyp' : ['Polyp', 'A small growth or fold of the lining in the uterus or cervix.'],
	'ZonaPellucida' : ['Zona Pellucida', 'The outer membrane of a human egg.'],
	'UterineSeptum' : ['Uterine Septum', 'An abnormality of the uterus in which the inside of the uterus is divided by a wall (septum). The septum may extend only part way into the uterus or it may reach as far as the cervix ...'],
	'MaleFactorInfertility' : ['Male Factor Infertility', 'Infertility that can be attributed to a reproductive problem in the male partner. In roughly 35% of all infertility cases, the cause is attributed to a factor in the male and in some 25% of cases the cause is attributed to both male and female factors ...'],
	'Ultrasound' : ['Ultrasound', 'A diagnostic procedure using sound waves that produces a two or three dimensional picture used for the examination, evaluation and measurement of the abdominal cavity, reproductive organs, developing follicles and developing fetus ...'],
	'Blastocyst' : ['Blastocyst', 'An embryo that is approximately five days old and consists of some 100 cells that form an outer shell of cells protecting an attached inner group of cells surrounding a fluid core ...']
	};
	




//tooltip object
afs.tooltip = null;
	
//delay timer
afs.timer = null;

//cache tooltip background image
afs.img = new Image;
afs.img.src = '/images/greenbit.gif';


//initialise tooltips function
function tooltips()
{
	//get spans inside content div
	afs.terms = document.getElementById('content').getElementsByTagName('span');
	afs.termsLen = afs.terms.length;
	
	//for each one
	for(var i=0; i<afs.terms.length; i++)
	{
		//if it has the right classname
		if(afs.terms[i].className.indexOf('info')!=-1)
		{
			//extract glossary ID reference
			afs.idref = afs.terms[i].className.replace('info ','');

			//if a corresponding array item exists
			if(typeof afs.tips[afs.idref] != 'undefined')
			{
				//add hasTooltip classname
				afs.terms[i].className += ' hasTooltip';
				
				//prevent widows and orphans by disallowing word wrapping
				afs.terms[i].style.whiteSpace = 'nowrap';

				//bind mouseover handler
				afs.terms[i].onmouseover = function()
				{
					//just in case a timer is running, nullify it
					clearInterval(afs.timer);
					afs.timer = null;

					//create tooltip on a new timer
					afs.self = this;
					afs.timer = window.setInterval('afs.createTooltip(afs.self)', afs.delay);
				};
			}
		}
	}

	
	//document click handler 
	document.onclick = function()
	{
		//if a tooltip exists
		if(afs.tooltip != null)
		{
			//remove and nullify it
			document.body.removeChild(afs.tooltip);
			afs.tooltip = null;
		}
	};


};






//create tooltip function
afs.createTooltip = function(span)
{
	
	//nullify timer
	clearInterval(afs.timer);
	afs.timer = null;

	//if a tooltip already exists
	if(afs.tooltip != null)
	{
		//remove and nullify it
		document.body.removeChild(afs.tooltip);
		afs.tooltip = null;
	}

	//create tooltip element and append to document body
	afs.tooltip = document.body.appendChild(document.createElement('div'));
	afs.tooltip.className = 'tooltip';

	//extract glossary ID reference
	span.idref = span.className.replace(/(info | hasTooltip)/g,'');

	//add definition list with terms, summary and 'more' link
	afs.tooltip.innerHTML = ''
		+ '<dl>'
		+ '<dt>' + afs.tips[span.idref][0] + '</dt>'
		+ '<dd>' + afs.tips[span.idref][1] + '</dd>'
		+ '<dd class="more"><a href="/resources/glossary.php#' + span.idref + '" title="More details">More &gt;</a></dd>'
		+ '</dl>';

	//get position of triggering span	
	span.pos = afs.getRealPosition(span);

	//add height of span
	span.pos.y += span.offsetHeight;

	//get height of tooltip
	span.tipheight = afs.tooltip.offsetHeight;

	//if layer exceeds window height
	if((span.pos.y + span.tipheight) > ((afs.getWindowSize().h + afs.getScrollAmount()) - 10))
	{
		//move it above the span
		span.pos.y -= (span.tipheight + span.offsetHeight);
	}

	//if layer exceeds window width
	if((span.pos.x + 252) > (afs.getWindowSize().w - 10))
	{
		//move it to the left
		span.pos.x -= (252 - span.offsetWidth);
	}

	//move tip to position 
	afs.tooltip.style.left = span.pos.x + 'px';
	afs.tooltip.style.top = span.pos.y + 'px';
	
	//show tooltip on a short timer to avoid a visible jump to position in moz
	afs.timer = window.setInterval('afs.showTooltip()', 55);
	
};




//show tooltip
afs.showTooltip = function()
{
	//nullify timer
	clearInterval(afs.timer);
	afs.timer = null;

	//show tooltip
	afs.tooltip.style.visibility = 'visible';
};





//get real position of element
afs.getRealPosition = function(ele)
{
	afs.pos = { 'x' : ele.offsetLeft , 'y' : ele.offsetTop };
	afs.parent = ele.offsetParent;
	while(afs.parent != null)
	{
		afs.pos.x += afs.parent.offsetLeft;
		afs.pos.y += afs.parent.offsetTop;
		afs.parent = afs.parent.offsetParent;
	}
	return afs.pos;
};




//get window size
afs.getWindowSize = function()
{
	if(typeof window.innerWidth != 'undefined')
	{
		afs.win = {
			w:window.innerWidth,
			h:window.innerHeight
			};
	}
	else if(typeof document.documentElement.offsetWidth != 'undefined')
	{
		afs.win = {
			w:document.documentElement.offsetWidth,
			h:document.documentElement.offsetHeight
			};
	}
	else
	{
		afs.win = {
			w:document.body.clientWidth,
			h:document.body.clientHeight
			};
	}
	return afs.win;
};



//get scroll amount
afs.getScrollAmount = function()
{
	if(typeof window.pageYOffset != 'undefined')
	{
		afs.scroll = window.pageYOffset;
	}
	else if(typeof document.documentElement.scrollTop != 'undefined')
	{
		afs.scroll = document.documentElement.scrollTop;
	}
	else
	{
		afs.scroll = document.body.scrollTop;
	}
	return afs.scroll;
};





