/* Set Vars For Moving Layers */
var theTop = 50;
var old = theTop;

/* 2 Functions for ACCME Layer */
function removeaccmelayer() {
	var arttool = document.getElementById("accmealert");
	setElementClass(arttool, 'inactive');
	if (document.getElementById("accmealertbtn")) {
		var arttool2 = document.getElementById("accmealertbtn");
		setElementClass(arttool2, 'active');
	}	
}
function addaccmelayer() {
	var arttool = document.getElementById("accmealertbtn");
	setElementClass(arttool, 'inactive');
	if (document.getElementById("accmealert")) {
		var arttool2 = document.getElementById("accmealert");
		setElementClass(arttool2, 'active');
	}	
}
/* Empty Placeholder function for two hour deplyment window */
function testaccmelayer() {
	}
/* Function To Expand Presentation */
function expandpresentation(valw, valh) {
	if (document.getElementById("expandlink").style.display == "block") {
		document.getElementById("flashpresentationiframe").style.zIndex = 750;
		document.getElementById("flashpresentationiframe").style.width = valw;
		document.getElementById("flashpresentationiframe").style.height = valh;
		document.getElementById("expandlink").style.display = "none"
		document.getElementById("shrinklink").style.display = "block"
		/*document.getElementById("presentationspacer").style.height = valh;*/
	}
	else {
		document.getElementById("flashpresentationiframe").style.zIndex = 750;
		document.getElementById("flashpresentationiframe").style.width = valw;
		document.getElementById("flashpresentationiframe").style.height = valh;
		document.getElementById("expandlink").style.display = "block"
		document.getElementById("shrinklink").style.display = "none"
		/*document.getElementById("presentationspacer").style.height = valh;*/
	}

}

/* Show The Download Tool */
function showdownloadtoolbox(state) {
	if (document.getElementById) {
		var arttool = document.getElementById("downloadtoolbox");
		setElementClass(arttool, state);
		movelayers("downloadtoolbox");
	}
}

/* Show The Synonyms */
function showsynonyms(state) {
	if (document.getElementById) {
		var syns = document.getElementById("synonymskeywords");
		setElementClass(syns, state);
		movelayers('synonymskeywords');
	}
}

/* Utility Function For Showing Hidden Layer */
function newshowcontent(state, layerid) {
	if (document.getElementById) {
		if (state == "active") {
			document.getElementById(layerid).style.display = "block";
			var contentlayer = document.getElementById(layerid);
			setElementClass(contentlayer, state);
			movelayers(layerid);
		}
		else {
			document.getElementById(layerid).style.display = "none";
			var contentlayer = document.getElementById(layerid);
			setElementClass(contentlayer, state);
			movelayers(layerid);
		}
	}
}

function showcontent(tent, layerid) {
	if ((tent == "active") || (tent == "inactive")) {
		newshowcontent(tent, layerid);
	}
	else {
		if ((document.getElementById(tent).style.display == "none") || (document.getElementById(tent).style.display == "")) {
			document.getElementById(tent).style.display = "none";
			document.getElementById(tent).style.top = '100px';
			document.getElementById(tent).style.position = "absolute";
			document.getElementById(tent).style.zIndex = 500;	
			document.getElementById(tent).style.display = "block";
			document.getElementById(tent).style.height = "auto";
			movelayers(tent);
		} else {
			document.getElementById(tent).style.display = "none";
		}
	}
}

/* Utility Function 2 For Showing Hidden Layer */
function showcontent2(state, layerid, numlink, checklink) {
	if (checklink == "1") {
		var contentlayer = document.getElementById(layerid);
		setElementClass(contentlayer, state);
		changeDiv("subjectheadingslink" + numlink, '<a href=\"javascript:showcontent2(\'inactive\',\'subjectheadings' + numlink + '\',\'' + numlink + '\',\'2\');\">&#8249; Subject Headings</a>');
	}
	else if (checklink == "2") {
		var contentlayer = document.getElementById(layerid);
		setElementClass(contentlayer, state);
		changeDiv("subjectheadingslink" + numlink, '<a href=\"javascript:showcontent2(\'active\',\'subjectheadings' + numlink + '\',\'' + numlink + '\',\'1\');\">Subject Headings &#8250;</a>');
	}
}

/* Utility Function 3 For Showing Hidden Inline Content */
function showcontent3(state, blockid, state2, blockid2) {
	if (document.getElementById) {
		var contentblock = document.getElementById(blockid);
		setElementClass(contentblock, state);
		var contentblock2 = document.getElementById(blockid2);
		setElementClass(contentblock2, state2);
	}
}

