var curPhoto = 1;
var theNextPhoto = 1;

var pb = $('thumbs_container');

var imgWidth = 504;

var imagePath = "";

var imgHeight = 500;

var zoomHeight = 1000;

isZoomed = false;

var theCaptions = [];

var isHome;

if (document.body.id.match("home-page")) {
	var zoomWidth = 1011;
	isHome = true;
	imagePath = "images/full/picture";
	theCaptions = [["Scrumtrulescent", "10.5\" x 10.5\""], ["Me, Myself and I", "11.5\" x 13\""], ["The Flaneur", "14\" x 16\""], ["A Conversation Among the Creatures and People Who<br>Hid in My Closet When I Was a Little Girl", "14\" x 14.5\""], ["The Coin Appears", "7.5\" x 9.5\""],["The Proper Sorrows of the Soul",""],["At The End Of A Long Scream",""], ["Help! He Left the Side Door Open and His Brown Show<br>on the Doorknob", "8\" x 8\""], ["Can't Remember", "11\" x 11\""], ["The Coin Disappears", "12\" x 13\""], ["Looking For Leah", "10\" x 12\""], ["Tumbling Cataclysmic Vortex", "12\" x 14\""], ["Shaking in My Boots", "11\" x 13\""], ["Unreliable Narrator", "14.5\" x 14.5\""], ["A Stranger Comes to Town or<br>Someone Goes on a Journey", "10\" x 17\""], ["A Single Trick Can Make All The Difference", "15\" x 16\""], ["Crusher of Dreams", "8\" x 8\""], ["A Logical Alternative", "17\" x 17\""], ["Rain Salesman", "11\" x 11\""],["God In A Rumpled Trenchcoat",""], ["Born in a Storm", "8\" x 8\""], ["He Looked and Acted Like Our Idea of a Hero", "12\" x 12\""], ["Super Etoile", "15\" x 23\""], ["Ghost Drops By to Say Boo", "21\" x 13\""], ["No More Than A Necessary Fiction", "10\" x 12\""], ["All You Say Will Be Used Against You",""],["Row Row Row Your Boat", "10\" x 12\""], ["When a Poem Offended Him He Ate It", "11\" x 13\""], ["I'm Not Lying, I'm Telling a Future Truth",""],["I'm Not Lying, I'm Telling a Future Truth", "6\" x 6\""], ["No Dialogue Except \"Beep Beep\"", "6.5\" x 6.5\""], ["Agamemnon's Daughter", "14\" x 14\""], ["An Overrated Way of Passing Time", "10\" x 10\""], ["Missing Inaction", "9\" x 10.5\""], ["She Forgot-Was it Abracadabra, Hocus Pocus,<br>Alakazam, Open Sesame, Presto-change-o or Shazam", "13\" x 13\""], ["Bright and Poodle Project", "13\" x 13\""], ["There's a Bad Moon on the Rise", "14.5\" x 18\""], ["They Only Speak When They Have Something To Say", "8\" x 8\""], ["Chacmools", "10\" x 12\""], ["Dance of Delusion", "7.5\" x 7.5\""], ["The Year 24", "24\" x 24\""],["His Grief Left Him No Language But A Cry",""],["Time Puzzle",""]];
}

if (document.body.id.match("assem-page")) {
	zoomWidth = 561;
	isHome = false;
	imagePath = "images/full/picture";
	theCaptions = [["Unbirthday (Music Box - Closed)","5\" x 9\""], ["Unbirthday (Music Box - Open)","5\" x 9\""], ["Another Shrug of My Life",""], ["Crux",""], ["Beautiful Dreamer (Music Box Cabinet)","14\" x 18\""], ["Catbird Feet","9.5\" x 11.5\""], ["Virgil Understood","6\" x 17\""], ["Self-Portrait","5\" x 9\""],["I Am An Optimist But About Nothing",""],["I Am An Optimist But About Nothing (Side View)",""],["I Am An Optimist But About Nothing (Side View)",""],["He Looked and Acted Like Our Idea of a Hero",""],["Nosey Parker",""],["Lazy Angels",""],["Land Near (Music Box)","9\" x 9\" x 4\""], ["Please Break My Heart","15\" x 17\""], ["The Valley of the Shadow of Death","16\" x 21\""], ["Thy Kingdom Come","11\" x 14\""], ["Thy Will Be Done","10\" x 13\""],["2307	",""],["Capilla",""]];
	
}

/*
function findPosX (obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (1) {
			curleft += obj.offsetLeft;
			if (!obj.offsetParent) {break;}
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function setOffset () {
	xOffset = findPosX (document.getElementById('thumbs'));
}
*/

xOffset = 286;

var slideActive = false;

var newX = 0;
var mouseX = 0;
var dist = 0;
var newScroll = 0;

var safariJunk = true;

var knobWidth = 14;

//var xOffset = 0;
//xOffset = 312;
//setOffset();
//window.onresize = setOffset;

var isSafari2 = false;

if (document.childNodes && !document.all && !navigator.taintEnabled && !window.devicePixelRatio) {
	isSafari2 = true;
}

var allA = $$('a');

for (i=0; i<allA.length; i++) {
	allA[i].onfocus = function () {this.blur();};
} 

function findThumbs() {
	//temp = document.getElementById('thumbs_container');
	all_thumbs = pb.getElementsByTagName('a');
	var number_of_link = all_thumbs.length;
	for(i=0;i<number_of_link;i++){
		all_thumbs[i].onfocus = new Function("this.blur();");
		all_thumbs[i].onclick = new Function("jumpToPhoto("+(i+1)+"); return false;");
	}	
}

