
function keep_on_top()
{
	var startX = 5, startY = 120;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	var px = document.layers ? "" : "px";
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.right=x+px;this.style.top=y+px;};
		el.x = startX; el.y = startY;
		return el;
	}
	window.stayTopLeft=function()
	{
		var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
		pY += (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight) - ftlObj.offsetHeight;  
		
		/*Above applys to w/ DTD. The following applys to w/o DTD*/
		
		//pY += (document.body.clientHeight ? document.body.clientHeight : window.innerHeight) - ftlObj.offsetHeight;  
		
		//alert(document.body.clientHeight); //IE and FF: window's height
		//alert(document.documentElement.clientHeight); //IE:0; FF: document height
		//alert(window.innerHeight); IE: undefined; FF: window's height
		//alert(document.documentElement.scrollTop);		
		
		var dY = (pY > startY) ? pY : startY;
		ftlObj.y += (dY - ftlObj.y)/1;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 1);
	}
	
	//Detect IE7.0+
	version=0;
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE");
		version=parseFloat(temp[1]);
		//alert("version is "+ version);
	}

	if (version != 0 && version<7.0) {//ONLY run the code on IE6.0-
		//alert("You're using IE7.0+");
	
		ftlObj = ml("arrow-thing");
		stayTopLeft();
	}
}

/**************************************************************************************************************
 * When user does search, scroll to show the match text on top - avoid be blocked by gizmo 
 */
//docBody = document.getElementsByTagName('body')[0];
//docBody.attachEvent("onselectstart", "alert('test!')");
//alert(docBody.id);
var select=false;

function findText_to_top(event){
	//alert(event.srcElement.tagName);
	//window.scrollTo(event.x, event.y);
	//alert(select + " " + event.type);
	if (!select)	{
		if (event.target) {//firefox
			event.target.scrollIntoView(); // scroll to top only when the "select" is not  
		}									   // done by user's mouse, which means it's a "Find" action
		else if (event.srcElement) { //IE
			event.srcElement.scrollIntoView();
		}
	}
}

function diable_scroll() {
	select=true;
	//alert(select);
}

function enable_scroll() {
	select=false;
	//alert(select);
}

function catch_events() {
	var docBody = document.getElementsByTagName('body')[0];
	if (docBody.addEventListener) {//firefox
		//alert("Firefox!");
		window.addEventListener("submit", findText_to_top, false); // cannot catch an event in firefox so far
		docBody.addEventListener("mousedown", diable_scroll, false); 
		docBody.addEventListener("mouseup", enable_scroll, false); 
	}
	else if (docBody.attachEvent) { //IE
		docBody.attachEvent("onselectstart", findText_to_top); //find window do a "select" when finding match
		docBody.attachEvent("onmousedown", diable_scroll); //disable "scroll to top" if user uses mouse to select
		docBody.attachEvent("onmouseup", enable_scroll); //enable "scroll to top" when user is done wiht selecting		
	}
}

/*
 * Handlers for automated loading
 */ 
 _LOADERS = Array();



function callAllLoaders() {
	var i, loaderFunc;
	for (i=0;i<_LOADERS.length;i++) {
		loaderFunc = _LOADERS[i];
		if (loaderFunc != callAllLoaders) loaderFunc();
	}
	//alert(document.getElementById('arrow-thing').offsetHeight);
	
}

function appendLoader(loaderFunc) {
	/* alert("In appendLoader"); */
	if (window.onload && window.onload != callAllLoaders)
		_LOADERS[_LOADERS.length] = window.onload;

	window.onload = callAllLoaders;

	_LOADERS[_LOADERS.length] = loaderFunc;	
		
}

appendLoader(keep_on_top);
appendLoader(catch_events);

/*
//------ SK - glossary links enabling/disabling --------------------------------
function swapAttributes(el, old_attr, new_attr)
{
	old_value = el.getAttribute(old_attr);
	el.removeAttribute(old_attr);
	el.setAttribute(new_attr, old_value);
}

function swapAttributes2(el, old_attr, new_attr, b)
{
	old_value = el.getAttribute(old_attr);
	if (b) {
		el.setAttribute(old_attr, "");
	}
	else {
		el.removeAttribute(old_attr);
	}
	el.setAttribute(new_attr, old_value);
}

function toggleglossarylinks_(cookie_value)
{
	var toggle_element = document.getElementById("toggle-glossary-link");
	var glossary_links = document.getElementsByName("gloss-reflink");
	
	if (cookie_value == null || cookie_value == "enabled") {
		
		toggle_element.firstChild.data = "Disable Glossary Links";

		for (i = 0; i < glossary_links.length; ++i) {
			var el = glossary_links[i];
			swapAttributes(el, "href_", "href");
			swapAttributes2(el, "onclick_", "onclick", false);
		}
	}
	else {
		
		toggle_element.firstChild.data = "Enable Glossary Links";

		for (i = 0; i < glossary_links.length; ++i) {
			var el = glossary_links[i];
			swapAttributes(el, "href", "href_");
			swapAttributes2(el, "onclick", "onclick_", true);
		}
	}
}

function toggleglossarylinks()
{
	var toggle_element = document.getElementById("toggle-glossary-link");

	if (toggle_element.firstChild.data.match("Enable"))
		pmcCreateCookie("GlossaryLinks", "enabled", 7);
	else 
		pmcCreateCookie("GlossaryLinks", "disabled", 7);
	
	toggleglossarylinks_(pmcReadCookie("GlossaryLinks"));
}

function adjustGlossaryLinks()
{
	if (document.getElementById("toggle-glossary-link")) {
		cookie_value = pmcReadCookie("GlossaryLinks");

		if (cookie_value == null)
			pmcCreateCookie("GlossaryLinks", "enabled", 7);
		else if (cookie_value == "disabled")
			toggleglossarylinks_(cookie_value);
	}
}

//------ AK - cookie support ---------------------------------------------------
function pmcCreateCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

	document.cookie = name+"="+value+expires+"; path=/";
}

function pmcReadCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}

	return null;
}

function pmcEraseCookie(name)
{
	pmcCreateCookie(name,"",-1);
}
//------------------------------------------------------------------------------
*/

