jQuery(document).ready( function () {
    // return generic hm url + arg
    var u = function (x) {
        return 'http://www.herald-mail.com/' + x;
    }
    // return url to section
    var s = function (id) {
        return u('?cmd=displaysection&format=html&section_id=' + id);
    };
    var index = [
        {
            name:   'Company',
            links:  [s(3), s(9), s(8), s(4), s(5)],
            titles: ['About Us', 'Advertise With Us', 'Careers', 'Contact Us', 'Terms of Use']
        },
        {
            name:   'Fine Print',
            titles: ['The Herald-Mail Company\n<br />100 Summit <abbr title="Avenue">Ave</abbr><br />Hagerstown, <abbr title="Maryland">MD</abbr> 21740', '(301) 733-5131', '&copy; 1996&ndash;2010 The Herald-Mail Company']
        },
        {
            name:   'Sections',
            links:  [s(10), s(30), s(20), s(23), u('?cmd=apt'), s(263), s(33), s(21), s(24), u('forums'), s(36), s(22), s(17), s(13), s(253), s(108), s(82), s(14), s(11), 'http://herald-mail.mycapture.com', s(74), s(31), s(110), s(49), 'http://www.allhagerstown.net', s(109)],
            titles: ['Arts &amp; Living', 'Blogs', 'Business', 'Celebrations', 'Classified', 'Cool Stuff', 'Editorials', 'Education', 'Entertainment', 'Forums', 'Games', 'Lifestyle', 'Local / Tristate', 'Magazines &amp; More', 'MD General Assembly', 'Multimedia', 'National / World', 'Obituaries', 'Opinion', 'Photo reprints', 'Pulse', 'Real Estate', 'Slideshows', 'Sports', 'THECalendar', 'Videos']
        },
        {
            name:   'Other H-M Sites',
            links:  ['http://www.allhagerstown.net', 'http://www.autofetchonline.com/', 'http://www.jobfetch.com/', 'http://www.searchthetristate.com/', 'http://www.shopthetristate.com/', 'http://www.washingtoncountyliving.com/', 'http://www.washingtoncountyweddings.com'],
            titles: ['allHagerstown.net', 'AutoFetch Online', 'JobFetch Online', 'Search the Tristate', 'Shop the Tristate', 'Washington County Living', 'Washington County Weddings']
        },
        {
            name:   'Feeds and Alerts',
            links:  [u('?cmd=users-preferences'), 'http://www.twitter.com/heraldmailnews', 'http://feeds2.feedburner.com/TheHerald-mailOnline?format=xml'],
            titles: ['Email Alerts', 'Follow Us on Twitter', 'RSS Feed']
        },
        {
            name:   'New Features',
            links:  [s(263), u('forums'), u('?cmd=archives-advanced')],
            titles: ['Cool Stuff', 'Forums back online', 'Improved search']
        },
        {
            name:   'Print Edition',
            links:  [s(6), 'https://cs.herald-mail.com/cgi-bin/cmo_cmo.sh/custservice/web/login.html', 'http://herald-mail.mycapture.com/mycapture/reprints.asp'],
            titles: ['Subscribe', 'Pay Online', 'Full page reprints']
        }
    ];
    var mama = document.getElementById('foot-content');
    var footBanner = document.getElementById('footer-banner');
    var el = document.createElement('div');
    for (var i = 0; i < index.length; i++) {
        var ul = document.createElement('ul');
        el.className = 'footer-column';
        for (var j = 0; j <= index[i].titles.length; j++) {
            var li = document.createElement('li');
            if (j === 0) {
                li.className = 'header';
                li.innerHTML = index[i].name;
            } else {
                if (index[i].links) {
                    li.innerHTML = '<a href="' + index[i].links[j-1] + '">' + index[i].titles[j-1] + '</a>';
                } else {
                    li.innerHTML = index[i].titles[j-1];
                    if (j > 1) {
                        li.className = 'padtop';
                    }
                }
            }
            ul.appendChild(li);
        }
        el.appendChild(ul);
        if (i === 1 || i === 2 || i === 4 || i === 6) {
            mama.insertBefore(el, footBanner);
            if (i < 5) {
                el = document.createElement('div');
            }
        }
    }
} );