allA = "";

/*
function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		{var y = x.currentStyle[styleProp];}
	else if (window.getComputedStyle)
		{var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);}
	return y;
}
*/

// get size of thumbnail container

function getThumbElements() {
	if (document.getElementById("thumbs")) {
		var t = document.getElementById("thumbs");
		var getwidths = t.getElementsByTagName("img");
		var widths = [];
		for (x=0;x<getwidths.length; x++){
			widths[x] = getwidths[x].width;
		}
		return widths;
	}
}

var widths = getThumbElements();
var moveX;
var temp;
var temps = [];
var moves = [0,0];
var windowWidth = 643;
//alert(windowWidth);

temps[0] = 0;

for (x=0; x<widths.length-1; x++)
{
	if (x==0) {
		temps[x] = widths[x] + 9;
		} else {	
		temps[x] = temps[x-1] + widths[x] + 9;
		}
	temp = (temps[x] + Math.round(widths[x+1] / 2) - Math.round(windowWidth / 2)) * -1;
	if (temp<0) {
			moves[x+2] = temp;
		}else{
			moves[x+2] = 0;
		}
}

scrollWidth = 0;
for (x=0; x<widths.length; x++) {
	if (window.ie) {
		scrollWidth += widths[x];
	}else{
		scrollWidth += 9;
		scrollWidth += widths[x];
	}
}
scrollWidth -= 9;
totalPhotos = widths.length;


var step = windowWidth;
var the_end = (scrollWidth - windowWidth) * -1;
//alert(widths + "");


// *** SCROLLBAR FUNCTIONS ***

//if (scrollWidth > windowWidth) {

// setInterval polls for slideActive being true
	$('thumbs_container').onmouseover = function() {
		slideActive = true;
	};

// activates the speed control
$('thumbs_container').onmousemove = function(event) {
	slideActive = true;
	var e = new Event (event);
	//doSomething(e);
	//mouseX = e.page.x - xOffset;
	//$('title').innerHTML = 	e.page.x;
	mouseX = e.page.x - xOffset;
};

// stops the scroller
$('thumbs_container').onmouseout = function() {
	slideActive = false;
};

var panActive = false;
var resumePan = false;
var firstrun = true;
var zcur = $('zoomcursor');

$('zoomcontainer').onmousedown = function(event) {
	var e = new Event(event);
	e.preventDefault();
	if (isZoomed) {
		panActive = true;
	}
	mouseX = e.page.x;
	mouseY = e.page.y;
};

$('viewer').onmousemove = function(event) {
	if (panActive) {
		var e = new Event (event);
		mouseX = e.page.x;
		mouseY = e.page.y;
	}
};

$('viewer').onmouseup = function() {
	if (isZoomed) {
		panActive = false;
		resumePan = true;
	}
};

var zpb;
zpb = $('zoomphotobox');

var panXoffset = 656;
var panYoffset = 421;
var tempPanX;
var tempPanY;

// this defines the area, left and right, where the mouse hover will cause scrolling to happen
var leftHover = Math.round (windowWidth * 0.35);
var rightHover = Math.round (windowWidth * 0.65);

// does the heavy work, always being polled by setInterval
function runSlider () {
	if (slideActive == true && panActive != true) {
		if (mouseX < leftHover) {
			dist = (leftHover - mouseX) / 50;
		} else if (mouseX > rightHover) {
			dist = (rightHover - mouseX) / 50;
		} else {
			dist = 0;
		}
		dist = Math.round (dist);
		//$('title').innerHTML = mouseX;
		newX += dist;
		if (newX > 0) { newX = 0; }
		if (newX < the_end) { newX = the_end; }
		pb.style.left = newX + 'px';
		// move scrollbar
		moveKnob();
	}
	//$('debug').innerHTML = newX;
	if (panActive == true) {
		if (firstrun) {
			panXoffset = mouseX - parseInt(zpb.style.left,10);
			panYoffset = mouseY - parseInt(zpb.style.top,10);
			firstrun = false;
		}
		if (resumePan) {
			panXoffset = mouseX - tempPanX;
			panYoffset = mouseY - tempPanY;
			resumePan = false;
		}
		tempPanX = mouseX - panXoffset;
		tempPanY = mouseY - panYoffset;
		zpb.style.left = Math.round(((mouseX - panXoffset)) * 1.1) + "px";
		zpb.style.top = Math.round(((mouseY - panYoffset)) * 1.1) + "px";
	}
}

var slider = new Slider ($('slider'), $('knob'), {
	onChange:function(v) {
		//newScroll = parseInt($('knob').style.left);
		newX = Math.round((scrollWidth - windowWidth) * ((v * -1) / step));
		pb.style.left = newX + 'px';
	},
	steps: step,
	mode: 'horizontal',
	wheel: false
});


// start slider
slideInterval = setInterval("runSlider()", 10);


 // ...with keyboard support (code from canopycanopycanopy.com)
document.addEvent('keydown', function(e) {
	 e = new Event(e); // .stop() // oops don't stop, we might want that!
	 if (e.key == 'right') {
	 nextPhoto();
	 } else if (e.key == 'left') {
	 prevPhoto();
	}
});

// preload first two images
preloadPhoto ();
theNextPhoto = 2;
preloadPhoto ();

setTimeout ('$("loading").style.display = "none"', 150); 

/*
if (document.body.id.match("assem-page")) {
	setOffset();
}
*/

findThumbs();
