/*   
 * Written April 2000 by David Kim -- KScripts Web Consulting and Design -- unless stated otherwise 
 * Copyright 2000 Kscripts Web Consulting and Design, All rights reserved, please do not copy without consent
 * 
 * Contains a modified version of Flyout menus from the University of Washington Home Page
 * Documentation can be found at
 *     http://www.washington.edu/webinfo/case/flyout/
 */

//menu options
var menuStatus = "on";
var url = "/";
var expiration_days = 1;
function makeCookie (onoff) {
	expireDate = new Date;
	expireDate.setDate(expireDate.getDate()+expiration_days);
	document.cookie = "menuStatus=" + onoff +";expires="+expireDate.toGMTString()+"; path=" + url;
}
if (document.cookie != "") {
	menuStatus = document.cookie.split("=")[1]
}	
window.status = (menuStatus == "off" ? 'Submenus are turned off' : '');
function window_status (message) {
	window.status = message;
}
function menusetting () {
      menuStatus = (menuStatus == "on" ? "off" : "on");
	makeCookie (menuStatus);
	if (document.images) {
		document.images["menustatusimage"].src = (menuStatus == "on" ? menuOff : menuOn);
		window.status = (menuStatus == "off" ? 'Submenus are turned off' : '');
	}
}

if (document.images) {
  go_img = new Image;
  go_yellow_img = new Image;
  go_img.src = "images/go.gif";
  go_yellow_img.src = "images/go_yellow.gif";
}
	
function menuimgIn () {
	if (document.images) {
		document.images["menustatusimage"].src = (menuStatus == "on" ? menuOff : menuOn);
	}
}
function menuimgOut () {
	if (document.images) {
		document.images["menustatusimage"].src = menu;
	}		
}

// Reloads window if resized
if(!window.W) {
  window.onresize = resize;
  window.W = window.innerWidth;
  window.H = window.innerHeight;
}

function resize() {
    if (W < window.innerWidth ||
        W > window.innerWidth ||
        H > window.innerHeight ||
        H < window.innerHeight )
    {
        window.history.go(0);
    }
}

var Months = new Array(
	'January',
	'February',
	'March',
	'April',
	'May',
	'June',
	'July',
	'August',
	'September',
	'October',
	'November',
	'December'
	);

var current = new Date();

function getDate() {
	var day = current.getDate();
	var month = Months[current.getMonth()]; 
	var year = current.getYear();
	if(navigator.appName == 'Netscape') {
		year = year + 1900;
	}
	var todays_date = month + " " + day + ", " + year;
	return todays_date;
}

//  Modified version of Flyout menus from the University of Washington Home Page
var d = document;
var doDHTML = 0;

if (d.layers || d.all) {
    doDHTML = 1;

    initFlyLyr ();
    initToShow ();
    initDelay ();

    d.write ("<style type='text/css'>" +
		".flyout { visibility: hidden; position: absolute; " +
		"left: 0; top: 0; }<\/style>");
}

function makeLayer (id, title) {
    if (! doDHTML)
	return;
 
    var a = arguments;
    var numsp = new Array;
    numsp.max = 0;
    for (var j = 2; j < a.length; ++j) {
	numsp[j] = a[j].length;
	a[j] = a[j].replace (/^ +/, '');
	numsp[j] -= a[j].length;
	numsp.max = Math.max (numsp[j], numsp.max);
    }
    var fd = FlyLyr.defs;
    d.write ("<div id='l_" + id + "' class='flyout'>" +  
		"<table cellpadding='5' cellspacing='0' border='0' background='" + //added background
		fd.background + "' bordercolor='" + fd.border + "'>");
    var divstart = "<tr><td><table cellpadding='1' cellspacing='0' " +
		    "border='0'>\n";  // took out title option
    d.write (divstart);
    for (j = 2; j < a.length; ++j) {
	if (! a[j]) {
	    d.write ("<\/table><\/td><\/tr>" + divstart);
	    continue;
	}
	var args = null;
	var i = numsp[j];
	if (i < numsp.max)
	    args = "colspan=" + (numsp.max - i + 1);
	d.write ("<tr>");
	while (i-- > 0)
	    d.write ("<td><font size='1'>&nbsp;&nbsp;<\/font><\/td>");
	d.write (buildCell (a[j], fd.useclass, args) + "<\/tr>\n");
    }
    d.write ("<\/table><\/td><\/tr><\/table><\/div>\n");
    new FlyLyr (id);
}

