window.addEvent('domready', function() {
    // Add dynamic input boxes
    var dynamicInput = new DynamicInput('input, textarea');

    // Add news ticker
    new Ticker('newsticker', {
        effect: {
            duration: 500
        }
    });

    // Setup slideshows
    $$('#advertisement .slideshow').each(function(element) {
        new Slideshow.Controlled({
            container: element,
            elements: 'li',
            wait: 6000,
            duration: 1250,
            transition: Fx.Transitions.linear,
            autoStart: true,
            controlsContainer: new Element('li', {
                'class': 'navigation'
            })
        });
    });

    /* Add focussed style to .round element */
    $$('.round input, .round textarea').addEvents({
        'focus': function() { this.getParent().addClass('focussed'); },
        'blur': function() { this.getParent().removeClass('focussed'); }
    });

    /* Open links in new window */
    $$(document.links).filter(function(a) {
        // Only open link in new window if:
        // - link doesn't already have a target
        // - the domain is different
        // - the link has the class 'external'
        return !a.getProperty('target') &&
               (a.href.test('^http', 'i') && !a.href.test('^' + document.location.href.substring(0, document.location.href.indexOf('/', 8)), 'i')) ||
               a.hasClass('external');
    }).setProperty('target', '_blank');
});