/* Function For Showing Hidden Slide */
function showslide(state, layerid) {
	if (document.getElementById) {
		var contentlayer = document.getElementById(layerid);
		setElementClass(contentlayer, state);
	}
}

/* Multi Nav Btn */
function togglearticlelist(state) { 
	if (document.getElementById) {
		var menu = document.getElementById("multiarticlelist").firstChild;
		while (menu.nodeType != 1) {
			menu = menu.nextSibling;
		}
		setElementClass(menu, state);
	}
}

/* Bottom TOC layer scripta */
function togglealloff(state) {
	if (document.getElementById("toclayer")) {
		togglebtmtoc(state);
	}
}

function togglebtmtoc(state) {
	if (document.getElementById) {
		var tocmenu = document.getElementById("toclayer").firstChild;
		while (tocmenu.nodeType != 1) {
			tocmenu = tocmenu.nextSibling;
		}
		setElementClass(tocmenu, state);
	}
}

/* eMed Medication Script */
function showtabs(tab) {
	var tabname = tab;
	var tabarray = new Array();
	tabarray = tabname.split('_');
	tabtype = tabarray[0];
	tabnum = tabarray[1];
	switchtab(tabname, tabtype, tabnum);
}
function switchtab(tabnamex, tabtypex, tabnumx) {
	var tabname = tabnamex;
	var tabtype = tabtypex;
	var tabnum = tabnumx;
	if (tabtype == "dosing") {
		var taboff1 = document.getElementById("interactions_" + tabnum).firstChild;
		var taboff2 = document.getElementById("contraindications_" + tabnum).firstChild;
		var taboff3 = document.getElementById("precautions_" + tabnum).firstChild;
		var tabon = document.getElementById(tabname).firstChild;
		while ((taboff1.nodeType != 1) & (taboff2.nodeType != 1) & (taboff3.nodeType != 1) & (tabon.nodeType != 1)) {
			taboff1 = taboff1.nextSibling;
			taboff2 = taboff2.nextSibling;
			taboff3 = taboff3.nextSibling;
			tabon = tabon.nextSibling;
		}
		setElementClass(taboff1, 'tabinactive');
		setElementClass(taboff2, 'tabinactive');
		setElementClass(taboff3, 'tabinactive');
		setElementClass(tabon, 'tabactive');
	}
	else if (tabtype == "interactions") {
		var taboff1 = document.getElementById("dosing_" + tabnum).firstChild;
		var taboff2 = document.getElementById("contraindications_" + tabnum).firstChild;
		var taboff3 = document.getElementById("precautions_" + tabnum).firstChild;
		var tabon = document.getElementById(tabname).firstChild;
		while ((taboff1.nodeType != 1) & (taboff2.nodeType != 1) & (taboff3.nodeType != 1) & (tabon.nodeType != 1)) {
			taboff1 = taboff1.nextSibling;
			taboff2 = taboff2.nextSibling;
			taboff3 = taboff3.nextSibling;
			tabon = tabon.nextSibling;
		}
		setElementClass(taboff1, 'tabinactive');
		setElementClass(taboff2, 'tabinactive');
		setElementClass(taboff3, 'tabinactive');
		setElementClass(tabon, 'tabactive');
	}
	else if (tabtype == "contraindications") {
		var taboff1 = document.getElementById("dosing_" + tabnum).firstChild;
		var taboff2 = document.getElementById("interactions_" + tabnum).firstChild;
		var taboff3 = document.getElementById("precautions_" + tabnum).firstChild;
		var tabon = document.getElementById(tabname).firstChild;
		while ((taboff1.nodeType != 1) & (taboff2.nodeType != 1) & (taboff3.nodeType != 1) & (tabon.nodeType != 1)) {
			taboff1 = taboff1.nextSibling;
			taboff2 = taboff2.nextSibling;
			taboff3 = taboff3.nextSibling;
			tabon = tabon.nextSibling;
		}
		setElementClass(taboff1, 'tabinactive');
		setElementClass(taboff2, 'tabinactive');
		setElementClass(taboff3, 'tabinactive');
		setElementClass(tabon, 'tabactive');
	}
	else if (tabtype == "precautions") {
		var taboff1 = document.getElementById("dosing_" + tabnum).firstChild;
		var taboff2 = document.getElementById("interactions_" + tabnum).firstChild;
		var taboff3 = document.getElementById("contraindications_" + tabnum).firstChild;
		var tabon = document.getElementById(tabname).firstChild;
		while ((taboff1.nodeType != 1) & (taboff2.nodeType != 1) & (taboff3.nodeType != 1) & (tabon.nodeType != 1)) {
			taboff1 = taboff1.nextSibling;
			taboff2 = taboff2.nextSibling;
			taboff3 = taboff3.nextSibling;
			tabon = tabon.nextSibling;
		}
		setElementClass(taboff1, 'tabinactive');
		setElementClass(taboff2, 'tabinactive');
		setElementClass(taboff3, 'tabinactive');
		setElementClass(tabon, 'tabactive');
	}
}

