var docSize = new Array();
docSize[0] = (self.innerWidth)?
	self.innerWidth :
	(document.documentElement || document.documentElement.clientWidth)?
		document.documentElement.clientWidth : 
		(document.body)?
			document.body.clientWidth :
			640;
docSize[1] = (self.innerHeight)?
	self.innerHeight :
	(document.documentElement || document.documentElement.clientHeight)?
		document.documentElement.clientHeight : 
		(document.body)? 
			document.body.clientHeight : 
			480;
var bigImgSize = [docSize[0]-100, docSize[1]-140];

var preload=['images/gallery.hover.gif','images/statement.hover.gif','images/contact.hover.gif','images/gallery.small.hover.gif','images/statement.small.hover.gif','images/contact.small.hover.gif'];
var preloadPaintingsBegin = preload.length;
if(window.location.href.substring(window.location.href.lastIndexOf('/')+1)=='gallery') {
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/000.No_Hablo_Espanol_SOLD.48x48.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/001.Inheritance_SOLD.4x4.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/002.In_a_Room.16x12.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/006.Papa_SOLD.1x1.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/007.Growth_SOLD.1x1.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/008.Mom_SOLD.12x12.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/102.Self_Portrait.24x24.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/104.Bipolar.24x24.jpg';
	preload[preload.length]='img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/105.Shaala.24x30.jpg';
}
var preloaded=[];
for (i in preload) {
	preloaded[i] = new Image();
	preloaded[i].src = preload[i]
}

function enlarge(image) {
	var imageParts = image.split('.');
	var title = imageParts[1].replace(/_/g,' ').replace('-APOS-','\'');
	var dimensions = imageParts[2];

	
	var enlargement_table = document.createElement('table');
	enlargement_table.id = 'enlargement_table';
	var enlargement_tr = document.createElement('tr');
	enlargement_tr.id ='enlargement_tr';
	var enlargement_td = document.createElement('td');
	enlargement_td.id = 'enlargement_td';
	var bigImg = document.createElement('img');
	bigImg.src = 'img.php?s=0&w='+bigImgSize[0]+'&h='+bigImgSize[1]+'&i=images/paintings/'+image;
	bigImg.id = 'bigImg';
	var brNode0 = document.createElement('br');
	var titleNode = document.createTextNode(title);
	var brNode1 = document.createElement('br');
	var dimensionsNode = document.createTextNode(dimensions);
	document.getElementById('enlargement').appendChild(enlargement_table);
	document.getElementById('enlargement_table').appendChild(enlargement_tr);
	document.getElementById('enlargement_tr').appendChild(enlargement_td);
	document.getElementById('enlargement_td').appendChild(bigImg);
	document.getElementById('enlargement_td').appendChild(brNode0);
	document.getElementById('enlargement_td').appendChild(titleNode);
	document.getElementById('enlargement_td').appendChild(brNode1);
	document.getElementById('enlargement_td').appendChild(dimensionsNode);
	
	document.getElementById('enlargement').style.visibility = 'visible';
	document.getElementById('nav').style.visibility = 'visible';
	document.getElementById('tothumbs').style.visibility = 'visible';
	document.getElementById('thumbnails').style.display = 'none';
	document.getElementById('footer').style.display = 'none';
}

function navigate(direction) {
	for(i=0;i<preload.length;i++) if(preload[i]==document.getElementById('bigImg').src.substring(document.getElementById('bigImg').src.indexOf('img.php'))) current = i;
	if(current+direction == preload.length) current = preloadPaintingsBegin-1;
	else if(current+direction < preloadPaintingsBegin) current = preload.length;
	destination = preload[current+direction];
	
	document.getElementById('enlargement').removeChild(document.getElementById('enlargement_table'));
	
	enlarge(destination.substring(destination.lastIndexOf('/')+1));
}

function tothumbs() {
	
	document.getElementById('enlargement').removeChild(document.getElementById('enlargement_table'));
	
	document.getElementById('enlargement').style.visibility = 'hidden';
	document.getElementById('nav').style.visibility = 'hidden';
	document.getElementById('tothumbs').style.visibility = 'hidden';
	document.getElementById('thumbnails').style.display = 'block';
	document.getElementById('footer').style.display = 'block';
}

