/*  SCRIPT FOR DISPLAYING ZOOM VERSIONS OF BOOKMARK IMAGES */
/* For this to work, every zoom image must have exactly the same 
   filename as their normal-sized image with "_zoom" at the end, 
   and be placed in the same folder. */

/* initialise - gets image links adds event listeners for them */
function init(){
	/*if functions not supported return (clicking on the image link will then just open the zoom image in the current window) */
	if(!document.getElementById || !document.getElementsByTagName){	
		return;
		}
	/* get array of all links on the page */
	arLinksAll=document.getElementsByTagName('a');
	/* loop the links and for each one that has a class of 'zoomLink' add an event listener */
	for(i=0; i < arLinksAll.length; i++){
		if(arLinksAll[i].className=='zoomLink'){
			addEvent(arLinksAll[i],'click',handle_zoomLink_click,false);}
	}
}

/* handler for clicking on zoom image links */
function handle_zoomLink_click(e){
	var zoomLink = getElmnt(e); //get the link that was clicked on
	if(zoomLink=='none'){
		return;}
	
	/*some browsers pass the link text instead of the 'a' element, 
		so move up the DOM tree until the 'a' element is found, don't go past the 'body' container*/
	while(zoomLink.nodeName.toLowerCase() != 'a' && zoomLink.nodeName.toLowerCase() != 'body'){
		zoomLink=zoomLink.parentNode;
		//prevent accidental infinite loop by returning if body tag reached
		if(zoomLink.nodeName.toLowerCase() == 'body'){
			return;}
	}	
		
	/* CREATE OR FOCUS ZOOM WINDOW */
	var winWidth=650;
	var winHeight=550;
	var leftPos=(screen.width-winWidth)/2;
	var topPos=(screen.height-winHeight)/2;
	var sOption="width="+winWidth+",height="+winHeight+",left="+leftPos+",top="+topPos+",menubar=no,"; 
		sOption+="toolbar=no,location=no,status=no,scrollbars=no,resizable=yes";  
	//if window is already open, close it
	if (window.zoomWin && !zoomWin.closed ){	
		zoomWin.close();}
	//create window and write image in it
	zoomWin=window.open('',"Zoom",sOption); 
	zoomWin.document.write('<html><head><title>Zoom</title></head><body style="background:white">' +
								'<p align="center"><img src="' + zoomLink.href + '"></p></body></html>');
	zoomWin.focus();
	
	cancelClick(e);
	return false;
}

addEvent(window, 'load', init, false);
