//--### array to store window details 1-image, 2-TimerID, 3-Title --

var stack=Array(25,3);

//--### initialize array --

for (i=0;i<25;i++) {
	stack[i,1]=null;
	stack[i,2]=null;
	stack[i,3]=null;
	}

//--### aquire blank resourses from stack array and assign window details --

function setImage(img,title)
{
 	var i=null;
//--### scan for null element of array --

 	for (i=0;i<25;i++)
	{
	 if (stack[i,1] == null && stack[i,2] == null && stack[i,3]==null)
	 {
//--### assign uninitialized image object to array element --

	  stack[i,1]=new Image();

//--### assign Image (start loading image into it - Preloading) Row=i,Col=1 --

	  stack[i,1].src=img;

//--### pass array element no. to Timeout parameter function --

	  s="chkit('"+i+"')";

//--###	save Timer ID into array (Row=i,Col=2) --

	  stack[i,2]=window.setTimeout(s,200);

//--### set Title of window into array (Row=i,Col=3) --

	  stack[i,3]=title;
	  break;
	 }
	}
	return (i);
}

//--### free resources by assigning null to array elements of given row 
//--### for later reuse. ---
	
function freeres(n)
{
	stack[n,1]=null;
	stack[n,2]=null;
	stack[n,3]=null;
}

//--### this will be called from setTimeOut event with array 
//--### element no. as a parameter --

function chkit(p)
{
	var width=0;
	var height=0;
//--### parse array element no. --

	n=parseInt(p);
//--### check if download of image (stored in column is complete?) --
	if (stack[n,1].complete)
	{
		s="menubar=0,toolbar=0,width="+stack[n,1].width+",height="+stack[n,1].height;

//--### open window and display image in form of document --
		w=window.open("","_blank",s);
		w.document.write("<html><head><title>");
		w.document.write(stack[n,3]);
		w.document.write("</title></head><body leftmargin=0 topmargin=0>");
		w.document.write("<IMG SRC='"+stack[n,1].src+"'>");
		w.document.write("</body></html>");
//--### release timer with timerID stored in second column of array.
		window.clearTimeout(stack[n,2]);
//--### free resourses --
		freeres(n);
	}
	else
	{
//--### if download is not complete again set timer of 500 milliseconds and save ID --
		s="chkit('"+p+"')";
		stack[n,2]=window.setTimeout(s,500);
	}
}
	
//--### main function receives parameter - ImagePath and Title -
function popwin(i,t)
{
	setImage(i,t);
}
