function $(e) {
  var d = document;
  if (typeof e == 'string') {
   if (d.getElementById)
     e = d.getElementById(e);
   else if (d.all)
     e = d.all[name];
   else if (d.layers)
   	 e = d.layers[name];
  }
  return e;
}

function addOnLoad(func) {
	if (window.onload) {
		var old = window.onload;
		window.onload = function() { old(); func(); };
	} else {
		window.onload = func;
	}
}

var expandable;
var expander;
var expand_startWidth = 0;
var expand_startPos = 0;
var mouseIsUp = true;
var expand_heightAlso = false;

function create_expander(elem, expandHeightAlso) {
	expandable = $(elem);
	expandable.className += " expandable";
	expandable.expandHeightAlso = expandHeightAlso;
	expander = document.createElement('div');
	expander.className = 'expander clearfix';
	expander.style.height = parseInt(expandable.style.height.replace(/px/ig,''),10) + 'px';
	expander.onmousedown = expand_start;
	expandable.parentNode.insertBefore(expander, expandable.nextSibling);
	var clear = document.createElement('br');
	clear.style.clear = 'both';
	expander.parentNode.insertBefore(clear, expander.nextSibling);
}

//set the initial position of the resize-bar
function expand_start(e){
 if (!e) var e = window.event;
 if (e.pageX)
  expand_startPos = e.pageX;
 else if (e.clientX)
  expand_startPos = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
 mouseIsUp = false;
 expand_startWidth = parseInt(expandable.style.width.replace(/px/ig,''),10);
}

//reset the position of the resize-bar when the mouse moves while button down
function expand_update(e){
 if(!mouseIsUp) {
  if (!e) var e = window.event;
	var x = 0;
  if (e.pageX)
   x = e.pageX;
  else if (e.clientX)
   x = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;
	var newWidth= expand_startWidth + x - expand_startPos;
	newWidth = (newWidth<5?5:newWidth)+'px';
	expandable.style.width = newWidth;
	if (expandable.expandHeightAlso) {
  	expandable.style.height = newWidth;
	  expander.style.height = newWidth;
	}
 }
}

document.onmousemove = expand_update;
document.onmouseup = function() { mouseIsUp = true; };
