// updated 15-nov-03 for macros
// updated 24-mar-04 fixed stepDuration
// updated 23-feb-05 use css

function nav1 (activeItem)
{
  renderNav (
    [ [ 'Home',     '/index.html' ]
    , [ 'Macros',   '/downloads/sas/macros/index.php' ]
    , [ 'Samples',  '/downloads/sas/samples/' ]
    , [ 'SASCBTBL', '/downloads/sas/sascbtbl/' ]
    , [ 'SAS/AF',   '/downloads/sas/af/' ]
    , [ 'Miscellaneous', '/docs/SAS/sas-colors.html' ]
    , [ 'Papers',   '/papers/' ]
    , [ 'Actions',  '/downloads/sas/actions/' ]
    ]
  , activeItem )
}

function nav2 (activeItem)
{
  renderNav (
    [ [ 'Colors',      '/docs/SAS/sas-colors.html' ]
    , [ 'Suggestions', '/docs/SAS/suggestions.php' ]
    , [ 'Impressions', '/docs/SAS/First Impressions.htm' ]
    ]
  , activeItem )
}

function nav3 (activeItem)
{
  renderNav (
    [ [ 'Spec Edit',     '/papers/nesug-1995/' ]
    , [ 'FSEDIT & AF',   '/papers/nesug-1996/' ]
    , [ 'AF:Data Table', '/papers/nesug-1999/' ]
    , [ 'AF:Composite',  '/papers/sugi-26/' ]
    , [ 'JavaObj 1',     '/papers/sesug-2003/' ]
    , [ 'JavaObj 2',     '/papers/sugi-29/' ]
    , [ 'JavaObj 3',     '/papers/sugi-30/' ]
    ]
  , activeItem )
}

var transitions = new Array()

transitions.timerId = 0
transitions.steps = 25
transitions.stepDuration = 10

transitions.atColor   = "#DDDDDD"
transitions.overColor = "#FFFF00"
transitions.outColor  = "#FFFFFF"

function removeElement(array, index) {
  if (array.length == 0) return
  for (var i=index; i<array.length-1 && i>=0;i++) {
    array[i] = array[i+1]
  }
  array.length=array.length-1
}

function htmlColorString (r,g,b) {
  r = r.toString(16); if (r.length == 1) r = '0'+r;
  g = g.toString(16); if (g.length == 1) g = '0'+g;
  b = b.toString(16); if (b.length == 1) b = '0'+b;

  return "#" + r + g + b
}

function transition (obj) {
  this.obj  = obj
  this.from = transitions.overColor.substring(1)
  this.to   = transitions.outColor.substring(1)
  this.step = 0
}

function doStep () {
  var from = this.from
  var   to = this.to
  var step = this.step
  var steps = transitions.steps

  var r0 = parseInt (from.substr(0,2),16)
  var g0 = parseInt (from.substr(2,2),16)
  var b0 = parseInt (from.substr(4,2),16)

  var r1 = parseInt (  to.substr(0,2),16)
  var g1 = parseInt (  to.substr(2,2),16)
  var b1 = parseInt (  to.substr(4,2),16)

  var r = Math.floor (r0 * ((steps-step)/steps) + r1 * (step/steps))
  var g = Math.floor (g0 * ((steps-step)/steps) + g1 * (step/steps))
  var b = Math.floor (b0 * ((steps-step)/steps) + b1 * (step/steps))

  var color = htmlColorString (r,g,b)

  this.step ++
  this.obj.style.backgroundColor = color
}

transition.prototype.doStep = doStep

function doTransitions () {
  var L = transitions.length

  for (var i=L-1; i>=0; i--) {
    transitions[i].doStep()
    if (transitions[i].step > transitions.steps)
      removeElement (transitions, i)
  }

  if (transitions.length)
    transitions.timerId = setTimeout ("doTransitions()", transitions.stepDuration)
  else
    transitions.timerId = 0
}

transitions.over = function (o,dest) {
  window.status = dest

  if (transitions.timerId) clearTimeout (transitions.timerId)
  transitions.timerId = 0

  var L = transitions.length
  for (var i=L-1; i>=0; i--) {
    if (transitions[i].obj == o) removeElement (transitions, i)
  }

  o.style.backgroundColor = transitions.overColor

  if (transitions.length>0)
    transitions.timerId = setTimeout ("doTransitions()", 0)

  return true
}

transitions.out = function (o) {
  window.status = ''

//uncomment these two for no fading
//o.style.backgroundColor = c
//return true

  transitions[transitions.length] = new transition (o) // push

  if (!transitions.timerId)
    transitions.timerId = setTimeout ("doTransitions()", 0)

  return true
}

function renderNav (items, activeItem) {
  var root, table, Q, i

  root = ''
  table = ""
  Q = "'"

  table += '<TABLE CLASS=nav>\n'
          +'<TR>';

  for (i=0;i<items.length;i++) {
//	var width = (100/items.length).toPrecision(4)
    var width = Math.floor((100/items.length) * 100)/100
    table += '\n<TD STYLE="width:'+width+'%'

    if (items[0][0] == 'Home') table += ';border-top:1px solid black'

    if (i == activeItem) {
      table += ';background-color: ' + transitions.atColor + '"'
    }
    else {
      table += ';background-color: ' + transitions.outColor + '"'
             + ' TARGET=_top'
             + ' ONMOUSEOVER="return transitions.over(this,' + Q + root + items[i][1] + Q + ')"'
             + ' ONMOUSEOUT ="return transitions.out (this)"'
             + ' ONCLICK="top.location.href=' + Q + root + items[i][1] + Q + '"'
    }
    table += '>' + items[i][0] + '\n</TD>'
  }
  table += '\n</TR>\n</TABLE>'

  document.write (table)
}

document.write
( "<style type='text/css'>"
+ "table.nav {width:100%;border-collapse:collapse;font-family:sans-serif;font-size:9pt}"
+ "table.nav td {text-align:center;border-right:1px solid black;border-bottom:1px solid black;border-left:1px solid black;padding:1px}"
+ "</style>"
)
