YAHOO.util.Event.addListener(window, "load", init);

function init(e) {

  YAHOO.util.Event.addListener(getElementsByClass("th"), "click", showImagePopup);
}


function showImagePopup(e) {

  var url = this.href;
  var image = this.getElementsByTagName('img')[0];

  var pId = /pId=([0-9]+)/.exec(url);
  var width = /width=([0-9]+)/.exec(url);
  var height = /height=([0-9]+)/.exec(url);

  if(pId !== null && width !== null && height !== null) {

    width = parseInt(width[1]) + 40;
    height = parseInt(height[1]) + 40;

    window.open('popup_image.php?pId=' + pId[1], 'image',
      'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + width + ',height=' + height + ',screenX=150,screenY=150,top=150,left=150');
  }


  YAHOO.util.Event.stopEvent(e);
}


function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if(node == null) {
    node = document;
  }
  if(tag == null) {
    tag = '*';
  }
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (var i = 0, j = 0; i < elsLen; i++) {
    if(pattern.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}