var popup_x0 = 0;
var popup_y0 = 0;
var popup_x1 = 0;
var popup_y1 = 0;
var popup_w0 = 0;
var popup_h0 = 0;
var popup_w1 = 0;
var popup_h1 = 0;
var animation_id = 0;
var frame_num = 0;

function showLogin(e) {
	var win_w = 0;
	var win_h = 0;
	if (window.innerWidth) {
		win_w = window.innerWidth;
		win_h = window.innerHeight;
	} else if (document.documentElement.clientWidth) {
		win_w = document.documentElement.clientWidth;
		win_h = document.documentElement.clientHeight;
	} else if (document.body.clientWidth) {
		win_w = document.body.clientWidth;
		win_h = document.body.clientHeight;
	}
	var offset_x = 0;
	var offset_y = 0;
	if (window.pageXOffset || window.pageYOffset) {
		offset_x = window.pageXOffset;
		offset_y = window.pageYOffset;
	} else if (document.documentElement.scrollLeft || document.documentElement.scrollTop) {
		offset_x = document.documentElement.scrollLeft;
		offset_y = document.documentElement.scrollTop;	
	} else if (document.body.scrollLeft || document.body.scrollTop) {
		offset_x = document.body.scrollLeft;
		offset_y = document.body.scrollTop;
	}
	var frame_w = 346;
	var frame_h = 440;
	popup_w1 = frame_w + 16;
	popup_h1 = frame_h + 16;
	popup_x1 = Math.round((win_w - popup_w1) / 2) + offset_x;
	popup_y1 = Math.round((win_h - popup_h1) / 2) + offset_y;

	popup_w0 = Math.round(popup_w1 / 10);
	popup_h0 = Math.round(popup_h1 / 10);

	if (!e) var e=window.event;
	if (e.pageX || e.pageY) {
		popup_x0 = e.pageX;
		popup_y0 = e.pageY;
	} else if (e.clientX || e.clientY) {
		popup_x0 = e.clientX + offset_x;
		popup_y0 = e.clientY + offset_y;
	} else {
		popup_x0 = Math.round(win_w / 2) + offset_x;
		popup_y0 = Math.round(win_h / 2) + offset_y;
	}
	popup_x0 -= Math.round(popup_w0 / 2);
	popup_y0 -= Math.round(popup_h0 / 2);
  	
	var div = document.getElementById("login_popup");
	if (!div) {
		div = document.createElement("div");
		div.style.position = "absolute";
		div.id = "login_popup";
		document.body.appendChild(div);
	}
	div.style.left = popup_x0 + "px";
	div.style.top = popup_y0 + "px";
	div.style.width = popup_w0 + "px";
	div.style.height = popup_h0 + "px";
	div.style.zIndex = 1000;
	div.innerHTML = '<div style="position:absolute; left:2px; top:2px; background-color:#000000; opacity:0.5; filter:alpha(opacity=80); border-radius:7px; -moz-border-radius:7px; -webkit-border-radius:7px; height:100%; width:100%;"></div>' +
		'<iframe id="login_iframe" frameborder="0" scrolling="no" src="/login.asp" allowtransparency="false" style="position:absolute; left:8px; top:8px; border:none; overflow:hidden; width:' + (popup_w0 - 16) + 'px; height:' + (popup_h0 - 16) + 'px; background-color:#FFFFFF;"></iframe>';
	startAnimation();

	return false;
}

function hideLogin() {
	var div = document.getElementById("login_popup");
	if (div) document.body.removeChild(div);
}

function startAnimation() {
	frame_num = 1;
	if (animation_id) clearInterval(animation_id);
	animation_id = setInterval("nextFrame()", 40);
}

function nextFrame() {
	if (frame_num < 10) {
		++frame_num;
		var div = document.getElementById("login_popup");
		if (div) {
			var pct = frame_num / 10;
			div.style.left = popup_x0 + Math.round(pct * (popup_x1 - popup_x0)) + "px";
			div.style.top = popup_y0 + Math.round(pct * (popup_y1 - popup_y0)) + "px";
			var w = popup_w0 + Math.round(pct * (popup_w1 - popup_w0));
			var h = popup_h0 + Math.round(pct * (popup_h1 - popup_h0));
			div.style.width = w + "px";
			div.style.height = h + "px";
			var obj = document.getElementById("login_iframe");
			if (obj) {
				obj.style.width = (w - 12) + "px";
				obj.style.height = (h - 12) + "px";
			}
		}
	} else {
		clearInterval(animation_id);
		animation_id = 0;
	}		
}
