/********** Last Updated 1/06/11 6:10 PM *********/
/* 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');
	}
}

/*  'function specindexmenu(state)' is moved to mostpopular.js */

/*  'function toggletop10list(state, listx, linkx)' is moved to mostpopular.js */

/* 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()
{
   /* Commented out as events were getting lost on HTML replace 
   $('.custom_button, .hover_menu').mouseenter(function()
    {
        $('.hover_menu').fadeIn('fast');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });
	*/
	$('.custom_button, .hover_menu').live('mouseover', function() {
		$('.hover_menu').fadeIn('fast');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
	});
	$('.custom_button, .hover_menu').live('mouseout', 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');
            $('.hover_menu').data('hidden', true);
        }
    }
});

$(function()
{
  /* Commented out as events were getting lost on HTML replace 
  $('.custom_button2, .hover_menu2').mouseenter(function()
    {
        $('.hover_menu2').fadeIn('fast');
        $(this).data('in', true);
        $('.hover_menu2').data('hidden', false);
    }).mouseleave(function()
    {
        $(this).data('in', false);
        setTimeout(hideMenu2, delay);
    });
	*/
	
	$('.custom_button2, .hover_menu2').live('mouseover', function() {
		 $('.hover_menu2').fadeIn('fast');
        $(this).data('in', true);
        $('.hover_menu2').data('hidden', false);
	});
	
	$('.custom_button2, .hover_menu2').live('mouseout', 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');
            $('.hover_menu2').data('hidden', true);
        }
    }
});
function fburl() {
	wmdPageLink('ar-share_face');
	var fbtitle = document.title;
	var fblink = window.location;
	fblink = fblink + "?src=stfb"
	var fbsharelink = "http://www.facebook.com/share.php?u=" + fblink + "&t=" + fbtitle;
	window.open(fbsharelink);
}
function twiturl() {
	wmdPageLink('ar-share_twit');
	var twtitle = document.title;
	var twiturl = window.location;
	twiturl = twiturl + "?src=sttwit"
	var ftwiturl = "http://twitter.com/share?url="+twiturl+"&text="+twtitle
	window.open(ftwiturl);
}

/* IF ipad and CME funciton */
$(document).ready(function() {
	if (navigator.userAgent.indexOf('iPad') != -1) {
		if (document.getElementById("cmeinfo")) {
			$('head').append('<meta name="viewport" content="width=980" /><link rel="stylesheet" href="http://img.medscape.com/medcss/ipad/ipad_cme.css" type="text/css" media="all">');
			$('<div class="ipadscroll">Use two fingers simultaneously to scroll CME Information.</div>').insertBefore('#accmealert .closewindow2 a');
			$('#cmeinfo p:last-child').hide();
		}
	}
});


/* Top Rated function */
$(function()
{
	$('#topratedart').click(function() {
		$('#mostemailartcontent').hide();
		$('#mostemailart').attr('class','mostpoprighttab');
		$('#topratedartcontent').fadeIn('fast');
		$('#topratedart').attr('class','mostpoprighttabselected');
	});
	$('#mostemailart').click(function() {
		$('#topratedartcontent').hide();
		$('#topratedart').attr('class','mostpoprighttab');
		$('#mostemailartcontent').fadeIn('fast');
		$('#mostemailart').attr('class','mostpoprighttabselected');
	});
});

/* 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;
     }
}
