// ==UserScript==
// @name 	        Codebox Expander/Enhancer for Hydrogenaudio
// @namespace     http://hydrogenaudio.org
// @include       http://hydrogenaudio.org/forums/*
// @include       http://www.hydrogenaudio.org/forums/*
// ==/UserScript==

(function() {
  var divs = document.getElementsByTagName("div");
  for(var i=0; i<divs.length-1; i++) {
    if (divs[i].className == "codetop" && divs[i + 1].className == "codemain") {
      var wx = window.innerWidth - 256;
      if (wx < 0) wx = 1024;
      wx = wx + "px";
      divs[i].style.width = wx;
      divs[i].style.margin = "0";
      divs[i+1].style.width = wx;
      divs[i+1].style.margin = "0";

      var btn = document.createElement("a");
      btn.appendChild(document.createTextNode("\u25BC"));
      //btn.setAttribute("style", "cursor:pointer; margin-right:4em; float:right;");
      btn.setAttribute("style", "cursor:pointer; float:left;");
      btn.setAttribute("m_target", i + 1);
      btn.addEventListener("click", function()
        {
          var wx = window.innerWidth - 256;
          if (wx < 0) wx = 1024;
          wx = wx + "px";
          var bi = this.getAttribute("m_target");
          var bd = document.getElementsByTagName("div");
          if (bd[bi].style.height == "auto") {
            bd[bi].style.height = "200px";
            bd[bi].style.width = wx;
          } else {
            bd[bi].style.height = "auto";
            bd[bi].style.width = "auto";
          }
        }
        , true);
      divs[i].appendChild(btn);
    }
  }
})();

