
AneBrunWidget = new function() {

  var stylesheetUrl = 'http://anebrun.com/widget/styles.css',
      fontUrl       = 'http://fonts.googleapis.com/css?family=Droid+Serif';

  function applyStylesheet( fileUrl ) {
    var stylesheet = document.createElement('link');
    stylesheet.rel = 'stylesheet';
    stylesheet.href = fileUrl;

    document.lastChild.firstChild.appendChild( stylesheet );
  }

  function applyCustomFonts( fileUrl ) {
    var link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = fileUrl;

    document.lastChild.firstChild.appendChild( link );
  }

  applyStylesheet( stylesheetUrl );
  applyCustomFonts( fontUrl );

  document.write('\
  <div id="anebrun_widget">\
    <div class="anebrun_widget_info">The single “Do You Remember”<br> is now available for purchase.</div>\
    <a class="anebrun_widget_button" href="http://www.itunes.com/anebrun/doyouremember-single" title="Buy “Do you remember” from iTunes">Buy “Do You Remember”</a>\
    <div class="anebrun_widget_more">\
      <a href="http://anebrun.com">Read more at anebrun.com</a>\
      |\
      <a href="#" id="anebrun_widget_share_link">Share this widget</a>\
    </div>\
    <div id="anebrun_widget_overlay">\
      <a href="#" id="anebrun_widget_overlay_close">Close</a>\
      <div class="anebrun_widget_spread">\
        Spread this widget:\
        <div>\
          <a href="http://twitter.com/share" class="twitter-share-button" data-text="@anebrun will release her new single &quot;Do You Remember&quot; on the 17th of may. Don\'t miss! http://anebrun.com" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>\
          <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fanebrun.com&amp;send=false&amp;layout=button_count&amp;width=150&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:21px;" allowTransparency="true"></iframe>\
        </div>\
      </div>\
      <div class="anebrun_widget_embed">\
        Embed this widget on your blog:\
        <textarea>&lt;script src="http://anebrun.com/widget/embed.js">&lt;/script></textarea>\
        <span>Copy and paste this code into an HTML webpage</span>\
      </div>\
    </div>\
  </div>'
  );

  var overlay = document.getElementById('anebrun_widget_overlay'),
      shareLink = document.getElementById('anebrun_widget_share_link'),
      overlayLink = document.getElementById('anebrun_widget_overlay_close');

  shareLink.onclick = function() {
    overlay.style.display = 'block';
    return false;
  }

  overlayLink.onclick = function() {
    overlay.style.display = 'none';
    return false;
  }

}
