window.addEvent("domready", function() {

    $$(".volatile").each(function(el) {
        $(el).addEvent("focus", function() {
            if (this.get("value") == this.get("title")) {
                this.value = "";
            }
        });
    });

    new SmoothScroll({ "links": $$(".scroll") });

    $$("a[rel*='external']").each(function(a) {
        $(a).setProperty("target", "_blank");
    });

    $$(".disable").addEvent("click", function(e) {
        new Event(e).stop();
    });

    if ($("calendarContent")) {

        var carousel = new SimpleSlideShow.Carousel($('calendarContent'), {
            startIndex: 0,
            slides: $$('#calendarContent li'),
            nextLink: 'calNext',
            prevLink: 'calPrev',
            wrap: false,
            disabledLinkClass: 'disabled'
        });


        carousel.addEvent('onSlideDisplay', function(num) {
            showEvent(num);
        });

        if ($$('#calendarContent li').length == 1) {
            $("calNext").set('styles', { 'display': 'none' });
        }
        showEvent(0);
    }

    if ($("sponsors")) {
        var mySlideShow = new SimpleSlideShow({
            startIndex: 0,
            slides: $$('#sponsors li'),
            wrap: true
        });

        function nextSponsor() {

            mySlideShow.forward();
            setTimeout(nextSponsor, 5000);
        }

        setTimeout(nextSponsor, 5000);
    }


    var myAccordion = new Accordion($$('.locationInner .title'), $$('.locationInner .bd'), {
        display: -1,
        alwaysHide: true,
        opacity: true,

        onActive: function(togglers) {
            togglers.addClass('selected');

        },
        onBackground: function(togglers) {
            togglers.removeClass('selected');
        }
    });

    $$(".locationInner .title").each(function(el) {
        el.addEvent("click", function(e) {
            new Event(e).stop();
        });
    });


    var passwordDisplay = -1;

    if ($$("#ForgottenPasswordForm .fielderror")[0]) {
        passwordDisplay = 0;
    }

    var myAccordion = new Accordion($$('.loginContainer .password'), $$('.requestPassword'), {
        display: passwordDisplay,
        duration: 0,
        alwaysHide: true,
        opacity: true
    });

    $$(".loginContainer .password").each(function(el) {
        el.addEvent("click", function(e) {
            new Event(e).stop();
        });
    });

});



function showEvent(num) {
    var visLink = $$('.upcomingList li')[0];
    var eventLinks = $$('#calendarContent li ._eventLink');
    if (eventLinks[num]) {
        visLink.innerHTML = eventLinks[num].innerHTML;
        visLink.href = eventLinks[num].href;
    }
    if (num == 0) {
        $("calPrev").set('styles', { 'display': 'none' });
    } else {
        $("calPrev").set('styles', { 'display': 'block' });
    }
}
