﻿// This is for the LinkToTop div that moves user back up the page.
window.onload = function () {
		document.getElementById('linkToTop').style.right = retLeftPos() + 'px';
		document.getElementById('aBackToTop').innerHTML = "Back to the top &laquo;";
		window.onscroll = function () {
			var doc = document.documentElement;
			scrollPosition = doc.scrollTop; 
			pageSize = (doc.scrollHeight - doc.clientHeight);
			percentageScrolled = Math.floor((scrollPosition / pageSize) * 100);
			if (percentageScrolled >= 98.5 || percentageScrolled <= 5){ // if the percentage is >= 50, scroll to top window.scrollTo(0,0)
				document.getElementById('linkToTop').style.display='none';
			}else  document.getElementById('linkToTop').style.display='block';
		};
		window.onresize = function () {
			linkTopPosition = retLeftPos();
			if (pageWidth > 750){
				document.getElementById('linkToTop').style.position='fixed';
				document.getElementById('linkToTop').style.right = linkTopPosition + 'px';
			}else {
				document.getElementById('linkToTop').style.position='';
				document.getElementById('linkToTop').style.right = linkTopPosition + 'px';
			}//document.getElementById('linkToTop').innerHTML = linkTopPosition + " " + pageWidth;
		};
	}; // left:auto; right:5px;
	function retLeftPos(){
		var doc; var pageWidthPosOffset = 450;
//		if( typeof( window.innerWidth ) == 'number' ) {
//			//Non-IE
//			doc = window;
//			myWidth = window.innerWidth;//myHeight = window.innerHeight;
//			myScrollWidth = myWidth;
//		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			doc = document.documentElement;
			myWidth = document.documentElement.clientWidth;//myHeight = document.documentElement.clientHeight;
			myScrollWidth = myWidth;
//		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//			//IE 4 compatible
//			doc = document.body;
//			myWidth = document.body.clientWidth;//myHeight = document.body.clientHeight;
//			myScrollWidth = myWidth;
//		}
		scrollPositionH = doc.scrollLeft;
		pageWidth = Math.floor(myScrollWidth);// - Math.floor(doc.clientWidth);percentageScrolledH = Math.floor((scrollPositionH / pageWidth) * 100);
		linkTopPosition = (Math.floor(pageWidth)/2) - pageWidthPosOffset;
		return linkTopPosition;
	}
