var currimg = 0;

function getAbsTop(top, elem) {
	if (!elem.offsetParent) return top + elem.offsetTop;
	top += elem.offsetTop;
	elem = elem.offsetParent;
	return getAbsTop(top, elem);
}

var currSmall = null;

function showBig(small, id) {
  currSmall = small;

	if (id != currimg) {
		if (currimg != 0) {
			hideBig(currimg);
		}

		var url = '?action=get_info';
		var pars = 'item_id=' + id;

		var myAjax = new Ajax.Request(
		url,
		{
			method: 'post',
			postBody: pars,
			encoding: 'ISO-8859-1',
			onComplete: itemInfoResponse
		});


		currimg = id;
	} else {
		hideBig(currimg);
		big.innerHTML = '';
	}
}

function hideBig(id) {
	//document.getElementById('big_image').style.display = 'none';
	document.getElementById('big_image').style.visibility = 'hidden';
	currimg = 0;
}

function highlightThumb(elem, highlight) {
	var help = elem.id.split('_');
	var thumb = document.getElementById('thumb_' + help[1]);
	//thumb.style.border = (highlight ? "solid 1px #000000" : "solid 1px #999999");
	thumb.style.borderColor = (highlight ? "#3366FF" : "#FFFFFF");
}

function itemInfoResponse(resp) {
	var offset_top = getAbsTop(0, currSmall);

	if(offset_top < 110) { //static fix to avoid having thumbs placed way up high
		offset_top = 110;
	}

	var big = document.getElementById('big_image');
	big.innerHTML = resp.responseText;

	var imgWidth = document.getElementById('nisse').width;
	var left = 330 + (510-imgWidth)/2;
	big.style.left = left + "px";
	big.style.top = String(offset_top - 30) + "px";
	big.style.width = imgWidth + 'px';
	big.style.visibility = 'visible';
	//var image = big.firstChild.childNodes[1].firstChild;
}

function userResolution() {
	var url = '?action=set_resolution';
	var pars = 'screen_width=' + screen.width + '&screen_height=' + screen.height;

	var myAjax = new Ajax.Request(
	url,
	{
		method: 'post',
		postBody: pars,
		encoding: 'ISO-8859-1',
		onComplete: myResponse
	});
}

function myResponse(resp) {
	$('page_content').innerHTML = resp.responseText;
}


function openPop(url, name, param) {
	var pop = window.open(url, name, param);
	pop.focus();
}

//image hack 2009-04-06
function updateImageList(ex_id, more_images) {

  //make sure we hide any open "big"
  hideBig();

  var url = '?';
  var pars = "CoMeT_function=run_module&module=Exhibition&function=update_image_list&ex_id=" + ex_id + "&more_images=" + more_images;

  var myAjax = new Ajax.Request(
    url,
    {
      method: 'post',
      postBody: pars,
      encoding: 'ISO-8859-1',
      onComplete: updateImageListResponse
    });
}

function updateImageListResponse(resp) {
  $('list_exhibition_art').innerHTML = resp.responseText;
}
