// JavaScript Document
function picture_obj (pic,caption) {
	this.pic=pic;
	this.caption=caption;
}
function make_page (pic_array,pic_display,path,thumbpath) {
	divBody = '';
	preload = '';
	divBody += '<p>Please click any of the images below (once only and allow 30 seconds) to see a larger \'framed\' example.</p>';
	//divBody += '<p align="center" class="small">Art Prints Sizes Image 59cm X 84cm approx - Framed Mount 88 X 73cm approx</p>';
	for (var n=0; n<pic_array.length; n++) {
		divBody += '<div class="thumbnail">\n';
		divBody += '<form action="quote.php" method="get" name="gallery_frm">\n';//
		divBody += '<a title="' + pic_array[n].caption + '" href="javascript:showImage(\'' + path + pic_array[n].pic + '\',\'' + pic_display + '\',' + n + ',\'' + path + '\')"><img src="' + thumbpath + pic_array[n].pic + '" alt="' + pic_array[n].caption + '" /></a>\n';
		divBody += '<div class="caption">' + pic_array[n].caption + '</div>\n';
		divBody += '<input name="image" type="hidden" value="' + thumbpath + pic_array[n].pic + '" />\n';
		divBody += '<input name="title" type="hidden" value="' + pic_array[n].caption + '" />\n';
		divBody += '<input type="submit" name="Submit" value="Get Quote" />\n';//
		divBody += '</form>\n';//
		divBody += '</div>\n';
		preload += '<img src="' + path + pic_array[n].pic + '" alt="' + pic_array[n].caption + '" title="' + pic_array[n].caption + '" width="0" height="0" />';
	}
	document.getElementById('imageDisplay').innerHTML=divBody;
	document.getElementById('imagePreload').innerHTML=preload;
}
var popup = null;
function showImage(imgSRC,pic_display,arrayID,path) {
	var win_opt = 'height=200,width=200,location=0,resizable=1,toolbar=0,status=0,scrollbars=1';
	popup = window.open(pic_display+".html?"+imgSRC+"&"+arrayID+"&"+path,'',win_opt);
}
function destroyPop() {
	if (popup != null && popup.open) popup.close();
}
window.onfocus=destroyPop;

var searchVal = self.location.search;
if (searchVal.length > 1) {
	searchVal = searchVal.substring(1,searchVal.length);
} else {
	searchVal = null;
}

urlVals = new Array();
if (searchVal) {
	for (var i=0; i < searchVal.split("&").length; i++) {
		urlVals[i] = searchVal.split("&")[i];
	}
}
if (urlVals.length > 0) {
	picUrl = urlVals[0];
	arrayID = urlVals[1];
	picPath = urlVals[2];
} else {
	picUrl = "";
}

function make_display(pic_array) {
	divDisplay = '';
	divDisplay += '<img src="' + picUrl + '" alt="' + pic_array[arrayID].caption + '" id="mainPhoto" border=0>';
	divDisplay += '<div class="caption">' + pic_array[arrayID].caption + '</div>\n';
	document.getElementById('displayArea').innerHTML=divDisplay;
	document.title = pic_array[arrayID].caption + ' - John M Bradbury Art';
}
	
var NS = (navigator.appName == 'Netscape')?true:false;

function fitPic() {
	imgObj = new Image();
	imgObj.src = picUrl;
	var imgWidth = imgObj.width;
	//window.alert(imgWidth);
	var imgHeight = imgObj.height;
	//window.alert(imgHeight);
	display = document.getElementById("displayArea");
	display.style.width = imgWidth + 'px';
	display.style.height = imgHeight + 'px';
	display.style.marginLeft = '-' + (imgWidth/2) + 'px';
	display.style.marginTop = '-' + (imgHeight/2) + 'px';

	border = document.getElementById("frameBorder");
	border.style.width = (imgWidth + 160) + 'px';
	border.style.height = (imgHeight + 160) + 'px';
	border.style.marginLeft = '-' + ((imgWidth + 160)/2) + 'px';
	border.style.marginTop = '-' + ((imgHeight + 160)/2) + 'px';
	
	background = document.getElementById("frameBackground");
	background.style.width = (imgWidth + 140) + 'px';
	background.style.height = (imgHeight + 140) + 'px';
	background.style.marginLeft = '-' + (((imgWidth + 140)/2)+5) + 'px';
	background.style.marginTop = '-' + (((imgHeight + 140)/2)+5) + 'px';
	
	closeDiv = document.getElementById("closeWidget");
	closeDiv.style.marginLeft = ((imgWidth + 20)/2) + 'px';
	closeDiv.style.marginTop = '-' + ((imgHeight + 120)/2) + 'px';
	
	windowWidth = imgWidth + 180;
	windowHeight = imgHeight + 250;
	
	border.style.top = ((windowHeight/2)-40) + 'px';
	border.style.left = ((windowWidth/2)-5) + 'px';
	background.style.top = ((windowHeight/2)-45) + 'px';
	background.style.left = ((windowWidth/2)-10) + 'px';
	display.style.top = ((windowHeight/2)-50) + 'px';
	display.style.left = ((windowWidth/2)-20) + 'px';
	
	window.resizeTo(windowWidth,windowHeight);
	self.focus();
	/*if (navigator.appVersion.indexOf("MSIE")!=-1) {
		//window.alert(imgWidth);
		if (imgWidth < 1) {
			setTimeout("location.reload()",500);
		}
	}*/
	if (imgWidth < 1) {
		setTimeout("location.reload()",1500);
	}
}

function imageDisplaySetup(pic_array) {
	make_display(pic_array);
	fitPic();
}
