var Popups_array = new Array();
function create_popups(Container, Popup_template, Popup_copy)
{
	if(top.pieceOjunk || !getObj()) return null;
	
	Popup_template.Copy = (Popup_copy ? Popup_copy : Popup_template);
	Popup_template.index = Popups_array.length;
	Popups_array[Popup_template.index] = Popup_template;
	
	Popup_template.style.display = 'none';
	Popup_template.style.top = '0px';
	
	var A_els = Container.getElementsByTagName('A');
	
	for(var i in A_els)
	{
		var A = A_els[i];
		
		//if the target is an image
		if( A.href && (A.href.search(/\.jpg$/i) > 0 || A.href.search(/\.gif$/i) > 0 || A.href.search(/\.png$/i) > 0) )
		{
			A.Popup = Popup_template;
			A.popup_type = 'image';
			A.onclick = function () {
				popup(this);
				return false;
			}
			A.target = '';
		}
	}
}

function popup(E)
{
	var inner = '';
	
	if(E.popup_type == 'image') 
	{
		inner = '<a href="javascript:hide_popup(' + E.Popup.index + ')">Click here to hide this image.</a><br><img src="' + E.href + '">';
		
		//visible
		if(E.Popup.style.display == 'block') {
			//current so hide
			if(E.Popup.href == E.href) {
				E.Popup.style.display = 'none';
			}
			//different so move over link link
			else {
				E.Popup.Copy.innerHTML = inner;
				E.Popup.href = E.href;
				E.Popup.style.top = (findPosY(E) + E.offsetHeight) + 'px';
			}
		}
		//invisible
		else {
			E.Popup.Copy.innerHTML = inner;
			E.Popup.href = E.href;
			E.Popup.style.top = (findPosY(E) + E.offsetHeight) + 'px';
			E.Popup.style.display = 'block';
		}
		
	} //end image
}

function hide_popup(index)
{
	Popups_array[index].style.display = 'none';
}

//Credits go to PPK of quirksmode.org for the following scripts
//THANKS!
function getObj(name)
{
	if(typeof name != 'string') return (document.getElementById || document.all);
	
	if (document.getElementById) {
		return document.getElementById(name);
	}
	else if (document.all) {
		return document.all[name];
	}
	else return null;
}
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}
