/* scroller functions from PLOS*/

function scrollingDetector(inflect) {
	//alert("inflect: " + inflect);
	var scrollLoc = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
	//alert("scrollTop: " + scrollLoc);
	if (scrollLoc > inflect) {
		document.getElementById('sectionNav').style.display = 'block';
		document.getElementById('sectionNavTop').style.display = 'none';
		
		var sn = document.getElementById('sectionNav');
		var snPos = findPosY(sn);
		var snTop = replace(sn.style.top,'px','');
		if (sn.offsetTop > 20) {
			snDiff = snPos - snTop;
			sn.style.top = (scrollLoc - snDiff + 20) + 'px';
		}
		
	} else {
		document.getElementById('sectionNav').style.display = 'none';
		document.getElementById('sectionNavTop').style.display = 'block';
	}
}

function showScroll() {
	var scrollLoc = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
	alert('scrolltop: ' + scrollLoc);
}

/* init */

var current;

function init() {
	if (articleType == 'ra') {
		snt = document.getElementById('sectionNavTop');
		if (snt) {
			var inflect = findPosY(snt);
			// set up scroll detector
			setInterval('scrollingDetector(' + inflect + ')', 100);
			//alert('inflect ' + inflect);
		}	
	}
	
	var trigger = document.getElementById('oa');
	trigger.onmouseover = showpopup;
	trigger.onmouseout = hoverhidepopup;

	var hover = document.getElementById('oa-hover');
	hover.onmouseout = mouseouthidepopup;

	current = dojo.lfx.html.fadeOut("oa-hover", 750, 0, hideHover);
	dojo.lang.setTimeout(current, current.play, 1000);

	externalLinks();
}

dojo.addOnLoad(init);

