var oldX, oldY;
var dragIt = false;

var ie=document.all&&document.getElementById;
var ns=document.getElementById&&!document.all;

function openHelp(picID,top) {
	var coords = getElementPosition(picID,top);		// get position of thumbnail
	if (!ie&&!ns)
		// if viewed with an older browser, open a standard pop-up window //
		window.open('poster/poster.htm',caption,"width=550,height=500");
	else {
		document.getElementById("galleryWin").style.display='';
		document.getElementById("galleryWin").style.width="550px";
		document.getElementById("galleryWin").style.height="500px";

		// position poster relative to thumbnail
		document.getElementById("galleryWin").style.left = coords.left-465+"px";
//		document.getElementById("galleryWin").style.top = coords.top-50+"px";
		document.getElementById("galleryWin").style.top = coords.top-top+"px";
//
//		//title = document.getElementById("helpTitle");  
//		//title.firstChild.nodeValue = caption;
		// load the gallery page into the iframe //
		document.getElementById("helpiFrame").src='poster/poster.htm?' + picID;
	}
}

function getElementPosition(elemID) {
	var offsetTrail = document.getElementById(elemID);
	var offsetLeft = 0;
	var offsetTop = 0;
	while(offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") {
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft, top:offsetTop};
}

function closeHelp()

{
	// retain the last position of the window ready to open it again in the same place
	oldX = document.getElementById("galleryWin").style.left;
	oldY = document.getElementById("galleryWin").style.top;
	// setting the display style to none renders the element invisible	
	document.getElementById("galleryWin").style.display="none";
}

function startDrag(e)

{
	offsetx=ie? event.clientX : e.clientX;
	offsety=ie? event.clientY : e.clientY;
	tempx=parseInt(document.getElementById("galleryWin").style.left);
	tempy=parseInt(document.getElementById("galleryWin").style.top);
	dragIt = true;
	document.getElementById("galleryWin").onmousemove=DragNDrop;
}

function DragNDrop(e){

	// move the pop-up window script for Internet Explorer //
	if (ie&&dragIt&&event.button==1){
		document.getElementById("galleryWin").style.left=tempx+event.clientX-offsetx+"px";
		document.getElementById("galleryWin").style.top=tempy+event.clientY-offsety+"px";
	}
	// move the pop-up window script for Netscape //
	else if (ns&&dragIt){
		document.getElementById("galleryWin").style.left=tempx+e.clientX-offsetx+"px";
		document.getElementById("galleryWin").style.top=tempy+e.clientY-offsety+"px";
	}
}

function stopDrag(){

	dragIt=false;
	document.getElementById("galleryWin").onmousemove=null;
}

