// Browser Object
// WindowListener Object
// NS4css Object
// ElementHelper Object
// Tween Class
// Ease Object
// Element Class
// MenuGroup Class
// Menu Class
// SwapImage Class
// DualRollover Class
// Ticker Class
// BlurAnchors Object
// SpecializedCenter Object

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// Browser Object

function Browser () {
	var ua = navigator.userAgent.toLowerCase();
	this.win = ua.indexOf ("win") != -1;
	this.mac = ua.indexOf ("mac") != -1;
	this.dom = document.getElementById;
	this.iedom = document.all;
	this.ns4dom = document.layers;
	this.gecko = ua.indexOf ("gecko") != -1;
	this.safari = ua.indexOf ("safari") != -1;
}
var Browser = new Browser();

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// WindowListener Object

var WindowListener = new Object();
WindowListener.funcs = new Object();

WindowListener.addEvent = function (event) {
	var self = this;
	window["on" + event] = function(){self.run (event)};
	this.funcs[event] = new Array();
}
WindowListener.run = function (event) {
	var e = this.funcs[event];
	for (var i = 0; i < e.length; i ++) {
		eval (e[i]);
	}
}
WindowListener.addListener = function (event, func) {
	var e = this.funcs[event];
	var key = e.length;
	e[key] = func;
	return key;
}
WindowListener.removeListener = function (event, key) {
	var e = this.funcs[event];
	e[key] = null;
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

WindowListener.addEvent ("load");
WindowListener.addEvent ("resize");

window.loaded = false;
WindowListener.addListener ("load", "window.loaded = true");

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// NS4css Object

var NS4css = new Object();
NS4css.width = window.innerWidth;
NS4css.height = window.innerHeight;

NS4css.fix = function () {
	if (this.width != window.innerWidth || this.height != window.innerHeight) {
		window.location.reload();
	}
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

if (document.layers) WindowListener.addListener ("resize", "NS4css.fix()");

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// ElementHelper Object

var ElementHelper = new Object();

ElementHelper.getObject = function (idname) {
	var e = null;
	if (document.getElementById) var e = document.getElementById (idname);
	else if (document.all) var e = document.all[idname];
	else if (document.layers) var e = this.findLayer (idname);
	return e;
}
ElementHelper.getStyle = function (idname) {
	var e = this.getObject (idname);
	if (e) return document.layers ? e : e.style;
	else return null;
}
ElementHelper.findLayer = function (idname, root) {
	var i, layer, found = null;
	if (!root) root = window;
	for (i = 0; i < root.document.layers.length; i++) {
		layer = root.document.layers[i];
		if (layer.id == idname) return layer;
		if (layer.document.layers.length) found = this.findLayer (idname, layer);
		if (found) return found;
	}
	return null;
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// Tween Class

Tween = function (getter, setter, ease) {
	this.getter = getter;
	this.setter = setter;
	this.ease = ease;
	this.interval = null;
	this.onComplete = function(){};
	this.obj = "TweenInstance_" + (++ Tween.instance);
	eval (this.obj + "=this");
}
Tween.instance = 0;

Tween.prototype.tween = function (end, duration) {
	this.clear ();
	this.end = end;
	this.duration = duration;
	this.elapsed = 0;
	this.start = this.getter ();
	this.difference = this.end - this.start;
	this.doTween ();
	this.interval = setInterval (this.obj + ".doTween()", 50);
}
Tween.prototype.doTween = function () {
	if (this.elapsed ++ < this.duration) {
		this.setter (this.ease (this.elapsed, this.start, this.difference, this.duration));
	} else {
		this.setter (this.end);
		this.clear ();
		this.onComplete ();
	}
}
Tween.prototype.clear = function () {
	clearInterval (this.interval);
	this.interval = null;
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// Ease Object

var Ease = new Object ();

Ease.outQuad = function (t, b, c, d) {
	return -c * (t /= d) * (t - 2) + b;
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// Element Class

function SafeElement (idname) {
	if (ElementHelper.getObject (idname)) return new Element (idname);
	else return false;
}

Element = function (idname) {
	this.el = ElementHelper.getObject (idname);
	this.css = ElementHelper.getStyle (idname);	
	this.obj = "ElementInstance_" + idname;
	eval (this.obj + "=this");
	var self = this;
	this.leftTween = new Tween (function(){return self.getLeft()}, function(left){self.setLeft(left)}, Ease.outQuad);
	this.topTween = new Tween (function(){return self.getTop()}, function(top){self.setTop(top)}, Ease.outQuad);
	this.idname = idname;
}

// Top
Element.prototype.getTop = function () {
	return parseInt (this.css.top) || 0;
}
Element.prototype.setTop = function (top) {
	this.css.top = document.layers ? top : top + "px";
}

// Top Tween
Element.prototype.tweenTop = function (end, duration) {
	this.topTween.tween (end, duration);
}
Element.prototype.setTopTweenCallback = function (callback) {
	this.topTween.onComplete = callback;
}

// Left
Element.prototype.getLeft = function () {
	return parseInt (this.css.left) || 0;
}
Element.prototype.setLeft = function (left) {
	this.css.left = document.layers ? left : left + "px";
}

// Left Tween
Element.prototype.tweenLeft = function (end, duration) {
	this.leftTween.tween (end, duration);
}
Element.prototype.setLeftTweenCallback = function (callback) {
	this.leftTween.onComplete = callback;
}

// Width
Element.prototype.getWidth = function () {
	return (document.layers) ? this.el.clip.width || this.el.document.width : this.el.offsetWidth;
}

// Height
Element.prototype.getHeight = function () {
	return (document.layers) ? this.el.clip.height || this.el.document.height : this.el.offsetHeight;
}

// Visibility
Element.prototype.hide = function () {
	this.css.visibility = "hidden";
}
Element.prototype.show = function () {
	this.css.visibility = "visible";
}

// Write
Element.prototype.setHTML = function (html) {
	if (document.layers) {
		this.el.document.open ("text/html");
		this.el.document.write (html);
		this.el.document.close();
	} else {
		//this.el.innerHTML = "";
		this.el.innerHTML = html;
	}
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// MenuGroup Class

MenuGroup = function (menuId) {
	this.menuElement = new Element (menuId);
	this.subItems = new Array ();
	this.baseTop = this.menuElement.getTop ();
}
MenuGroup.prototype.addSubItem = function (itemId, menuId) {
	var i = this.subItems.length;
	this.subItems[i] = new Object ();
	this.subItems[i].itemElement = new Element (itemId);
	this.subItems[i].menuElement = (menuId != null) ? new Element (menuId) : null;
	return i;
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
// Menu Class

Menu = function () {
	this.speed = 3;
	this.activeMenu = null;
	this.activeMenuHeight = null;
	this.activeIndex = null;
	this.activeSubIndex = null;
	this.menus = new Array();
	this.obj = "MenuInstance_" + (++ Menu.instance);
	eval (this.obj + "=this");
}
Menu.instance = 0;

Menu.prototype.addMenu = function (menuObj) {
	this.menus[this.menus.length] = menuObj;
	return this.menus.length - 1;
}
Menu.prototype.showMenu = function (index) {
	if (index == this.activeIndex) return;// don't allow the active menu to be close by clicking it again
	this.activeMenu = this.menus[index]; // pointer to the active menu's Element objects
	this.activeMenuHeight = this.activeMenu.subItems.length * this.activeMenu.subItems[0].itemElement.getHeight(); // height of the active sub menu
	var i; // index of top level menus
	var k; // index of 2nd level menu items
	var m; // reference to the current menu's Element objects
	var s; // reference to the current submenu item's Element object
	for (i = 0; i < this.menus.length; i ++) {// loop through top level menus
		m = this.menus[i];
		// tween top level menus
		var position = m.baseTop;
		if (i > index) position += this.activeMenuHeight;
		m.menuElement.tweenTop (position, this.speed);
		// tween 2nd level menu items
		for (k = 0; k < m.subItems.length; k ++) {// loop through 2nd level menu items of the current menu
			s = m.subItems[k].itemElement;
			s.setTop (m.baseTop + m.menuElement.getHeight());// position 2nd level menu items directly under the current menu
			if (i == index) {
				s.show();
				s.tweenTop (s.getTop() + (s.getHeight() * k), this.speed);
			} else {
				s.hide();
			}
		}
	}
	// hide previously active 3rd level menu
	if (this.activeSubIndex != null) {
		this.menus[this.activeIndex].subItems[this.activeSubIndex].menuElement.hide();
		this.activeSubIndex = null;
	}
	// save the active index
	this.activeIndex = index;
	// ugly hack
	SpecializedCenter.run();
}
Menu.prototype.showSub = function (index) {
	if (index != this.activeSubIndex) {
		var activeMenu = this.activeMenu;
		var activeSubitem = activeMenu.subItems[index].itemElement;
		var activeSubmenu = activeMenu.subItems[index].menuElement;
                var activeSubmenuHeight = 0;

                //
                // James: 12/10/2004 
                // menu items that are only 2 deep will not have a 
                // activeSubmenu object.  We need to check for null here to
                // avoid dereferencing a null reference.
                //
                if (activeSubmenu != null)
		    activeSubmenuHeight = activeSubmenu.getHeight();

		// tween top level menus
		for (var i = this.activeIndex + 1; i < this.menus.length; i ++) {
			var m = this.menus[i];
			m.menuElement.originalTop = m.menuElement.getTop();
			m.menuElement.tweenTop (m.baseTop + this.activeMenuHeight + activeSubmenuHeight, this.speed);
		}
		// tween 2nd level menu items
		for (var i = 0; i < activeMenu.subItems.length; i ++) {
			var s = activeMenu.subItems[i].itemElement;
			var position = activeMenu.baseTop + (s.getHeight() * (i + 1));
			if (i > index) position += activeSubmenuHeight;
			s.tweenTop (position, this.speed);
		}
		// tween 3rd level menu
                if (activeSubmenu != null) {
   		    activeSubmenu.setTop (activeMenu.baseTop);
		    activeSubmenu.tweenTop (activeMenu.baseTop + activeMenu.menuElement.getHeight() + (activeSubitem.getHeight() * (index + 1)), this.speed * 2);
		    activeSubmenu.show();
                }

		// close previous 3rd level menu
		if (this.activeSubIndex != null) {
			activeMenu.subItems[this.activeSubIndex].menuElement.hide();
		}
		// save the active sub index
		this.activeSubIndex = index;
		// ugly hack
		SpecializedCenter.run();
	}
}
Menu.prototype.autoOpen = function (menuIndex, submenuIndex) {
	this.showMenu (menuIndex);
	if (submenuIndex != null) setTimeout (this.obj + ".showSub(" + submenuIndex + ")", 1000);
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// SwapImage Class

SwapImage = function (imageName) {
	this.name = imageName;
	this.images = new Object();
	this.restoresrc = null;
	this.nest = null;
}
SwapImage.prototype.add = function (state, src) {
	this.images[state] = new Image();
	this.images[state].src = src;
}
SwapImage.prototype.swap = function (state) {
	var img = this.getImage();
	this.restoresrc = img.src;
	img.src = this.images[state].src;
}
SwapImage.prototype.restore = function () {
	if (this.restoresrc) {
		this.getImage().src = this.restoresrc;
		this.restoresrc = null;
	}
}
SwapImage.prototype.getImage = function () {// Private
	if (document.layers && this.nest == null) this.nest = this.getLayer();
	if (document.layers && this.nest != false){
		return this.nest.document.images[this.name];
	} else {
		return document.images[this.name];
	}
}
SwapImage.prototype.getLayer = function (root) {// Private
	var i, k, layer, found = false;
	if (!root) root = window;
	for (i = 0; i < root.document.layers.length; i++) {
		layer = root.document.layers[i];
		for (k = 0; k < layer.document.images.length; k++) {
			if (layer.document.images[k].name == this.name) {
				return layer;
			}
		}
		if (layer.document.layers.length) found = this.getLayer (layer);
		if (found) return found;
	}
	return false;
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// TextRollover Class
TextRollover = function (textId) {
        this.textElement = new Element (textId);
}                              

TextRollover.prototype.show = function (text) {
        this.textElement.setHTML ("<span style='vertical-align:middle;'>" +
                                  text + "<\/span>");
        this.textElement.show();
}

TextRollover.prototype.hide = function() {
        this.textElement.hide();
}           

// DualRollover Class

/*
DualRollover = function (descriptionId, imageName) {
	this.descriptionElement = new Element (descriptionId);
	this.imageName = imageName;
	this.active = false;
	this.descriptions = new Array();
	this.swap = new SwapImage (this.imageName);
}
DualRollover.prototype.add = function (descriptionText, imageSrc) {
	var i = this.descriptions.length;
	this.descriptions[i] = descriptionText;
	this.swap.add ("over" + i, imageSrc);
	return i;
}
DualRollover.prototype.over = function (index) {
	// double check that out() was triggered
	if (this.active) this.out();
	this.active = true;
	// swap the image
	//this.swap.swap ("over" + index);
	// display the description
	this.descriptionElement.setHTML ("<span style='vertical-align:middle;'>" + this.descriptions[index] + "<\/span>");
	this.descriptionElement.show();
}
DualRollover.prototype.out = function () {
	this.active = false;
	// clear the image and description
	//this.swap.restore ();
	this.descriptionElement.hide();
}
*/

DualRollover = function (descriptionId, imageName) {
        this.description = new TextRollover (descriptionId);
        this.imageName = imageName;
        this.active = false;
        this.descriptions = new Array();
        this.swap = new SwapImage (this.imageName);
} 

DualRollover.prototype.add = function (descriptionText, imageSrc) {
        var i = this.descriptions.length;
        this.descriptions[i] = descriptionText; 
        this.swap.add ("over" + i, imageSrc);
        return i;
}

DualRollover.prototype.over = function (index) {
        // double check that out() was triggered
        if (this.active) this.out();
        this.active = true;

        // swap the image
        //this.swap.swap ("over" + index);
        // display the description
        this.description.show (this.descriptions[index]);
}

DualRollover.prototype.out = function () {
        this.active = false;
        // clear the image and description
        //this.swap.restore();
        this.description.hide();
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// Ticker Class

Ticker = function (maskId, headlineId) {
	this.maskElement = new Element (maskId);
	this.headlineElement = new Element (headlineId);
	this.headlines = new Array();
	this.index = 0;
	this.interval = null;
	this.msec = 6000; // default speed
	this.obj = "TickerInstance_" + maskId;
	eval (this.obj + "=this");
}
Ticker.prototype.setSpeed = function (speed) {// in seconds
	this.msec = speed * 1000;
}
Ticker.prototype.add = function (text, url) {
	this.headlines[this.headlines.length] = [text, url];
}
Ticker.prototype.start = function () {
	this.headlineElement.setTop (-this.maskElement.getHeight());
	this.headlineElement.tweenTop (0, 15);
	var headline = this.headlines[this.index++ % this.headlines.length];
        if (headline != null) {
   	    this.headlineElement.setHTML ('<p><a href="' + headline[1] + '">' + headline[0] + "<\/a><\/p>");
        }
	this.interval = setTimeout (this.obj + ".start()", this.msec);
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// BlurAnchors Object

var BlurAnchors = new Object ();

BlurAnchors.run = function () {
	var a = document.getElementsByTagName ("a");
	for (var i = 0; i < a.length; i ++) {
		a[i].onfocus = function(){this.blur()};
	}
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

if (document.getElementsByTagName) WindowListener.addListener ("load", "BlurAnchors.run()");

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// -----------------------------------------------------------------------------
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

// SpecializedCenter Object

var SpecializedCenter = new Object();

SpecializedCenter.start = function () {

	// -----------------------------------------------------------
	// EDIT THESE PROPERTIES
	this.pageWidth = 770;
	this.imageElement = SafeElement ("rolloverImage");
	this.descriptionElement = SafeElement ("rolloverDescription");
	this.tickerElement = SafeElement ("tickerMask");
	// -----------------------------------------------------------

	this.menuOffset = SpecializedMenu.menu.menus[0].menuElement.getLeft();
	if (this.imageElement) this.imageOffset = this.imageElement.getLeft();
	if (this.descriptionElement) this.descriptionOffset = this.descriptionElement.getLeft();
	if (this.tickerElement) this.tickerOffset = this.tickerElement.getLeft();

	this.run();
}
SpecializedCenter.run = function () {
	if (this.timer) clearTimeout (this.timer);
	this.repeat = 0;
	this.doRun();
}
SpecializedCenter.doRun = function () {
	// get window width
	if (document.documentElement && document.documentElement.clientWidth) {
		var windowWidth = document.documentElement.clientWidth;// Explorer 6 strict
	} else if (document.body && document.body.clientWidth) {
		var windowWidth = document.body.clientWidth;// Explorer, Gecko
	} else {
		var windowWidth = window.innerWidth - 16;// Netscape 4
    	//if (document.height > window.innerHeight) windowWidth -= 16;
    }
	// get offset value
	var left = Math.floor ((windowWidth - this.pageWidth) / 2);
	if (Browser.gecko && !Browser.safari && windowWidth % 2 != 0) left += 1;
	if (left < 0) left = 0;
	// center menu
	var i, m, k, s;
	var menus = SpecializedMenu.menu.menus;
	for (i = 0; i < menus.length; i ++) {
		m = menus[i];
		m.menuElement.setLeft (left + this.menuOffset);
		for (k = 0; k < m.subItems.length; k ++) {
			s = m.subItems[k];
			s.itemElement.setLeft (left + this.menuOffset);
			if (s.menuElement) s.menuElement.setLeft (left + this.menuOffset);
		}
	}
	// center rollover image
	if (this.imageElement) this.imageElement.setLeft (left + this.imageOffset);
	// center rollover description
	if (this.descriptionElement) this.descriptionElement.setLeft (left + this.descriptionOffset);
	// center ticker
	if (this.tickerElement) this.tickerElement.setLeft (left + this.tickerOffset);
	// repeat a few times for good luck
	if (++ this.repeat < 5 && !Browser.ns4dom) {
		this.timer = setTimeout ("SpecializedCenter.doRun()", 500);
	}
}

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

//WindowListener.addListener ("load", "SpecializedCenter.start()");
WindowListener.addListener ("resize", "SpecializedCenter.run()");

// '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
