
// start PrintPage
var PrintPage = Class.create (
{
    initialize: function(link)
    {
        this.link = link;
        Event.observe(this.link, 'click', this.__Click.bindAsEventListener(this));
    },
    __Click: function(e)
    {
        var e = e || window.event;
        Event.stop(e);
        var element = Event.element(e);
        if (window.print){window.print();}
    }

});
// end PrintPage

// start TextareaMaxlength
var TextareaMaxlength = Class.create (
{
    initialize: function(textarea, maxlength)
    {
        this.textarea = textarea;
        this.maxlength = maxlength;
        Event.observe(this.textarea, 'keyup', this.__Key.bindAsEventListener(this));
    },
    __Key: function(e)
    {
        var e = e || window.event;
        Event.stop(e);
        var element = Event.element(e);
        this.enforce();
    },
    enforce: function()
    {
        if ($F(this.textarea).length >= this.maxlength)
        {
            this.textarea.value = $F(this.textarea).substring(0, this.maxlength);
        }
    }

});
// end TextareaMaxlength

// start PopupWindow
var PopupWindow = Class.create (
{
    initialize: function(link, width, height, extras)
    {
        this.winName = 'popup';
        this.altWidth = 640;
        this.altHeight = 480;
        this.altExtras = 'location=yes,menubar=yes,statusbar=yes,toolbar=yes,scrollbars=yes,resizable=yes';
        this.link = link;
        this.url = link.getAttribute('href');
        this.w = width || this.altWidth;
        this.h = height || this.altHeight;
        this.x = extras || this.altExtras;
        this.features = 'width=' + this.w + ',height=' + this.h + ',' + this.x;
        Event.observe(this.link, 'click', this.__Click.bindAsEventListener(this));
    },
    __Click: function(e)
    {
        var e = e || window.event;
        Event.stop(e);
        var element = Event.element(e);
        var win = window.open(this.url, this.winName, this.features);
        win.focus();
    }
});
// end PopupWindow

// start ClosePopup
var ClosePopup = Class.create (
{
    initialize: function(link)
    {
        this.link = link;
        Event.observe(this.link, 'click', this.__Click.bindAsEventListener(this));
    },
    __Click: function(e)
    {
        var e = e || window.event;
        Event.stop(e);
        var element = Event.element(e);
        window.close();
    }

});
// end ClosePopup

// start FlyoutNav
var FlyoutNav = Class.create (
{
    initialize: function(nav)
    {
        this.nav = nav;
        this.navnodes = nav.childElements();
        for(var i=0; i<this.navnodes.length; i++)
        {
            Event.observe(this.navnodes[i], 'mouseover', function()
            {
                this.addClassName('over');
            });
            Event.observe(this.navnodes[i], 'mouseout', function()
            {
                this.removeClassName('over');
            });
            //Event.observe(this.navnodes[i], 'mouseover', this.__Mouseover.bindAsEventListener(this));
            //Event.observe(this.navnodes[i], 'mouseout', this.__Mouseout.bindAsEventListener(this));
        }
    },
    __Mouseover: function(e)
    {
        var e = e || window.event;
        var element = Event.findElement(e, 'li');
        element.addClassName('over');
    },
    __Mouseout: function(e)
    {
        var e = e || window.event;
        var element = Event.findElement(e, 'li');
        element.removeClassName('over');
    }
});
// only needed for IE6, place in head inside IE6 conditional comment
/*
document.observe('dom:loaded', function()
{
    doSiteNavFlyout = new FlyoutNav( $('mainnav') );
});
*/
// end FlyoutNav


// ********************************************************
// below: old-school JS, may still be useful for reference.
// ********************************************************

// start: misc

function printPage()
{
    if (window.print){window.print();}
}

function hide(element)
{
	document.getElementById(element).style.display = 'none';
	return;
}
function show(element)
{
	document.getElementById(element).style.display = 'block';
	return;		
}

// end: misc

// start: popup window
// usage: popuplink(['js-only url',] this[, w[, h[, scroll[, extras]]]])
// basic usage: <a href="popup.html" target="_blank" onclick="return(popuplink(this));">new pop</a>
// advanced usage: <a href="popup_nojs.html" target="_blank" onclick="return(popuplink('popup_yesjs.html', this, 200, 100, false));">new pop</a>
// site-wide defaults:
popup_w = 400;
popup_h = 300;
popup_scroll = true;
popup_extras = 'location=0,statusbar=0,menubar=0';
function popuplink() {
	var undef, i=0, args=popuplink.arguments;
	var url = (typeof(args[i])=='string') ? args[i++] : args[i].getAttribute('href');
	var target = args[i++].getAttribute('target') || '_blank';
	var w = args[i++];
	var h = args[i++];
	var s = (args[i]===undef) ? popup_scroll : args[i++];
	var features = 'width=' + (w || popup_w)
				 + ',height=' + (h || popup_h)
				 + ',scrollbars=' + (s ? 'yes,' : 'no,')
				 + (args[i] || popup_extras);
	var win = window.open(url, target, features);
	win.focus();
	return false;
}
// end: popup window