/* Show Specialty Index Menu */
function specindexmenu(state) {
	if (document.getElementById) {
		var specmenu = document.getElementById("top10pulldownindex");
		setElementClass(specmenu, state);
	}
}

/* Toggle Top 10 Lists */
function toggletop10list(state, listx, linkx) {
	if (document.getElementById) {
		if (linkx == "top10emaillink") {
			var top10list = document.getElementById(listx);
			setElementClass(top10list, state);
			var top10link = document.getElementById(linkx);
			setElementClass(top10link, 'current');
			var newHTML = "<b>Most Emailed Articles</b>"
			changeDiv(linkx, newHTML);
			var top10list2 = document.getElementById("top10rate");
			setElementClass(top10list2, 'inactive');
			var top10link2 = document.getElementById("top10ratelink");
			setElementClass(top10link2, '');
			var newHTML2 = "<a href=\"javascript:toggletop10list('active','top10rate','top10ratelink');\">Top Rated Articles</a>"
			changeDiv('top10ratelink', newHTML2);
		}
		else if (linkx == "top10ratelink") {
			var top10list = document.getElementById(listx);
			setElementClass(top10list, state);
			var top10link = document.getElementById(linkx);
			setElementClass(top10link, 'current');
			var newHTML = "<b>Top Rated Articles</b>"
			changeDiv(linkx, newHTML);
			var top10list2 = document.getElementById("top10email");
			setElementClass(top10list2, 'inactive');
			var top10link2 = document.getElementById("top10emaillink");
			setElementClass(top10link2, '');
			var newHTML2 = "<a href=\"javascript:toggletop10list('active','top10email','top10emaillink');\">Most Emailed Articles</a>"
			changeDiv('top10emaillink', newHTML2);
		}
	}
}

/* Utility Function Move Layers */
function movelayers(num)
{
	if (window.innerHeight)
	{
		pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		pos = document.body.scrollTop
	}
	
	if (pos < theTop)
		{
		pos = theTop;
		}
	else
		{
		pos += 50;
		}
	
	if (pos == old)
	{
		document.getElementById(num).style.top = (pos + 'px');
	}
	else
	{
		old = pos;
		movelayers(num);
	}
}

// basic jQuery show and hide for share button
$(function()
{
    $('.custom_button, .hover_menu').mouseenter(function()
    {
        $('.hover_menu').fadeIn('fast');
        $('.custom_button').addClass('active');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });

    var delay = 400;
    function hideMenu()
    {
        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden'))
        {
            $('.hover_menu').fadeOut('fast');
            $('.custom_button').removeClass('active');
            $('.hover_menu').data('hidden', true);
        }
    }
});

$(function()
{
    $('.custom_button2, .hover_menu2').mouseenter(function()
    {
        $('.hover_menu2').fadeIn('fast');
        $('.custom_button2').addClass('active');
        $(this).data('in', true);
        $('.hover_menu2').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu2, delay);
    });

    var delay = 400;
    function hideMenu2()
    {
        if (!$('.custom_button2').data('in') && !$('.hover_menu2').data('in') && !$('.hover_menu2').data('hidden'))
        {
            $('.hover_menu2').fadeOut('fast');
            $('.custom_button2').removeClass('active');
            $('.hover_menu2').data('hidden', true);
        }
    }
});

/* Utility Function For Hide Show States */
function getElementClass(element) {
	if (element.getAttribute("class")) {
		return element.getAttribute("class");
	} else if (element.getAttribute("className")) {
		return element.getAttribute("className");
	}
}

function setElementClass(element, classValue) {
	if (element.setAttribute("class", classValue)) {
		element.setAttribute("class", classValue);
	} else if (element.setAttribute("className", classValue)) {
		element.setAttribute("className", classValue);
	}
}

/* Utility Function For Changing Div Content */
function changeDiv(id, str) {
     if(!document.getElementById) return; // Not Supported
     
	 if(document.getElementById) {
	 	document.getElementById(id).innerHTML = str;
     }
}