// John Edward Chandler Javascript

var preImages = new Array();
var widths = new Array();
var heights = new Array();
var loaded = new Array();
var currCount = 0;
var imageCount = 0;
var currentImage = 0;

var bgLeft = 235;

function setImageCount(count) {
	imageCount = count;	
}

function loadImage(imagenum)
{	
	currentImage = imagenum;
	var title = document.getElementById('art_title');
	var mainimage = document.getElementById('main_image');
	/*
	if(widths[imagenum] < heights[imagenum])
		background.src = "images/portfoliopage/vertical-frame.gif";
	else
		background.src = "images/portfoliopage/horizontal-frame.gif";
	*/
	//var ratio = .12
	
	//background.width = widths[imagenum] + 2*ratio*widths[imagenum];
	//background.height = heights[imagenum] + ratio*heights[imagenum];
	mainimage.style.paddingTop = 0;
	//mainimage.style.paddingTop = (700 - heights[imagenum])/2 + "px";
	title.innerHTML = titles[imagenum];
	mainimage.src = images[imagenum];
	//mainimage.style.left = (bgLeft - widths[imagenum]/2) + "px";
}

function loadImages() { 
	for (i = 0; i < images.length; i++) { 
		preImages[i] = new Image()
		preImages[i].src = images[i]
	}
	for (i = 0; i < preImages.length; i++) { 
		loaded[i] = false
	}
	checkLoad()
}

function checkLoad() {
	if (currCount == preImages.length) {
		//document.getElementById('please_wait').style.display = "none";
		document.getElementById('art_title').style.display = "block";
		document.getElementById('main_image').style.display = "block";
		//document.getElementById('set').style.display = "inline"; 
		loadImage(0);
		//location.replace(locationAfterPreload)
		return
	}
	for (i = 0; i <= preImages.length; i++) {
		if (loaded[i] == false && preImages[i].complete) {
			loaded[i] = true
			//eval("document.img" + currCount + ".src=dots[1].src")
			heights[i] = preImages[i].height;
			widths[i] = preImages[i].width;
			//alert(heights[i] + ', ' + widths[i]);
			currCount++
		}
	}
	timerID = setTimeout("checkLoad()",10) 
}

function hoverState(el,on) {
	if(on)
		el.className = "hoveron";
	else
		el.className = "hoveroff";
}

function over_img(name, img)
{document [name].src = img}

function nextImage() {
	if(currentImage + 1 < imageCount){
		loadImage(currentImage + 1);
	}
	else {
		loadImage(0);
	}
}

function prevImage() {
	if(currentImage > 0) {
		loadImage(currentImage - 1);
	}
	else {
		loadImage(imageCount - 1);	
	}
	
}


