﻿/* This briefly oscillates the position of the navigational buttons in the heading. */

var HNavArea, HNavButtons, HNavButtonCnt, HNavButtonTimer;
var B, Sx, Sy, Ix, Iy, Rx, Ry, Dx, Dy, Pi2;

if ( window.addEventListener ) window.addEventListener( "load", StartAfterPageLoad, false );
else window.attachEvent( "onload", StartAfterPageLoad );


function ChildElements(Parent) {
	
	var C; /* Child number */
	var nodeType_Element = 1;
	var Elements = Array();
	var ElementCnt = 0;
	
	for ( C = 0; C < Parent.childNodes.length; C++ ) {
		if ( Parent.childNodes[C].nodeType == nodeType_Element ) {
			Elements[ElementCnt] = Parent.childNodes[C];
			ElementCnt += 1;
		}
	}
	
	return Elements;
	
}


function StartAfterPageLoad() {
	
	HNavArea = document.getElementById("HeadingNavigation");
	HNavButtons = new ChildElements(HNavArea);
	HNavButtonCnt = HNavButtons.length;
	B = 0;    /* Button number */
	Sx = 0;  Sy = 0;            /* Horizontal and vertical sway */
	Ix = .3;  Iy = .3;         /* Sway increment */
	Rx = 5;  Ry = 5;           /* Sway radius */
	Dx = Rx / 60;  Dy = Ry / 60; /* Diminish sway radius */
	Pi2 = 2 * Math.PI;
	
	HNavButtonTimer = window.setInterval( "MoveButtons();", 75 );
	
}


function MoveButtons() {
	
	var NB;
	
	Sx += Ix;
	Sy += Iy;
	if ( Sx > Pi2 ) Sx -= Pi2;
	if ( Sy > Pi2 ) Sy -= Pi2;
	
	for ( B = 0; B < HNavButtonCnt; B++ ) {
		HNavButtons[B].style.left = Math.round( Math.cos( Sx + B ) * Rx ) + "px";
		HNavButtons[B].style.top = Math.round( Math.sin( Sy + B ) * Ry ) + "px";
	}
	
	// Diminish radius
	Rx -= Dx;
	Ry -= Dy;
	if ( Rx < .5 && Ry < .5 ) window.clearInterval(HNavButtonTimer);
	
}
