// image galley script
var newwin = null;
function load_frame(url,imgtitle,hires){
	if(document.getElementById){
		document.getElementById("image_viewer_title").innerHTML="<b>"+imgtitle+"</b>";
		document.getElementById("image_viewer_progress").innerHTML="<img src='../../../images/elements/loaderbar.gif' width=150 height=18 alt='LOADING...'>";
		document.getElementById("image_viewer_image").innerHTML="<a href=\"javascript:hideframe()\"><img src=\"" +  url + "\" border=0 alt=\"" + imgtitle +"\" onload=doneloading()></a>";
		if(hires.length){
			document.getElementById("image_viewer_footer").innerHTML="Download <a href=\"" + hires + "\" target=_blank> hi-res version</a><br><a href=\"javascript:hideframe()\">Close</a>";
		} else {
		document.getElementById("image_viewer_footer").innerHTML= "<a href=\"javascript:hideframe()\">Close</a>";
		}
		document.getElementById("viewer_frame").style.visibility = "visible";
		document.body.style.cursor = 'progress';
		moveto_scroll();
	} else {
		newwin = window.open(url,'imagewin','width=600,height=600,top=150,left=22,menubar=no,toolbar=no,statusbar=no,addressbar=no');
		newwin.focus();
	}
	
}
function hideframe(){
	if(document.getElementById){
		document.getElementById("viewer_frame").style.visibility = "hidden";
	} else {
		newwin.close();	
	}
}
function doneloading(){
	if(document.getElementById){
		document.getElementById("image_viewer_progress").innerHTML="";
		document.body.style.cursor = 'default';
	}
}
// variables for frame dragging
var dragWin = null;
NS = (document.all) ? 0 : 1;
dragActive = 0;
var mousex = 0;
var mousey = 0;
var offsetx = 0;
var offsety = 0;


function mouseD(evt) {
	dragWin = document.getElementById("viewer_frame");
	
	if(NS){
		if(evt.target.id == "drag") {
			dragActive = 1;
			offsetx = evt.pageX - dragWin.offsetLeft;
			offsety = evt.pageY - dragWin.offsetTop;
			document.body.style.cursor =  "move";
		}
	} else {
		if (window.event.srcElement == document.getElementById("drag")) {
			dragActive = 1;
			offsetx = window.event.x + document.body.scrollLeft - dragWin.offsetLeft;
			offsety = window.event.y + document.body.scrollTop - dragWin.offsetTop;
			document.body.style.cursor =  "move";
		}
	}
}

function mousedrag(evt) {
	
		if (NS) {
			mousex = evt.pageX;
			mousey = evt.pageY;
		} else {	
				mousex = window.event.x + document.body.scrollLeft;
				mousey = window.event.y + document.body.scrollTop;
		
		}
	if (dragActive) {
		//window.status = mousex + "    " + mousey;
		dragWin.style.left = mousex - offsetx;
		dragWin.style.top = mousey - offsety;
   	}
}
function mouseU() {
		dragActive = 0;
		document.body.style.cursor = "default";
}
function moveto_scroll(){
		win_offset = -300;
		//document.getElementById("viewer_frame").style.left = mousex + win_offset  + "px";
		document.getElementById("viewer_frame").style.top =  mousey + win_offset + "px";
		//window.status = mousex + "    " + mousey;
}

if (NS) {
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);

}
document.onmousemove = mousedrag;
document.onmousedown = mouseD;
document.onmouseup = mouseU;


