/*
This file and its contents are (c) Angus Turnbull, 2004. All Rights Reserved.

I don't mind if you view this to see how it works, but please ask me before copying significant
portions into your own scripts.

Copying this entire file and using it on other websites is EXPRESSLY FORBIDDEN.
Instead, get a new copy of the "FreeStyle Menu" script from my site, which is what I use here,
and come up with an original design!
*/


var isDOM=document.getElementById?1:0,isIE=document.all?1:0,isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,isOp=self.opera?1:0,isDyn=isDOM||isIE||isNS4;function getRef(i,p){p=!p?document:p.navigator?p.document:p;return isIE?p.all[i]:isDOM?(p.getElementById?p:p.ownerDocument).getElementById(i):isNS4?p.layers[i]:null};function getSty(i,p){var r=getRef(i,p);return r?isNS4?r:r.style:null};if(!self.LayerObj)var LayerObj=new Function('i','p','this.ref=getRef(i,p);this.sty=getSty(i,p);return this');function getLyr(i,p){return new LayerObj(i,p)};function LyrFn(n,f){LayerObj.prototype[n]=new Function('var a=arguments,p=a[0],px=isNS4||isOp?0:"px";with(this){'+f+'}')};LyrFn('x','if(!isNaN(p))sty.left=p+px;else return parseInt(sty.left)');LyrFn('y','if(!isNaN(p))sty.top=p+px;else return parseInt(sty.top)');function FSMenu(myName,nested,cssProp,cssVis,cssHid){this.myName=myName;this.nested=nested;this.cssProp=cssProp;this.cssVis=cssVis;this.cssHid=cssHid;this.cssLitClass='';this.menus={root:new FSMenuNode('root',this)};this.menuToShow=[];this.mtsTimer=null;this.showDelay=0;this.hideDelay=500};FSMenu.prototype.show=function(mN){with(this){menuToShow=arguments;clearTimeout(mtsTimer);mtsTimer=setTimeout(myName+'.menus.root.over()',10)}};FSMenu.prototype.hide=function(mN){with(this){clearTimeout(mtsTimer);if(menus[mN])menus[mN].out()}};function FSMenuNode(id,obj){this.id=id;this.obj=obj;this.lyr=this.child=this.args=this.par=this.timer=null;var node=this;this.over=function(evt){with(node)with(obj){if(isNS4&&evt&&lyr.ref)lyr.ref.routeEvent(evt);clearTimeout(timer);if(menuToShow){clearTimeout(mtsTimer);var a=menuToShow,m=a[0];menuToShow=null;if(!menus[m]||!menus[m].lyr.ref)menus[m]=new FSMenuNode(m,obj);var c=menus[m];if(c==node)return;clearTimeout(c.timer);if(c!=child&&c.lyr.ref){c.args=a;c.par=node;if(showDelay)c.timer=setTimeout(myName+'.menus["'+c.id+'"].show()',showDelay);else c.show()}}if(!nested&&par)par.over()}};this.out=function(evt){with(node)with(obj){if(isNS4&&evt&&lyr&&lyr.ref)lyr.ref.routeEvent(evt);clearTimeout(timer);timer=setTimeout(myName+'.menus["'+id+'"].hide()',hideDelay);if(!nested&&par)par.out()}};if(id!='root')with(this)with(lyr=getLyr(id))if(ref){if(ref.addEventListener){ref.addEventListener('mouseover',this.over,false);ref.addEventListener('mouseout',this.out,false)}else{ref.onmouseover=this.over;ref.onmouseout=this.out}}};FSMenuNode.prototype.show=function(){with(this)with(obj){if(!par)return;if(par.child&&par.child!=this)par.child.hide();par.child=this;var offR=args[1];if(offR&&cssLitClass&&!isNS4)offR.className+=(offR.className?' ':'')+cssLitClass;lyrVis(1)}};FSMenuNode.prototype.hide=function(){with(this)with(obj){if(!par)return;if(args[1]&&cssLitClass&&!isNS4)args[1].className=args[1].className.replace(new RegExp('\\s*'+cssLitClass+'$'),'');if(lyr)lyrVis(0);if(child)child.hide();if(par&&par.child==this)par.child=null;par=null}};FSMenuNode.prototype.lyrVis=function(sh){with(this)with(obj){lyr.timer|=0;lyr.counter|=0;with(lyr){clearTimeout(timer);if(sh)sty[cssProp]=cssVis;sty.zIndex=1000+sh;lyr.alpha(counter==100?null:counter);counter+=10*(sh?1:-1);counter+=10*(sh?1:-1);if(counter>100){counter=100}else if(counter<0){counter=0;sty[cssProp]=cssHid}else timer=setTimeout(myName+'.menus["'+id+'"].lyrVis('+sh+')',50)}}};LyrFn('alpha','var f=ref.filters,d=(p==null),o=d?"inherit":p/100;if(f){if(!d&&sty.filter.indexOf("alpha")==-1)sty.filter+=" alpha(opacity="+p+")";else if(f.length&&f.alpha)with(f.alpha){if(d)enabled=false;else{opacity=p;enabled=true}}}else if(isDOM)sty.opacity=sty.MozOpacity=o;');


// Create menu object.
var menu = new FSMenu('menu', true, 'visibility', 'visible', 'hidden');
menu.cssLitClass = 'highlighted';
menu.showDelay = 150;

// Menu locking/floating.
var menuFloat = 0;
var menuFixed = !isIE || isOp;


