//======================================================================
// 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://www.idontsmoke.co.uk/]
//======================================================================

var imagePop = {

  init: function(e) {
	if ((document.all || (document.getElementById && document.getElementsByTagName)) && !(document.all && navigator.platform == "MacPPC")) {
		var p = imagePop.getElementsByClass("imagePop");
		if(p == null) return;
		for (var i = 0; i < p.length; i++) {
		  if (p[i].nodeName == "A" || p[i].nodeName == "IMG") 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.getAttribute("src") || this.getAttribute("title") || img.src;
    img.title = this.getAttribute("title") || (this.firstChild ? this.firstChild.getAttribute("title") : 0) || this.getAttribute("src") || img.src;
    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") || this.getAttribute("src");

    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.writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
    win.document.writeln("<html><head><title>"+this.title+"</title>");
    win.document.writeln("<style type=\"text/css\">img { position:absolute; top:0; left:0; border:none; }</style>");
    win.document.writeln("</head><body>");
    win.document.writeln("<img src=\""+this.src+"\" height=\""+h+"\" width=\""+w+"\" alt=\""+this.alt+"\" />");
    win.document.writeln("</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 = "";
  }

}
