var wjhu = function() { };

wjhu.Strings = {
  BASE_URL: 'http://webhost5.nts.jhu.edu/wjhu',
  LISTEN_FILE: '/listen.php',
  LISTEN_6DJS: 'http://128.220.65.93:8000/listen.m3u',
  SCHED_FILE: '/schedule.htm',
  ABOUT_FILE: '/about.htm',
  JOIN_FILE: 'http://www.wjhuradio.com/blog'
};

wjhu.setIndexListeners = function() {
  $('#schedule').click(function() { window.location = wjhu.Strings.BASE_URL +
      wjhu.Strings.SCHED_FILE; });
  $('#jam').click(function() { window.location = "http://www.wjhuradio.com/6djs" });
  $('#6djs').click(function() { window.locatoin = wjhu.Strings.LISTEN_6DJS });
  $('#about').click(function() { window.location = wjhu.Strings.BASE_URL +
      wjhu.Strings.ABOUT_FILE; });
  $('#join').click(function() { window.location = wjhu.Strings.JOIN_FILE; });
};

wjhu.setupJoin = function() {
  $('div.title').prepend('<span class="expand">+</span>');
  $('div.title.active > span.expand').remove();
  $('div.title.active').prepend('<span class="expand">-</span>');
  $('#dj').click(function() { wjhu.toggle('#dj'); });
  $('#mdir').click(function() { wjhu.toggle('#mdir'); });
  $('#tdir').click(function() { wjhu.toggle('#tdir'); });
  $('#scast').click(function() { wjhu.toggle('#scast'); });
  $('#ncast').click(function() { wjhu.toggle('#ncast'); });
};

wjhu.setupAbout = function() {
  $('div.title').prepend('<span class="expand">+</span>');
  $('div.title.active > span.expand').remove();
  $('div.title.active').prepend('<span class="expand">-</span>');
  $('#dir').click(function() { wjhu.toggle('#dir'); });
  $('#staff').click(function() { wjhu.toggle('#staff'); });
};

wjhu.setupSchedule = function() {
  $('div.title').prepend('<span class="expand">+</span>');
  $('#sun').click(function() { wjhu.toggle('#sun'); });
  $('#mon').click(function() { wjhu.toggle('#mon'); });
  $('#tues').click(function() { wjhu.toggle('#tues'); });
  $('#wed').click(function() { wjhu.toggle('#wed'); });
  $('#thurs').click(function() { wjhu.toggle('#thurs'); });
  $('#fri').click(function() { wjhu.toggle('#fri'); });
  $('#sat').click(function() { wjhu.toggle('#sat'); });
};

wjhu.toggle = function(id) {
  var title = $(id);
  var title_expander = $(id + ' > span.expand');
  var desc = $(id + '_d');
  if (title.hasClass('active')) {
    title_expander.text('+');
    desc.slideUp();
    desc.removeClass('active');
    title.removeClass('active');
  } else {
    var active = $('div.title.active');
    if (active.length) {
      wjhu.toggle('#' + active.attr('id'));
    }
    title_expander.text('-');
    desc.slideDown();
    desc.addClass('active');
    title.addClass('active');
  }
};

wjhu.soundTimer = function() { this.resetDelay = 600000 /* 10 minutes */ };

wjhu.soundTimer.prototype.start = function() {
  this.timerID = window.setInterval(this.checkStatus_, this.resetDelay);
};

wjhu.soundTimer.prototype.stop = function() {
  window.clearInterval(this.timerID);
};

wjhu.soundTimer.prototype.checkStatus_ = function() {
  if (soundManager.getSoundById('wjhuRadio')) {
    soundManager.stopAll();
    soundManager.destroySound('wjhuRadio');
    soundManager.createSound('wjhuRadio',
      'http://128.220.253.157:8000/;');
    soundManager.play('wjhuRadio');
  }
};
