function gebi (elem)
{
 return document.getElementById(elem);   
}

function pageX(elem) {
        return elem.offsetParent ?
               elem.offsetLeft + pageX( elem.offsetParent ) :
               elem.offsetLeft;
}

function pageY(elem) {
        return elem.offsetParent ?
               elem.offsetTop + pageY( elem.offsetParent ) :
               elem.offsetTop;
}

function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft()
{
  return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function artifactAlt(obj, evnt, show) {
	if (!obj) return;
	var div = gebi(obj.getAttribute('id')+'_alt');
	if (!div) return;
	var act1 = obj.getAttribute('act1');
	var act2 = obj.getAttribute('act2');
	if (show == 2) {
		document.onmousemove=function(e) {artifactAlt(obj, e||event, 1)} 
		div.style.display = 'block';
		if (act1 || act2) {
			if (obj.tagName == 'IMAGE') {
				obj.src = ("images/itemact-"+ act1) + (act2 +".gif")
			} else {
				obj.style.backgroundImage = 'url(' + ("images/itemact-"+ act1) + (act2 +".gif") + ')'
			}
		}
	}
	if (!show) {
		if (act1 || act2) {
			if (obj.tagName == 'IMAGE') {
				obj.src = "images/d.gif"
			} else {
				obj.style.backgroundImage = 'url(' + "images/d.gif" + ')'
			}
		}
		div.style.display = 'none';
		obj.style.zIndex = 100;
		document.onmousemove=function(){}
		return;
	}
	obj.style.zIndex = 10000;
	var ua = navigator.userAgent.toLowerCase();
	isIE = (ua.indexOf("msie") != -1 && ua.indexOf("opera") == -1);
	isOpera = (ua.indexOf("opera") != -1);
	isGecko = (ua.indexOf("gecko") != -1);
	isSafari = (ua.indexOf("safari") != -1);
	
	if(isIE){
		var exs=event.x;
		var eys=event.y;
	}else{
		var ex = evnt.clientX - pageX(obj);
		var ey = evnt.clientY - pageY(obj);
		
		var exs = ex + self.pageXOffset;
		var eys = ey + self.pageYOffset ;
	}
	if (act1 || act2) {
		obj.style.cursor = 'default'
		obj.onclick = function(){showArtifactInfo(obj.getAttribute('aid'))}
		var coord = getCoords(obj)
		var cont = gebi("item_list")
		var rel_x = (ex + cont.scrollLeft - coord.l)
		if (rel_x >= 40) {
			var rel_y = (ey + cont.scrollTop - coord.t)
			if (act1 != 0 && rel_y < 20) {
				obj.onclick = function(){try{artifactAct(obj, act1)}catch(e){}}
				try{obj.style.cursor = 'hand'} catch(e){}
				try{obj.style.cursor = 'pointer'} catch(e){}
			}
			if (act2 != 0 && rel_y >= 40) {
				obj.onclick = function(){try{artifactAct(obj, act2)}catch(e){}}
				try{obj.style.cursor = 'hand'} catch(e){}
				try{obj.style.cursor = 'pointer'} catch(e){}
			}
		}
	}
	//alert(evnt.clientX+":"+div.offsetWidth+":"+(document.body.clientWidth - 7));
	if (evnt.clientX+div.offsetWidth> document.body.clientWidth - 7){
		var x=exs - div.offsetWidth - 10;
	}else{
		var x=exs + 10;
	}
	//var x = exs + div.offsetWidth > document.body.clientWidth - 7 ?  : exs + 10;
    if (evnt.clientY + div.offsetHeight > document.body.clientHeight - 7)
    	var y =  eys - div.offsetHeight - 10;
    else
    	var y=eys + 10;
    
    /*if (x < 0 ) {
     x = evnt.clientX - pageX(obj) - div.offsetWidth/2
     alert("true");
    }
    if (x < 7 ) {
      x = 7
    }*/
    if (x > document.body.clientWidth - div.offsetWidth - 7) {
      x= document.body.clientWidth - div.offsetWidth - 7
    }
	
	div.style.left = x + 'px';
	div.style.top = y + 'px';
}

