// ===========================================================================
// contact
// ===========================================================================

var leader = "Comments to "
var meat = "&#105;&#109;&#97;&#103;&#105;&#110;&#101;&#101;&#114;&#52;&#55;&#64;"
var domain = "&#121;&#97;&#104;&#111;&#111;&#46;&#99;&#111;&#109;"

function hotcontact()
{
document.getElementById('contactarea').innerHTML = 
    '<i>' 
    + leader + '<a href="mailto:' + meat + domain + '">' + meat + domain + '</a>' 
    + '</i>'
}

// ===========================================================================
// style
// ===========================================================================

var flavors = new Array(9)
var defaultflavor = 0
var flavormax = 8
var docname = "index.htm"
var flavorpath = ""

flavors[0] = "css/stop.css"
flavors[1] = "classic.css"
flavors[2] = "css/ansel.css"
flavors[3] = "css/white-pal14.css"
flavors[4] = "css/sky-t10.css"
flavors[5] = "css/midnight-t10.css"
flavors[6] = "css/midnight-v10.css"
flavors[7] = "css/white-v12.css"
flavors[8] = "css/white-pal11.css"

// -----------------------------------

function style_init(codepath)
{
  flavorpath = codepath

  var p = location.href
  var i = p.indexOf('?')
  if( i < 0 ){ docname = p }
  else { docname = p.substr( 0, i ) }

  defaultflavor = 0
  p = location.search
  if( p.length >= 4 ){
    defaultflavor = p.substr( 3, p.length - 3 )
  }
  write_CSSlink(defaultflavor)
}

function write_CSSlink(flavor)
{
  if( flavor == "" ){ flavor = defaultflavor }
  var taste = flavorpath + flavors[flavor]
  document.write( '<link rel="stylesheet" type="text/css" href="'
                  + taste + '" />' );
}

function style_bodyonload()
{
  FlavorAllLinks();
  InsertFlavorChooser();
}

function FlavorAllLinks()
// appends the stylesheet indicator to all links in the document.
{
  for (var i=0; i < document.links.length; i++)
    if( document.links[i].protocol == "http:" ||
        document.links[i].protocol == "file:" )
      document.links[i].href = FlavoredURL( document.links[i].href );
}

function FlavoredURL(targetURL)
{
  return( targetURL + '?s=' + defaultflavor )
}

function InsertFlavorChooser()
{
  document.getElementById('stylechooserarea').innerHTML = LinkToNextStyle();
}

function LinkToNextStyle()
{
  return( '<a accesskey="S" href="' + URLToNextStyle() + '">Style</a> //' )
}

function URLToNextStyle()
{
  var next = defaultflavor
  next++
  if( next > flavormax ){ next = 0 }
  return( docname + '?s=' + next )
}


// ===========================================================================
// main
// ===========================================================================

function init(codepath)
{
  style_init(codepath);
}

function bodyonload()
{
  style_bodyonload();
  hotcontact();
}


