// Decors

var isIE = ((document.all)?true:false);

function InitDecor(id) {
	try {
		var thisItem = document.getElementById(id);
	} catch(err) {
		return false;
	}
	if (thisItem != null) {
		// Decor found
		var thisMag = document.getElementById("mag"+id);
		thisMag.style.top = GetRealY(thisItem)+6;
		thisMag.style.left = GetRealX(thisItem)+7;
		thisMag.style.display = "inline";
		thisMag.style.cursor = "pointer";
		thisMag.onclick = PopMag;
	} else {
		return false;
	}
}

function InitDecors() {
	InitDecor('decor1');
	InitDecor('decor2');
	InitDecor('decor3');
	document.getElementById("shadow").onclick = Dummy;
}

function ResetDecors() {
	InitDecor('decor1');
	InitDecor('decor2');
	InitDecor('decor3');
	for (var i=1;i<4;i++) {
		var thispop = document.getElementById("magdecor"+i);
		if (thispop != null) {
			if (document.getElementById("pop"+i).style.display == "block") SetPop(thispop);
		}
	}
}

function SetEvents() {
	window.onresize = ResetDecors;
}

function PopMag(ev) {
	if (isIE) {
		var who = event.srcElement;
	} else {
		var who = ev.target;
	}
	SetPop(who);
}

function SetPop(who) {
	document.getElementById("shadow").style.display = "block";
	document.getElementById("shadow").style.width = document.body.scrollWidth+"px";
	document.getElementById("shadow").style.height = document.body.scrollHeight+"px";
	var thisPop = document.getElementById("pop"+who.id.substr(8,1));
	thisPop.style.display = "block";
	var visibleTop = Math.round(document.body.clientHeight/2 - thisPop.offsetHeight/2);
	visibleTop += document.body.scrollTop;
	var visibleLeft = Math.round(document.body.clientWidth/2 - thisPop.offsetWidth/2);
	visibleLeft += document.body.scrollLeft;
	thisPop.style.top = visibleTop;
	thisPop.style.left = visibleLeft;
	var thisUnmag = document.getElementById("unmag");
	thisUnmag.style.top = visibleTop + 7;
	thisUnmag.style.left = visibleLeft + 8;
	thisUnmag.style.zIndex = 100;
	thisUnmag.style.display = "inline";
	thisUnmag.setAttribute("closewho",thisPop.id);
}

function ClosePop(who) {
	var closewho = document.getElementById(who.getAttribute("closewho"));
	closewho.style.display = "none";
	document.getElementById("unmag").style.display = "none";
	document.getElementById("shadow").style.display = "none";
}

function GetRealX(who) {
	try {
		if (who.tagName.toUpperCase() == "BODY" || who.tagName.toUpperCase() == "HTML") {
			return 0;
		} else {
			return (who.offsetLeft + GetRealX(who.offsetParent));
		}
	} catch(err) {
	}
}

function GetRealY(who) {
	try {
		if (who.tagName.toUpperCase() == "BODY" || who.tagName.toUpperCase() == "HTML") {
			return 0;
		} else {
			return (who.offsetTop + GetRealY(who.offsetParent));
		}
	} catch(err) {
	}
}

function Dummy() {
	return false;
}