function buildCell (str, fc, args) {
    var retstr = "<td";
    if (args)
	retstr += " " + args;
    var eqpos = str.indexOf ("=");
    if (eqpos > 0)
	retstr += "><a href='" + str.substr (eqpos + 1) + "' class='" + fc + "'>"  //added class for link
        + str.substr (0, eqpos) + "<\/a>";
    else
	retstr += " class='navheading'>" + str; //added navheading class
    return retstr + "<\/td>";
}

function positionLayerNS () {
    var img = this.image;
    var ypos = img.y + img.height;
    this.lyr.moveTo (img.x + img.width, ypos);  //took out layer movement if cut off by window
}

function positionLayer () {
    var img = this.image;
    var xpos = 5;
    var ypos = img.height;  //took out layer movement if cut off by window
    if (FlyLyr.usepos['startX'])
	xpos += FlyLyr.usepos['startX'];
    if (FlyLyr.usepos['startY'])
	ypos += FlyLyr.usepos['startY'];
    for (; img && img.parentElement; img = img.parentElement)
	if (FlyLyr.usepos[img.tagName]) {
	    xpos += img.offsetLeft;
	    ypos += img.offsetTop;
	}
    this.lyr.style.pixelLeft = xpos;
    this.lyr.style.pixelTop = ypos;
    if (this.tbl)
	this.lyr.style.clip = 'rect ( 0px ' + this.tbl.offsetWidth + 'px ' +
				this.tbl.offsetHeight + 'px 0px )';
}

function FlyLyr (id) {
    this.lyr = findObj ('l_' + id);
    if (! d.all) {
        this.lyr.captureEvents (Event.MOUSEOUT | Event.MOUSEOVER);
	this.lyr.bgColor = FlyLyr.defs.background;
    }
    this.lyr.onmouseover = function () {
	FlyLyr.showing.stopdelay ()
	ToShow.stopdelay ();
    };
    this.lyr.onmouseout = function () { mOut () };
    this.id = id;
    if (this.lyr.children && FlyLyr.unmacOffset)
	this.tbl = this.lyr.children[0];
    FlyLyr.lyrs[id] = this;
    for (var a in FlyLyr.defs)
	this[a] = FlyLyr.defs[a];
}

function flyDefs (defs) {
    if (! defs)
	return;
    for (var d in defs)
	FlyLyr.defs[d] = defs[d];
}

