////////////////////////////////////////////////////////////////////////////////
// Showpic (Creates an image popup and resizes it automatically)
// Version 2.1b
// Last update: 14.May.2007
//
// (c) 2001 by Achim Wiedemann
// You may use this script freely but please leave this infobox untouched. Thanx.
//
////////////////////////////////////////////////////////////////////////////////


// V A R I A B L E S - set the following ones:
var 
    // The title of the image window
		windowTitle = "World to Ashes",
		// Alternative Text for the Picture
		picAltText = "(c) by World to Ashes",
		// Set your Font-Attributes (CSS)
    fontType = "Arial, Helvetica",
		fontSize = "10pt",
		fontWeight = "bold",
		stdFontColor = "#ffffff";
		// Wheter every picture is opened in the same, or in an extra window
		useOneWindow = true;


// Don't change anything here!
var	firstTime = true,
		lines,
		windowWidth=200,
		windowHeight=200,
		windowName="Showpic",
		source,
		text,
		textColor;

function showpic(linkNode, lines, fontColor){
    source = linkNode.href;
    if (linkNode.firstChild.nodeName.toLowerCase() == "img" && linkNode.firstChild.alt){
      text = linkNode.firstChild.alt;
    }
    showthepic(source, text, lines, fontColor);
}

// F U N C T I O N S
function showthepic(source, text, lines, fontColor)
{
  // Determine browser
  var browserVersion = navigator.appVersion.substr(0,3);
  if ((parseFloat(browserVersion) >= 4) && (navigator.appName == 'Microsoft Internet Explorer')) browser = "MSIE4+";
  if ((parseFloat(browserVersion) >= 4) && (navigator.appName == 'Netscape')) browser = "Netscape4+";
  if (navigator.userAgent.search(/Opera/) != -1) browser = "Opera";

  if (firstTime){
    firstTime = false;
    // Sanitize window-name
    if (!useOneWindow) windowName = source.replace(/[^a-zA-Z0-9]/g, "_");

		// Since window.focus() doesn't seem to work with all browsers (may for sec-
		// urity reasons) we gotta close an existing popup, and open a new one again
		// so it will have the focus in the end.
    if (typeof(pictureWindow) != "undefined" && useOneWindow) pictureWindow.close();
    // Open the window
    pictureWindow = window.open("", windowName ,"toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=no,copyhistory=no,width=" + windowWidth + ",height=" + windowHeight + ",left=0,top=0");
    pictureWindow.document.open();
    pictureWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>' + windowTitle + '</title><style type="text/css">body{font-family:verdana; width:100%; height:100%; font-size:10px; color:black;}</style></head><body><p>loading...</p></body></html>');
    pictureWindow.document.close();

    myImage = new Image();		// load the image
    myImage.src = source;
  }

  // Call showpic() again, until the image is loaded completely
  if (myImage.complete){
    display();
  }else{
    hlpsource = source;
    hlptext = text;
    hlplines = lines;
    hlptextColor = textColor;
    setTimeout("showthepic(hlpsource, hlptext, hlplines, hlptextColor);", 100);
  }

	/**
	 * Display the window with the image
	 */
  function display(){
    // Set the size of the window
		if (browser == "MSIE4+"){
		  // Unfortunately IE doesn't support innerWidth...
	    pictureWindow.resizeTo(
	      myImage.width + 10,
	      myImage.height + 20
	    );
	  }else{
	    // Since setting innerWidth doesn't work in Opera, use a workaround...
	    pictureWindow.resizeTo(
	      myImage.width  + pictureWindow.outerWidth - pictureWindow.innerWidth,
	      myImage.height + pictureWindow.outerHeight - pictureWindow.innerHeight
	    );
		}
		
		// Prevent uninitialized vars...
    if (typeof(text) == "undefined") text = " ";
    if (typeof(lines) == "undefined") lines = 1;
    if (typeof(textColor) == "undefined") fontColor = stdFontColor;

 		// Place the picture
    textPosition = myImage.height - (lines * 17);
    pictureWindow.document.getElementsByTagName("body")[0].innerHTML = "<div style='position: absolute; top:0; left:0;'><img src='"+myImage.src+"' alt='"+picAltText+"' /></div><div style='position:absolute; top:"+textPosition+"; left:5; z-index:9; font-family:"+fontType+"; font-size:"+fontSize+"; color:"+fontColor+"; font-weight:"+fontWeight+";'>"+text+"</div>";

		// Reset the flag for the image loading
    firstTime = true;
  }
}