function setEvent(obj, evt, fn)
{
 if (obj.addEventListener) obj.addEventListener(evt, fn, false);
 else obj['on' + evt] = fn;
}


function loadHandler()
{
 if (!isDOM) return;

 // Menu activation & linking.
 var a, ul, m = getRef('menuroot'), nodes, count = 1;
 var items = m.getElementsByTagName('li');
 for (var i = 0; i < items.length; i++)
 {
  nodes = items[i].childNodes;
  if (!nodes) continue;
  a = ul = null;
  if (nodes) for (var n = 0; n < nodes.length; n++)
  {
   if (!nodes[n].nodeName) continue;
   if (nodes[n].nodeName == 'A') a = nodes[n];
   if (nodes[n].nodeName == 'UL') ul = nodes[n];
   if (a && ul)
   {
    var menuID = 'menu-id-' + count++;
    setEvent(a, 'mouseover', new Function('menu.show("' + menuID + '", this)'));
    setEvent(a, 'mouseout', new Function('menu.hide("' + menuID + '")'));
    ul.setAttribute('id', menuID);
    var subI = document.createElement('span');
    if (subI)
    {
     subI.appendChild(document.createTextNode('>'));
     subI.className = 'subind';
     a.appendChild(subI);
    }
   }
  }
 }

 // "Lock/Float menu" element.
 if (document.createTextNode)
 {
  var ml = document.createElement('span');


  m.appendChild(ml);

 }

 // IE5+/Win,Moz,Safari,Op>6,etc... only past this point.
 if (!document.documentElement || (isIE && !isOp && (navigator.userAgent.indexOf('Mac') > -1))) return;

 // H1 Animation hook.
 h1Setup();

 // Titles -> display area.
 var lt = document.createElement('div');
 lt.setAttribute('id', 'linktitle');
 getRef('navigation').appendChild(lt);
 setEvent(m, 'mouseover', new Function('e', 'e=e||window.event; menu.menus.root.over();' +
  'var lt=getRef("linktitle"); if (lt) { while (lt.firstChild) lt.removeChild(lt.firstChild);' +
  'e=e.target||e.srcElement; while(e&&!e.title) e=e.parentNode;' +
  'if (e && e.getAttribute) lt.appendChild(document.createTextNode(e.getAttribute("title"))) }'));
 setEvent(m, 'mouseout', new Function('e',
  'var lt=getRef("linktitle"); if (lt) while (lt.firstChild) lt.removeChild(lt.firstChild)'));

 // Create zoom boxes.
 var pZoom = document.createElement('div');
 pZoom.setAttribute('id', 'pagezoom');
 var zControls = [['+', 'Zoom In', 'zoom(1)'], ['0', 'Restore Original Zoom', 'zoom(0)'],
  ['-', 'Zoom Out', 'zoom(-1)']];
 for (var c in zControls)
 {
  var tmp = document.createElement('span');
  tmp.appendChild(document.createTextNode(zControls[c][0]));
  tmp.setAttribute('title', zControls[c][1]);
  setEvent(tmp, 'click', new Function(zControls[c][2]));
  setEvent(tmp, 'mouseover', new Function('this.className = "zoomHover"'));
  setEvent(tmp, 'mouseout', new Function('this.className = ""'));
  pZoom.appendChild(tmp);
 }


};

// Because Safari sucks sometimes.
if (navigator.userAgent.indexOf('KHTML') > -1) var safHack = setInterval(
 'if (document.readyState == "complete") { clearInterval(safHack); loadHandler() }', 100);
else setEvent(window, 'load', loadHandler);




// <h1> fading effect :).
var h1Arr = [];
function h1Setup()
{
 h1Arr = document.getElementsByTagName('h1');
 for (var h = 0; h < h1Arr.length; h++)
 {
  var h1 = h1Arr[h], text = h1.firstChild.nodeValue;
  h1.removeChild(h1.firstChild);
  h1.animNodes = [];
  for (var i = 0; i < text.length; i++)
  {
   var span = document.createElement('span');
   span.appendChild(document.createTextNode(text.substring(i, i+1)));
   h1.appendChild(span);
   h1.animNodes[h1.animNodes.length] = span;
  }
  h1.animCount = 0;
  h1.animTimer = setInterval('h1Anim(' + h + ')', 50);
 }
};
function h1Anim(h)
{
 var h1 = h1Arr[h], c = h1.animCount++, noAnim = 1;
 for (var i = 0; i < h1.animNodes.length; i++)
 {
  var s = h1.animNodes[i];
  var frac = Math.max(0, Math.min(1, (c-i)/10));
  if (s.animDone) continue;
  noAnim = 0;
  s.style.color = 'rgb(' + parseInt(255-255*frac) + ',' +
   parseInt(255-111*frac) + ',' + parseInt(255-111*frac) + ')';
  if (frac == 1)
  {
   s.style.marginLeft = 'auto';
   s.animDone = 1;
  }
  else if (frac > 0) s.style.marginLeft = 0.6*(1-frac) + 'em';
 }
 if (noAnim) clearInterval(h1.animTimer);
 h1.style.visibility = 'visible';
};


// Page zoom.
var zoomVal = 0;
function zoom(val)
{
 if (!document.body || !document.body.style) return;
 zoomVal = (val ? zoomVal + val : 0);
 document.body.style.fontSize = (80 + zoomVal*10) + '%';
}


if (isDOM && document.documentElement)
{
 // Hide H1 elements for animation. Yeah, I know document.write sucks.
 document.write('<style type="text/css"> h1 { visibility: hidden } </style>');
}
