/*
 * Big Thanks to Paul for this modification.
 * Modified on 2002-04-10: assumes use of anchor element and alt attribute
 * for origional please email <paul@idontsmoke.co.uk>
 */
//======================================================================
// imagePop is a cool little popup script that automatically determines 
// image dimensions and sizes the window appropriately. it's even 
// standards-compliant. yippee!
//======================================================================
// code may be used if this copyright is intact
// please use w3c standards and help evolve the web
// developed by: aaron boodman <http://youngpup.net/>
//               paul sowden <http://idontsmoke.co.uk/>
//======================================================================

var imagePop = {

  init: function(e) {
	if (document.all || (document.getElementById && document.getElementsByTagName)) {
		var p = imagePop.getElementsByClass("imagePop");
		if(p == null) return;
		for (var i = 0; i < p.length; i++)
		  if (p[i].nodeName == "A")  p[i].onclick = imagePop.clicked;
	}
  },

  getElementsByClass: function(className) {
    var c = new Array();
    var r = new RegExp("(^| )" + className + "( |$)", "");
	var a = document.all ? document.all : document.getElementsByTagName("*");
  
    for (var i = 0; i < a.length; i++) {
      if (a[i].className.match(r) != null) c[c.length] = a[i];
    }
  
    return c.length == 0 ? null : c ;
  },

  clicked: function(e) {
    var img = new Image();
	img.alt = this.getElementsByTagName("img").item(0).getAttribute("alt");
    img.title = img.alt;
    img.onload = imagePop.popit;
    img.onerror = imagePop.fucked;
    img.onabort = imagePop.fucked;
    window.status = "image loading ... ";
    document.documentElement.style.cursor = "wait";
    img.src = this.getAttribute("href");

    return false;
  },

  popit: function(e) {
    var h = this.height;
    var w = this.width;
    var l = Math.round((screen.width - w) / 2);
    var t = Math.round((screen.height - h) / 2);

    var win = window.open("", "image", "width="+w+",height="+h+",top="+t+",left="+l);
    win.document.open();
    win.document.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n");
    win.document.write("<html><head><title>"+this.title+"</title>");
    win.document.write("<style type=\"text/css\">img { position:absolute; top:0; left:0; border:none; }</style>");
    win.document.write("</head><body>");
    win.document.write("<img src=\""+this.src+"\" height=\""+h+"\" width=\""+w+"\" alt=\""+this.alt+"\" />");
    win.document.write("</body></html>");
    win.document.close();

	document.documentElement.style.cursor = "auto";
    window.status = "";
  },

  fucked: function(e) {
    var r = new RegExp("[^/]+$");
    alert("the image \""+this.src.match(r)+"\" failed to load");
	document.documentElement.style.cursor = "auto";
    window.status = "";
  }
}