document.observe('dom:loaded', function(event) {
    swfobject.embedSWF("/flash/header.swf", "flashcontent", "976", "97", "7", null, {}, {wmode:'transparent'});
});

var Slideshow = Behavior.create({
    initialize: function() {
        this.interval = setInterval(this.next.bind(this), 5000);
        this.show(this.element.down('div.show'));
    },
    next: function() {
        var show = this.showing.next('div.show') || this.element.down('div.show');
        this.hide();
        this.show(show);
    },
    hide: function() {
        this.showing.removeClassName('visible');
        new Effect.Fade(this.showing, { queue: 'end' });
    },
    show: function(show) {
        this.showing = show;
        show.addClassName('visible');
        new Effect.Appear(show, { queue: 'end' });
    }
});

Event.addBehavior({
    '#artist_list input#artist_name': function() {
      var artist_name_auto_completer = new Ajax.Autocompleter('artist_name', 'artist_name_auto_complete', '/artists/auto_complete_for_artist_name', {
        updateElement: function(li) {
          var href = li.down('a').readAttribute('href');
          document.location.href = href;
        }
      })
    },
    '#show_slideshow': Slideshow,
    'div.search input#artist_name': Gizmos.PromptingField,
    'p.about a.biography:click': function(event) {
        event.element().up('p.about').hide();
        event.element().up('p.about').next('div.bio_content').show();
        event.stop();
    },
    '#artist_list #tabs dt a:click': function(event) {
        var link = event.element();
        var dd = link.up('dt').next('dd');
        var dl = link.up('dl');
        $('artist_list').removeClassName('all').removeClassName('live').removeClassName('djs').removeClassName('speakers');
        if (dd.hasClassName('open')) {
            dd.removeClassName('open');
            dl.addClassName('closed');
        } else {
            link.up('dl').select('dd').invoke('removeClassName', 'open');
            dd.addClassName('open')
            $('artist_list').addClassName(link.up('dt').readAttribute('class'));
            dl.removeClassName('closed');
        }
        link.blur();
        event.stop();
    }
});