var initialOffSet = 0;
var element = null;
var elementId = "stickyDiv";

function onPageLoad() {
	initialiseStickyDiv();
}

function initialiseStickyDiv() {

	// find the div/layer we are moving
	if (document.getElementById)
		element = document.getElementById(elementId);
	else if (document.all)
		element = document.all[elementId];

	// If the element was found set up the movement
	if (element) {
		initialOffSet = element.offsetTop;
		if (document.all) {
			// position div and tie function to events
			moveStickyDiv();
			onscroll = moveStickyDiv;
			onresize = moveStickyDiv;
			// use attachEvent test cos both it and onbefore/afterprint are IE5+ only
			if(window.attachEvent) window.onbeforeprint = resetStickyDiv;
			if(window.attachEvent) window.onafterprint = moveStickyDiv;
		}
		else
			setInterval("moveStickyDiv()",50);
	}
}

function moveStickyDiv() {
	var myScrollTop = (document.body.scrollTop) ? (document.body.scrollTop): window.pageYOffset;
	element.style.top = (myScrollTop > initialOffSet) ? myScrollTop-initialOffSet + "px" : "0";
}

function resetStickyDiv() {
	element.style.top = 0;
}

// these 2 functions switch tab images
function tabOn(tabName){
	if(document.images)
		document.images[tabName].src = onArr[tabName].src;
}

function tabOff(tabName) {
	if(document.images)
		document.images[tabName].src = offArr[tabName].src;
}

function showFullDetails(aimID, yearID, aimRef) {
	window.open( jsAppRoot + "Aims/aimFull.asp?LAid=" + aimID + "&AYid=" + yearID + "&CO=Y&AP=Y&AF=Y&aimRef=" + aimRef + "&printIt=Y", "fullAimWin","height=200,width=200,location=no,directories=no,menubar,scrollbars,resizable,status=no,toolbar=no");
}

function printFull() {
	// if it is supported print the window
	if(window.print) {
		window.print();
		// dont close the window if not IE - window closes before print dialog displays
		if(navigator.appName.indexOf("Microsoft") > -1) window.close();
	}
}

