﻿function runOnLoad(f) {
    if (runOnLoad.loaded) f();
    else runOnLoad.funcs.push(f);
}
runOnLoad.funcs = [];
runOnLoad.loaded = false;

runOnLoad.run = function() {
    if (runOnLoad.loaded) return;
    for (var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch (e) { /* An exception in one function shouldn't stop the rest */ }
    }
    runOnLoad.loaded = true;
    delete runOnLoad.funcs;
    delete runOnLoad.run;
};
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;

runOnLoad(function() {
    $('#promotions').cycle({
        fx: 'scrollHorz',
        speed: 'slow',
        timeout: 10000,
        pager: '#promotions-nav',
        prev: '#promotions-prev',
        next: '#promotions-next'
    });
    LoadListItems('NewsAndEvents');
});

function LoadListItems(type) {
    $('#recent-news-content').load('/_layouts/AJAXListHandler.ashx?type=' + type + '&count=5'); //&timestamp=' + new Date().getTime());
    var cl;
    switch (type) { case 'NewsAndEvents': cl = '.recent-news-events'; break; case 'Publications': cl = '.recent-publications'; break; case 'PublicNotices': cl = '.recent-public-notices'; break; }
    var n = $(cl);
    n.parent().children().children().removeClass('selected');
    n.children('a').addClass('selected');
}