// JavaScript Document

var lastHigh  = '';
var relight   = false;

function findPos(obja) {
	var curleft = curtop = 0;
	obj = document.getElementById(obja);
	var curheight = obj.height;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
  position=new Object();
  position.x=curleft;
  position.y=curtop;
  position.h=curheight;
  return position;
 }

function focusImage(bild) {
	document.getElementById(bild).className = 'imfoc';	
}

function unfocusImage(bild) {
	document.getElementById(bild).className = 'imnor';	
}

function removeInfo(bild) {
	var inforemove = document.getElementById('info_'+bild); 
	if(inforemove){ 
		inforemove.parentNode.removeChild(inforemove);
	}
}

function createInfo(bild) {
	a = findPos(bild);
	var infodiv = document.createElement('div'); 
	infodiv.style.left = a.x + 'px';
	infodiv.style.top = a.y + a.h + 10 + 'px';
	infodiv.id = 'info_'+bild;
	infodiv.className = 'diainfo'; 
	infodiv.innerHTML = '';
	document.getElementById('in_'+bild).appendChild(infodiv);
}

function imgReq(bild) {
	var inloc = 'nix';
		if(document.getElementById('img_txt').checked) {
			inloc = 'info_'+bild;
		}
	serial_AJAX(scriptDir+'img_info.php', 'img', bild, inloc);
}

function highlighte(bild) {
	if(lastHigh) {
		if (relight == false && bild == lastHigh) {
			return;
		}
		unfocusImage(lastHigh);
		removeInfo(lastHigh);
	}
	if(bild) {
		focusImage(bild);
		if(document.getElementById('img_txt').checked) {
			createInfo(bild);
		}
		imgReq(bild);
		lastHigh = bild;
		relight = false;
	}
}

function relighte() {
	relight = true;
	highlighte(lastHigh);
}

