/**************************** 
* linear JavaScript Library *
*       version 0.01        *
****************************/

//////// handler for theme picker requests ////////////
function colorize(pri, sec, ter, link, vlink, hover)
{
  CSSbody =     document.styleSheets[0].rules.item(0);
  CSSlink =     document.styleSheets[0].rules.item(4);
  CSSvisited =  document.styleSheets[0].rules.item(5);
  CSShover =    document.styleSheets[0].rules.item(6);
  CSSnavbar =   document.styleSheets[0].rules.item(11);
  CSSentry =    document.styleSheets[0].rules.item(12);
  // do it the new way 
  CSSbody.style.backgroundColor = pri;
  CSSbody.style.scrollbarFaceColor = sec;
  CSSbody.style.scrollbarShadowColor = ter;
  CSSbody.style.scrollbarHighlightColor = ter;
  CSSbody.style.scrollbar3dlightColor = ter;
  CSSbody.style.scrollbarDarkshadowColor = ter;
  CSSbody.style.scrollbarTrackColor = pri;
  CSSbody.style.scrollbarArrowColor = ter;
  CSSbody.style.color = ter;
  //CSSnavbar.style.backgroundColor = sec;
  //CSSentry.style.backgroundColor = sec;
  
  // need to keep this loop for now....
  divs = document.getElementsByTagName('div');
  for(var i=1; i<divs.length; i++)
  {
    el = divs[i];
    if (el.className == 'entry' || el.id == 'navBar')
	{
      divs[i].style.backgroundColor = sec;
    }
    divs[i].style.color = ter;
  }
  // document.styleSheets[0].rules.item(2).style.color = link;
  document.styleSheets[0].rules.item(3).style.color = link;
  document.styleSheets[0].rules.item(4).style.color = vlink;
  document.styleSheets[0].rules.item(5).style.color = hover;
  
  // have a cookie
  var now = new Date();   
  var then = new Date();   
  then.setTime(now.getTime() + 1000*60*60*24*180);
  setCookie('pri', pri, then);
  setCookie('sec', sec, then);
  setCookie('ter', ter, then);
  setCookie('link', link, then);
  setCookie('vlink', vlink, then);
  setCookie('hover', hover, then);
}


//////// Cookie utility function
function setCookie(name, value, expire)
{   
  document.cookie = name + "=" + escape(value) + "; path=/" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}

//////// floater bar handler IE only, dammit
function smoothMove()
{
  var Dif = parseInt((document.body.scrollTop+topOffset-document.all.navBar.offsetTop)*.1);
  // Work-around wierd Netscape NaN bug when Dif is 0
  if (isNaN(Dif))
  {
    Dif=0;
  }
  document.all.navBar.style.pixelTop+=Dif;
}

function smoothMoveDOM()
{ 
  // in progress...
  // gotta replace document.all everywhere with document.getElementById()
  var el = document.getElementById('navBar');
  var from = parseInt(el.style.top);
  // what's the DOM equivalent of document.scrollTop??
  var dif = Window.pageYOffset - document.getElementById('navBar').style.top + topOffset;
  dif = parseInt(dif/10);
  //alert(window.pageYOffset);alert(dif);
  if (isNaN(dif)) dif=0;
  //el.style.top = from + dif;
  //document.getElementById('navBar')el.style.top = 345;
}

//////// onLoad handler
function doLoad()
{
  window.setInterval("smoothMove()",20)

  divs = document.getElementsByTagName('div');
  for(var i=1; i<divs.length; i++)
  {
    el = divs[i];
    divs[i].style.color = "#c8c8c8";
  }
}

function barf()
{
  alert(document.getElementById('navBar').style.top);
}

function clearText(thefield)
{
  if(thefield.defaultValue==thefield.value)
  {
    thefield.value = ""
  }
}