(function($) {
// bail out if jQuery isn't loaded
if (typeof $ === 'undefined') { return; }

$(document).ready(function() {

// play media files on page load

  if ($('a.media').length) {
  // audio with cookies
    if ($.cookie) {
      var c = location.pathname.slice(1) || 'index';
    
      if ($.cookie(c) == 'userplay') {
        $('a.media').media({mp3Player:'mediaplayer.swf', height:'36px',width: '300px'}); 
      } else {
        $('a.media').media({autoplay: true, mp3Player:'mediaplayer.swf', height:'36px',width: '300px',flashvars: {autostart: true} }); 
        $.cookie(c, 'userplay', {expires: 30, path: '/'});
      }
  // audio without cookies (plays every time)
    } else {
      $('a.media').media({autoplay: true, mp3Player:'mediaplayer.swf', height:'36px',width: '300px',flashvars: {autostart: true} }); 
    }
  }
  
  // open "popup" links in new window
  $('a.popup').bind('click', function(event) {
    event.preventDefault();
    window.open(this.href);
  });
});

})(jQuery);
