addEvent(window, "load", dockable_init);
addEvent(window, "scroll", calcIEPosition);

var dockable = document.getElementById('dockableComment');

function dockable_init() {

	if (!document.getElementById) return;

	var dockcontrol = document.getElementById('dockcontrol');
	
	if (!dockable || !dockcontrol) return;
	
	var docklink = dockcontrol.appendChild(document.createElement('a'));
	docklink.href="#commentform";
	var docktext = docklink.appendChild(document.createTextNode('Dock Comment'));
	
	docklink.onmouseover = function() {
		if (/docked/i.exec(dockable.className)) return;
		dockable.className += " outlined";
	}


	docklink.onmouseout = function() {
		if (/docked/i.exec(dockable.className)) return;
		dockable.className = dockable.className.replace(/outlined/g,"");
	}


	docklink.onfocus = docklink.onmouseover;
	docklink.onblur = docklink.onmouseout;



	docklink.onclick = function() {

		if (!/docked/i.exec(dockable.className)) {
			dockable.className += " docked";
			docktext.nodeValue = "Undock Comment";

		} else {
			dockable.className = dockable.className.replace(/docked/g, "");
			docktext.nodeValue = "Dock Comment";
		}
		
		calcIEPosition();
		
	}
	
}


function calcIEPosition() {
	
  try {
	if (getComputedStyle) return;
  } catch (e) {
  		
	  if( document.documentElement) {
		topY = document.documentElement.scrollTop;
	  } else {
		return;  
	  }
  	
	dockable.style.top = topY;
  
  }
  
  
	
	
	
	
}















function addEvent(elm, evType, fn, useCapture)
  // addEvent and removeEvent
  // cross-browser event handling for IE5+,  NS6 and Mozilla
  // By Scott Andrew
  {
    if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
    } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
    }
  } 
