// script by one.idontsmoke.co.uk

window.onload = function(e) {
  imagePop.init(e);
}

var imagePop = {

  init: function(e) {
    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.push(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.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.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
    win.document.write("<html><head><title>"+this.title+"</title>");
		//win.document.write("<script type=\"text/javascript\" src=\"/1k.js\"></script>");
		//win.document.write("<script type=\"text/javascript\" src=\"/tooltip.js\"></script>");
		//win.document.write("<script type=\"text/javascript\">");
		//win.document.write("onload=function(e){");
		//win.document.write("	T.init()");
		//win.document.write("	T.follows = true");
		//win.document.write("	T.delay = 0");
		//win.document.write("}");
		//win.document.write("</script>");
    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("<a href=\"#\" title=\""+this.title+" ...click to close window\" onclick=\"window.close();\">");
		win.document.write("<img src=\""+this.src+"\" height=\""+h+"\" width=\""+w+"\" alt=\""+this.alt+" ...click to close window\" title=\""+this.title+" ...click to close window\" />");
		win.document.write("</a>");
    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 = "";
  }

}