top.obj = null;
top.noIframeAlt = 1;

function getIframeShift(obj){
	var obj = obj || window;
	var ret={'l':0,'t':0};
	while(o=obj.frameElement){
		obj=obj.parent;
		ret.l+=o.offsetLeft - obj.document.body.scrollLeft;
		ret.t+=o.offsetTop - obj.document.body.scrollTop;
		while(o=o.offsetParent){
			ret.l+=o.offsetLeft;
			ret.t+=o.offsetTop;
		}
	}
	return ret;
}
 
function artifactAlt(obj, evnt, show) {
	var art_id = obj.getAttribute('div_id');
	var div = gebi(obj.getAttribute('div_id'));
	var artifact_alt = top.gebi('artifact_alt');
	if (!artifact_alt) return;
 
	var act1 = obj.getAttribute('act1');
	var act2 = obj.getAttribute('act2');
	var act3 = obj.getAttribute('act3');
	if (act3 == 0) act3 = '' // костыль что бы не переименовывать картинки в локализациях
	if (show == 2) {
		document.onmousemove=function(e) {artifactAlt(obj, e||event, 1);}
		
		if (!artifact_alt.getAttribute('art_id') || obj.getAttribute('div_id') != artifact_alt.getAttribute('art_id')) {
			artifact_alt.innerHTML = renderArtifactAlt(obj.getAttribute('div_id'));
			//artifact_alt.innerHTML = div.innerHTML;
			artifact_alt.setAttribute('art_id',obj.getAttribute('div_id'));
		}
		
		artifact_alt.style.display = 'block';
		if (act1 || act2 || act3) {
			_background(obj, (top.locale_path + "images/itemact-"+ act1) + act2 + (act3 +".gif"));
		}
		
		top.obj = obj;
		if (top.show_alt) {
			top.show_alt();
		}
	}
	if (!show) {
		if (act1 || act2 || act3) {
			_background(obj, 'images/d.gif');
		}
		artifact_alt.style.display = 'none';
		document.onmousemove=function(){}
		return;
	}
 
	var coor = getIframeShift();
	var ex = evnt.clientX+coor.l;
	var ey = evnt.clientY+coor.t;
 
	if (top.noIframeAlt) {
		ex = evnt.clientX + top.document.body.scrollLeft;
		//ey = evnt.clientY + top.document.body.scrollTop + 200;
		ey = evnt.clientY + top.document.body.scrollTop;
	}
 
	if (act1 || act2 || act3) {
		obj.style.cursor = 'pointer'
		obj.onclick = (act1 != 0 ? function(){try{artifactAct(obj, act1)}catch(e){}} : function(){showArtifactInfo(obj.getAttribute('aid'), obj.getAttribute('art_id'))});
		_background(obj, (top.locale_path + "images/itemact-"+ act1) + act2 + (act3 + ".gif"));
		var coord = getCoords(obj)
		var cont = gebi("item_list")
		var rel_x = (ex + cont.scrollLeft - coord.l - coor.l)
		if (rel_x >= 40) {
			var rel_y = (ey + cont.scrollTop - coord.t - coor.t)
			if (rel_y < 20) {
				if (obj.getAttribute('store')) { // в магазине при клике на info необходимо выводить товар по артикулу
					obj.onclick = function(){showArtifactInfo(false, obj.getAttribute('art_id'))};
				} else { 
					obj.onclick = function(){showArtifactInfo(obj.getAttribute('aid'))}
				}
				_background(obj, top.locale_path + 'images/itemact_info' + act2 + (act3 + '.gif'));
				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){}}
				_background(obj, top.locale_path + 'images/itemact_drop' + act2 + (act3 + '.gif'));
				try{obj.style.cursor = 'hand'} catch(e){}
				try{obj.style.cursor = 'pointer'} catch(e){}
			}
		}
		if (act3 > 0 && rel_x < 20) {
			var rel_y = (ey + cont.scrollTop - coord.t - coor.t);
			if (rel_y < 20) {
				obj.onclick = function(){try{artifactAct(obj, act3)}catch(e){}};
				_background(obj, top.locale_path + 'images/itemact_use' + act2 + (act3 + '.gif'));
				try {obj.style.cursor = 'hand'} catch(e){}
				try {obj.style.cursor = 'pointer'} catch(e){}
			}
		}
	}
	var x = ex + artifact_alt.offsetWidth > top.document.body.clientWidth - 20 ? ex - artifact_alt.offsetWidth - 10 : ex + 10;
	var y = ey + artifact_alt.offsetHeight - top.document.body.scrollTop > top.document.body.clientHeight - 20 ? ey - artifact_alt.offsetHeight - 10 : ey + 10;
 
	if (x < 0 ) {
		x = ex - artifact_alt.offsetWidth/2;
	}
	if (x < 7 ) {
		x = 7;
	}
	if (x > top.document.body.clientWidth - artifact_alt.offsetWidth - 20) {
		x= top.document.body.clientWidth - artifact_alt.offsetWidth - 20;
	}
 
	artifact_alt.style.left = x;
	artifact_alt.style.top = y;
	return;
}
 
 
function renderArtifactAlt(id) {
	var a = art_alt[id];
	var bg = true;
	var i = 0;
	var content = '';
 
	content += '<table width="300" border="0" cellspacing="0" cellpadding="0" style="background-color:#FBD4A4;" class="aa-table">';
	content += '<tr><td width="14" class="aa-tl"><img src="/images/d.gif" width="14" height="24"><br></td>';
	content += '<td class="aa-t" align="center" style="vertical-align:middle"><b style="color:' + a.color + '">' + a.title + '</b></td>';
	content += '<td width="14" class="aa-tr"><img src="/images/d.gif" width="14" height="24"><br></td></tr>';
	content += '<tr><td class="aa-l" style="padding:0;"></td><td style="padding:0;">';
	content += '<table width="275" style=" margin: 3px" border="0" cellspacing="0" cellpadding="0"><tr>';
	content += '<td align="center" valign="top" width="60">';
	content += '<table width="60" height="60" cellpadding="0" cellspacing="0" border="0" style="margin: 2px" background="/' + a.image + '"><tr><td valign="bottom">';
	if (a.count && a.count != undefined) {
		content += '<div class="bpdig">' + a.count + '</div>';
	} else if (a.enchant_icon && a.enchant_icon != undefined) {
		content += a.enchant_icon;
	} else {
		content += '&nbsp;';
	}
	content += '</td></tr></table>';
	content += '</td><td>';
	content += '<div><img src="/images/tbl-shp_item-icon.gif" width="11" height="10" align="absmiddle">&nbsp;' + a.kind + '</div>';
	if (a.dur && a.dur != undefined) {
		content += '<div><img src="/images/tbl-shp_item-iznos.gif" width="11" height="10" align="absmiddle"> <span class="red">' + a.dur + '</span>/' + a.dur_max + '</div>';
	}
	if (a.price && a.price != undefined) {
		content += '<div class="b red">' + a.price + '</div>';
	}
	if (a.com && a.com != undefined) {
		content += '<div class="b red">' + a.com.title + ' ' + a.com.value + '</div>';
	}
	if (a.owner && a.owner != undefined) {
		content += '<div><b class="b red">' + a.owner.title + '</b>' + a.owner.value + '</div>';
	}
	content += '</td><td>';
	if (a.lev && a.lev != undefined) {
		content += '<div><img src="/images/tbl-shp_level-icon.gif" width="11" height="10" align="absmiddle"> ' + a.lev.title + ' <b class="red">' + a.lev.value + '</b></div>';
	}
	if (a.trend && a.trend != undefined) {
		content += '<div><img src="/images/tbl-shp_item-trend.gif" width="11" height="10" align="absmiddle">&nbsp;' + a.trend + '</div>';
	}
	if (a.cls && a.cls != undefined) {
		content += '<div><img src="/images/class.gif" width="11" height="10" align="absmiddle"> ';
		for (i in a.cls) {
			content += a.cls[i];
		}
		content += '</div>'
	}
	content += '</td></tr></table>';
	content += '<table width="100%" cellpadding="0" cellspacing="0" border="0">';
	if (a.skills && a.skills != undefined) {
		for (i in a.skills) {
			content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td>' + a.skills[i].title + '</td><td class="red" align="right">' + a.skills[i].value + '</td></tr>';
			bg = !bg;
		}
	}
	if (a.skills_e && a.skills_e != undefined) {
		for (i in a.skills_e) {
			content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td>' + a.skills_e[i].title + '</td><td class="red" align="right">' + a.skills_e[i].value + '</td></tr>';
			bg = !bg;
		}
	}
	if (a.enchant && a.enchant != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td>' + a.enchant.title + '</td><td class="red" align="right">' + a.enchant.value + '</td></tr>';
		bg = !bg;
	}
	if (a.enchant_mod && a.enchant_mod != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td>' + a.enchant_mod.title + '</td><td class="red" align="right">' + a.enchant_mod.value + '</td></tr>';
		bg = !bg;
	}
	if (a.set && a.set != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td>' + a.set.title + '</td><td class="red" align="right">' + a.set.value + '</td></tr>';
		bg = !bg;
	}
	if (a.exp && a.exp != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td>' + a.exp.title + '</td><td class="grnn b" align="right">' + a.exp.value + '</td></tr>';
		bg = !bg;
	}
	if (a.change && a.change != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td colspan="2" class="redd b">' + a.change + '</td></tr>';
		bg = !bg;
	}
	if (a.boe && a.boe != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td colspan="2" class="redd b">' + a.boe + '</td></tr>';
		bg = !bg;
	}
	if (a.desc && a.desc != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td colspan="2">' + a.desc + '</td></tr>';
		bg = !bg;
	}
	if (a.note && a.none != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td colspan="2" class="redd b">' + a.note + '</td></tr>';
		bg = !bg;
	}
	if (a.engrave && a.engrave != undefined) {
		content += '<tr class="skill_list ' + (bg ? 'list_dark' : '') + '"><td colspan="2" class="redd b">' + a.engrave + '</td></tr>';
		bg = !bg;
	}
	content += '</table>';
	content += '</td><td class="aa-r" style="padding:0px"></td></tr>';
	content += '<tr><td class="aa-bl"></td><td class="aa-b"><img src="/images/d.gif" width="1" height="5"></td><td class="aa-br"></td></tr>';
	content += '</table>';
 
	return content;
}
