// All these calculations assume the image libraries have entries named
// 000.gif, 005.gif ... 355.gif with intervals of 5 degrees. By changing
// interval to any whole number factor of 360, other intervals are possible.

var interval = 5

// These values describe Moon and sky rotation rates per day,
// epoch date and time and the path to the GIF image library

var lunarRate = 360/29.530355
var lunarDT   = '2000/1/6 13:14:23'
var lunarPath = '../moon/'

var skyRate   = 360*1.00273790935
var skyDT     = '2000/1/1 00:00:00'
var skyPath   = '../skymaps/'

// Create a [MODIFIED] Julian Day Number from a date string and a time string.

function modJDN(DT)
{
    var mjdn=nuDATE(DT)
    return mjdn.getTime()/_msD_
}

// Calculate the filename ### from  the dates, the cycle and the rate per day.
// This will be a series of values 000 to 360 spaced at interval [currently 5]

function filename(given, epoch, cycle, rate)
{   var degrees,fn

    degrees=(given-epoch)*rate + (cycle*interval)
    degrees=Round(degrees/interval)*interval
    fn=String(degrees%360)
    while (fn.length<3) {fn='0'+fn}
    return fn
}

// Paste an image selected by fn at the position on the page determined by icon.

function pasteImage(icon, fn)
{   var gifImage

    gifImage=locateImage(icon)
    if (gifImage) {gifImage.src=fn}
}

// Locate the parameters associated with the space reserved for the image called icon.

function locateImage(icon)
{   var theImage

    theImage=false
    if (document.images) {theImage=document.images[icon]}
    if (theImage) {return theImage}
    return (false)
}

// Determine the Julian day number (decimal) for the given and epoch dates.
// Determine the ### (000...355) for these dates as a filename
// Complete the file name with the path information and the extension (GIF)
// Paste this GIF image at the place reserved for it by icon

function Rotate(givenDT, epochDT, cycle, rate, path)
{   var given,epoch,fn

    given=modJDN(givenDT)
    epoch=modJDN(epochDT)
    fn=filename(given,epoch,cycle,rate)
    fn=(path+fn+'.gif')
    pasteImage('Icon',fn)
}

