// ==UserScript==
// @name          MozillaZine Forum Sidebar Toggle
// @namespace     http://mozilla.wikicities.com/
// @include       http://forums.mozillazine.org/*
// @description	  Toggle sidebar on and off
// ==/UserScript==

(function() {
  var head = document.getElementsByTagName('head')[0];

  var gm = {
    injectStyle:function(css) {
      script = document.createElement('style');
      script.setAttribute('type', 'text/css');
      script.innerHTML = css;
      head.appendChild(script);
    },
    injectScript:function(js) {
      script = document.createElement('script');
      script.setAttribute('type', 'text/javascript');
      script.innerHTML = js;
      head.appendChild(script);
    }
  }

  var css = '' +
    '.sidebar {\n' +
    '  background-color: #faf9f6;\n' +
    '  margin-bottom: .5em;\n' +
    '  border-width: 1px;\n' +
    '}\n\n' +
    '.forumline,\n' +
    '.sidebar {\n' +
    '  -moz-border-radius: 10px;\n' +
    '}\n\n' +
    '.thCornerL {\n' +
    '  -moz-border-radius-topleft: 10px;\n' +
    '}\n\n' +
    '.thCornerR {\n' +
    '  -moz-border-radius-topright: 10px;\n' +
    '}\n\n' +
    '.thHead {\n' +
    '  -moz-border-radius: 10px 10px 0 0;\n' +
    '}\n\n' +
    'a:hover {\n' +
    '  text-decoration: underline;\n' +
    '}\n\n' +
    'input[type="button"],\n' +
    'input[type="submit"],\n' +
    'input[type="reset"] {\n' +
    '  border: 1px outset #f7f0e0;\n' +
    '  background:\n' +
    '    #f7f0e0\n' +
    '    url(http://static.mozillazine.org/forums/images/bg2.gif)\n' +
    '    top center;\n' +
    '}\n\n' +
    'input[type="button"]:hover,\n' +
    'input[type="submit"]:hover,\n' +
    'input[type="reset"]:hover {\n' +
    '  background-position: bottom center;\n' +
    '}\n\n' +
    'input[type="button"]:active,\n' +
    'input[type="submit"]:active,\n' +
    'input[type="reset"]:active {\n' +
    '  background-image: url(http://static.mozillazine.org/forums/images/bg1.gif);\n' +
    '  background-position: top center;\n' +
    '  border-style: inset;\n' +
    '}\n\n'

  var js = '' +
    'function toggleSidebar() {\n' +
    '  var sidebar = document.getElementById("sidebar");\n' +
    '  if(sidebar.style.display == "") {\n' +
    '    sidebar.style.display = "none";\n' +
    '  } else {\n' +
    '    sidebar.style.display = "";\n' +
    '  }\n' +
    '}\n'

  gm.injectStyle(css);
  gm.injectScript(js);

  var sprite = document.getElementById('masthead').lastChild.previousSibling;
  sprite.setAttribute('onclick', 'toggleSidebar();')
  sprite.setAttribute('title', 'Toggle Sidebar');
  sprite.style.cursor = 'pointer';
})();

