var currentZoomIndex = 0;

function recenter() {
	// Check for dragging out of bounds
	c = $('zoom_container');
	x = c.getWidth();
	y = c.getHeight();
	z = $('zoomer');
	zx = z.getWidth();
	zy = z.getHeight();
	z.style.left = (Math.floor(x/2) - Math.floor(zx/2)) + "px";
	z.style.top = (Math.floor(y/2) - Math.floor(zy/2)) + "px";
}

function zoom(index) {

	// Zoom in on current image section
	if (currentZoomIndex != index) {
		
		if (use_sid) {

			zc = $('zoom_container');
			x = zc.getWidth() * index;
			y = zc.getHeight() * index;
			$('zoomer').src = 'http://lt01.nypl.org/lizardtech/iserv/getimage?cat=NYPL&item=9-27-2007/' + nypl_doc_id + 'd.sid&wid=' + x + '&hei=' + y + '&rgn=0,0,1,1';

			// highlight current nav button
			for (var i = 1;i < 4; i++) {
				$('zoom_nav' + i).style.background = "none"
			}
			$('zoom_nav' + index).style.background = "#999"

		} else if (local_file) {

			$('zoomer').src = '/assets/' + nypl_doc_id + '.jpg';

		} else {

			$('zoomer').src = 'http://images.nypl.org/?id=' + nypl_doc_id + '&t=w';

		}

		currentZoomIndex = index;

	}
}

function download_image() {
	zoom(3);
	window.location = $('zoomer').src;
}
