﻿//Functions to run on page load
var Site = {
	start: function() {
	    ExternalLinks.start();
	    ExpandForm.start();
    }
};

//XHTML compliant way of doing _blank
var ExternalLinks = {
    start: function() {
        if (!document.getElementsByTagName) return;
        var anchors = document.getElementsByTagName('a');
        for (var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            try {
            if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
                anchor.target = '_blank';
            }catch(err) {}
        }
    }
};

var ExpandForm = {
    start: function() {
        var form = $('form');
        if (!form.hasClassName('donotclose')) {        
            form.style.height = 0;
            form.style.overflow = 'hidden';
            form.style.padding = 0;}
         
        var expandLink = $('expandlistlink');
        expandLink.href = "javascript:void(0);";
        Event.observe(expandLink, 'click', function() {
            ExpandForm.doExpand(expandLink);
        });
        //This is to make the action device independent
        Event.observe(expandLink, 'keypress', function() {
            ExpandForm.doExpand();
        });
    },
    doExpand: function() {
        var expandLink = $('expandlistlink');
        expandLink.stopObserving('click');
        expandLink.stopObserving('keypress');
        
        var form = $('form');
        var scrollHeight= form.scrollHeight + 70;
        
        new Effect.Morph(form,{
            style:'height:' + scrollHeight + 'px;overflow:visible;',
            duration:2.0
        });
    }
};

Event.observe(window, "load", Site.start);