// JavaScript Document

function initial()
{
	preloadImages();
	imageOut();	
}

if (document.layers) { // Netscape
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
document.onmousemove = captureMousePosition;
}

// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {

if (document.layers) { //Netscape
xMousePos = e.pageX;
yMousePos = e.pageY;
trueYmouse = e.pageY - window.pageYOffset;
xMousePosMax = window.innerWidth+window.pageXOffset;
yMousePosMax = window.innerHeight;
} else if (document.all) { //IE
xMousePos = window.event.x+document.documentElement.scrollLeft;
yMousePos = window.event.y+document.documentElement.scrollTop;
trueYmouse = window.event.y;
xMousePosMax = document.documentElement.clientWidth+document.documentElement.scrollLeft ;
yMousePosMax = document.documentElement.clientHeight;
} else if (document.getElementById) {

// Netscape 6 behaves the same as Netscape 4 in this regard
xMousePos = e.pageX;
yMousePos = e.pageY;
trueYmouse = e.pageY - window.pageYOffset;
xMousePosMax = window.innerWidth+window.pageXOffset;
yMousePosMax = window.innerHeight;

}


move_image();


window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos +
", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;

window.status += ", trueYmouse =" + trueYmouse;
}


var display_pic_Offset = 20;



function adjust(image)
{	
	with(document)
	{
		getElementById("image_Border").style.height =  theHeight + 60 + 'px';
		getElementById("image_Border").style.width =  theWidth  + 'px';	
	}
	move_image();
}


var borderAdjusted = false; // initially image border height was not adjusted

function imageOver(image)
{
	adjustTimer = setInterval("adjust()", 200);
	borderAdjusted = true;// image border height was adjusted
	with(document)
	{
		getElementById("image_Border").style.visibility="visible";
		getElementById("image_Holder").style.visibility="visible";
		getElementById("current_image").src = "works/paintings/" + gallery + "/medium/" + image + ".jpg";
		var theHeight = Number(getElementById("current_image").height);
		var theWidth = Number(getElementById("current_image").width);
		var str = getElementById(image).id;
		var info = str.split("AA0");
		getElementById("image_text").value = 'Title: ' + info[0] + '\r\n' + 'Product-ID: ' + info[1];
		//img.src = "works/paintings/medium/" + image + ".JPG";// Starts the browser performing the operation which will trigger the onload
	}
	
}

function imageOut()
{
	if(borderAdjusted == true)
	clearInterval(adjustTimer);
	
	with(document)
	{
		getElementById("current_image").src = "images/loading.gif";
		getElementById("image_Border").style.visibility="hidden";
		getElementById("image_Holder").style.visibility= "hidden";
	}
}

function showPic()
{
	document.getElementById("top_image").style.visibility="visible";
}

function hidePic()
{
	document.getElementById("top_image").style.visibility= "hidden";
}

function move_image()
{
	theHeight = Number(document.getElementById("current_image").height);
	theWidth = Number(document.getElementById("current_image").width);
	//document.form1.posynum.value = document.form1.posxnum.value;
	if( xMousePos > xMousePosMax - theWidth)
	{
		document.getElementById("image_Holder").style.left = xMousePos - document.getElementById("current_image").width - display_pic_Offset + "px";
		document.getElementById("image_Border").style.left = xMousePos - document.getElementById("current_image").width - display_pic_Offset + "px";
	}
	else
	{
		document.getElementById("image_Holder").style.left = xMousePos + display_pic_Offset + "px";
		document.getElementById("image_Border").style.left = xMousePos + display_pic_Offset + "px";
	}

	if (trueYmouse + theHeight > yMousePosMax && trueYmouse - theHeight < 0)
	{
		document.getElementById("image_Holder").style.top = yMousePos - (theHeight/2) + "px";
		document.getElementById("image_Border").style.top = yMousePos - (theHeight/2) + "px";	
	}
	
	else if (trueYmouse + theHeight/2 > yMousePosMax)//above cursor
	{
		document.getElementById("image_Holder").style.top = yMousePos - (theHeight) + "px";
		document.getElementById("image_Border").style.top = yMousePos - (theHeight) + "px";
	}
	/*
	else if (trueYmouse < 300)//above cursor
	{
		document.getElementById("image_Holder").style.top = theHeight + 50 + "px";
		document.getElementById("image_Border").style.top = yMousePos - (theHeight/2) + "px";
	}
	*/
	
	else
	{
		document.getElementById("image_Holder").style.top = yMousePos - (theHeight/2) + "px";
		document.getElementById("image_Border").style.top = yMousePos - (theHeight/2) + "px";
	}

} // end of move_image function


function getSet(theSet, theStart, theEnd)// passes the variables of starting and ending pictures to the hidden input fields
{
	document.picNav.currentSet.value = Number(theSet);
	document.picNav.setStart.value = Number(theStart);
	document.picNav.setEnd.value = Number(theEnd);
	document.picNav.submit();
}