function initFlyLyr () {
    FlyLyr.prototype.doHide = function () {
	this.stopdelay ();
	this.realHide ();
	this.image.src = this.outimg;
	FlyLyr.showing = null;
    };
    FlyLyr.prototype.doShow = function () {
	if (! this.image && ! (this.image = findObj (this.id)))
	    return;
	this.position ();
	this.realShow ();
	this.image.src = this.overimg;
	FlyLyr.showing = this;
    };
    FlyLyr.prototype.delayCallback = function () {
	if (this == FlyLyr.showing)
	    this.doHide ();
    };
    FlyLyr.prototype.setdelay = function () {
	this.delay = new Delay (this.timeout, this);
    };
    FlyLyr.prototype.stopdelay = function () {
	if (this.delay)
	    this.delay.stop ();
	return this.delay;
    };

    FlyLyr.lyrs = new Object ();
    FlyLyr.defs = {
	background: '#ffffff',
	titlebackground: '#ffffff',
	border: '#ffffff',
	useclass: 'navheading',
	titleclass: 'navheading',
	overimg: '/default.gif',
	outimg: '/default.gif',
	pause: 0,
	timeout: 500
    }
    FlyLyr.unmacOffset = navigator.platform.indexOf ("Mac") != -1 ? 0 : 16;

    if (d.all) {
    	FlyLyr.prototype.realHide = function () {
    	    this.lyr.style.visibility = 'hidden';
	};
    	FlyLyr.prototype.realShow = function () {
    	    this.lyr.style.visibility = 'visible';
	};
    	FlyLyr.prototype.position = positionLayer;
	var vers = navigator.appVersion.split ("MSIE ");
	vers = vers[vers.length - 1];
	FlyLyr.usepos = {
	    'BODY': 1,
	    'IMG': 1,
	    'TABLE': 1,
	    'TD': 1
	};
	if (parseInt (vers) < 5)
	    FlyLyr.usepos["TR"] = 1;
	else if (! FlyLyr.unmacOffset) {
	    FlyLyr.usepos["startX"] = 8;
	    FlyLyr.usepos["startY"] = 12;
	}
    } else {
    	FlyLyr.prototype.realHide = function () {
    	    this.lyr.visibility = 'hide';
	};
    	FlyLyr.prototype.realShow = function () {
    	    this.lyr.visibility = 'show';
	};
    	FlyLyr.prototype.position = positionLayerNS;
    }
}

function ToShow (lyr) {
    if (! lyr || lyr == FlyLyr.showing)
	return;
    this.lyr = lyr;
    ToShow.stopdelay ();
    ToShow.queued = this;
    this.delay = new Delay (FlyLyr.defs.pause, this);
}

function initToShow () {
    ToShow.stopdelay = function () {
	var q = ToShow.queued;
	if (q) {
	    q.delay.stop ();
	    ToShow.queued = null;
	}
	return q;
    };
    ToShow.prototype.delayCallback = function () {
	ToShow.queued = null;
	if (FlyLyr.showing)
	    FlyLyr.showing.doHide ();
	if (this.lyr)
	    this.lyr.doShow ();
    };
}

function Delay (delay, obj) {
    this.obj = obj;
    var uid = ++Delay.nuid;
    this.timeoutid = setTimeout ('Delay.dispatch (' + uid + ')', delay);
    this.uid = uid;
    Delay.disparr[uid] = this;
}

function initDelay () {
    Delay.prototype.stop = function () {
	clearTimeout (this.timerid);
	delete Delay.disparr[this.uid];
    };
    Delay.dispatch = function (uid) {
	var item = Delay.disparr[uid];
	if (! item)
	    return;
	item.obj.delayCallback ();
	item.stop ();
    };
    Delay.nuid = 0;
    Delay.disparr = new Object;
}

function findObj (n, od) { // was MM_findObj v3.0 from Macromedia Dreamweaver
    var p, i, x;
    if (! od)
	od = d;
    if ((p = n.indexOf ("?")) > 0 && parent.frames.length) {
	od = parent.frames[n.substring (p + 1)].document;
	n = n.substring (0, p);
    }
    if (! (x = od[n]) && d.all)
	x = od.all[n];
    for (i = 0; ! x && i < od.forms.length; i++)
	x = od.forms[i][n];
    for (i = 0; ! x && od.layers && i < od.layers.length; i++)
	x = findObj (n, od.layers[i].document);
    return x;
}

function mIn (id) {
    if (! doDHTML || menuStatus == "off")
    	return;
    var lyr = FlyLyr.lyrs[id];
    if (! lyr)
	return;
    if (lyr == FlyLyr.showing)
	lyr.stopdelay ();
    else
	new ToShow (lyr);
}

function mOut () {
    if (! doDHTML || menuStatus == "off")
	return;
    var lyr = FlyLyr.showing;
    if (! ToShow.stopdelay () && lyr)
	lyr.setdelay ();
}
// end of flyout script from UW homepage

