
var ie = document.all ? true : false;
var pup = _gel("pup");
var pupActive = false;
var mouseX = 0;
var mouseY = 0;
document.onmousemove=get_mouse;

// set dynamic coords
function get_mouse(e){
	
	mouseX = ie ? event.clientX : e["clientX"];
	mouseY = ie ? event.clientY : e["clientY"]; 

	renderPopup();

}

function renderPopup(){
	if(!pupActive){return;}
	var scrollY = document.body.scrollTop;

	var x = mouseX;
	var y = mouseY + scrollY;
	var w = pup.firstChild.offsetWidth;
	var h = pup.offsetHeight;

	var ch = document.body.clientHeight;
	var cw = document.body.clientWidth;

	var heightExtreem = ch + scrollY - h;
	var widthExtreem = cw - w;
	// alert(x+" "+y+" "+w+" "+h+" "+ch+" "+cw+" "+heightExtreem+" "+widthExtreem);
	var l = x + 40;
	var t = y + 20;
	
	if(t > heightExtreem){t = heightExtreem;}
	if(l > widthExtreem){l = widthExtreem;}
	
	if(t < y && t+h > y && l < x && l+w > x){
		t = y - h - 10;
		if(t < scrollY){l = x - w - 10;}
	}

	if(t < scrollY){t = scrollY;}
	if(t == scrollY && h > ch){
		var tw = parseInt(pup.firstChild.width);
		if(tw < cw / 2){
			tw = tw + 100 < cw / 2 ? tw + 100 : Math.ceil(cw / 2);
			pup.firstChild.width = tw;
			pup.style.width = tw+"px";
			renderPopup();
			return;
		}
	}

	pup.style.top = t+"px";
	pup.style.left = l+"px";
}

function popup(str){
	pupActive = true;
	pup.innerHTML = "<table cellspacing=0 cellpadding=0 border=0><tr><td width=12><img src='/images/pop_tl.gif'></td><td background='/images/pop_t.gif'><img src='/images/spacer.gif'></td><td width=13><img src='/images/pop_tr.gif'></td></tr><tr><td background='/images/pop_l.gif'><img src='/images/spacer.gif'></td><td width=300 bgcolor='#ffffff'>"+str+"</td><td background='/images/pop_r.gif'><img src='/images/spacer.gif'></td></tr><tr><td width=12><img src='/images/pop_bl.gif'></td><td background='/images/pop_b.gif'><img src='/images/spacer.gif'></td><td width=13><img src='/images/pop_br.gif'></td></tr></table>";
	// pup.style.width = pup.offsetWidth;
	renderPopup();
	pup.style.display = "block";
}
function kill(){
	pupActive = false;
	pup.style.display = "none";
	pup.style.width = "auto";
}
