window.onload = setScreenClass; 
window.onresize = setScreenClass;

// Set a class on body depending on the width of the browser
function setScreenClass() {
  var browserwidth = document.documentElement.clientWidth;
  if (browserwidth < 960) { document.body.className='browser-narrow'; }
  else if (browserwidth > 1400) { document.body.className='browser-wide'; }
  else { document.body.className='browser-normal'; } 
}

// Clears text from the search input on focus
function clearText() {
	if (document.searchform.q.value == document.searchform.q.value) { document.searchform.q.value = "" ; }
}

function open_css(elementid,styleparameter,styleattribute) {
	document.getElementById(elementid).style.styleparameter = styleattribute;
}
	
function open_vocalrangeexplanation() {
	document.getElementById('whatis_vocalrange_explanation').style.display = 'block';
}
	
$(document).ready(function(){

  // Initialize player
  $("#jplayer").jPlayer({ 
    ready: function () {
      $(this).jPlayer("setMedia", { mp3: 'http://media.whitmoresmusic.com.s3.amazonaws.com/084418084029.mp3' });
    },
    swfPath: "/scripts",
    supplied: "mp3",
    wmode: "window"
  });

  // Start, stop, and change styles for playing
  $('.jplay').click(function() {
    if ($(this).hasClass('jplaying')) {
      stop_jplayer();
    } else {
      stop_jplayer();
      $(this).addClass('jplaying');
      $("#jplayer").jPlayer({
        ready: function () {
          $(this)
            .jPlayer("setMedia", { mp3: $('.jplay.jplaying').data('audio-url') })
            .jPlayer("play");
        },
        ended: function () {
          stop_jplayer();
        },
        swfPath: "/scripts",
        supplied: "mp3"
      });
    }
    return false;
  });
});

function stop_jplayer() {
  if ('undefined' != typeof $('#jplayer').jPlayer) {
    $('#jplayer').jPlayer('stop');
    $('#jplayer').jPlayer('destroy');
    $('#jplayer').data('track-id', '');
    $('.jplay.jplaying').removeClass('jplaying');
  }
}
