/*** Copyright 2007 TheFunder.com, All Rights Reserved.-- Author Y Stefanishin ***/
(function () {
var LOCAL = "http://www.thefunded.com/feed/remote/";
var IMGS = "http://www.thefunded.com/images/remote/";
var oldScrols = [];
var currBoo = [];
var stopit, oo, sr;
var IE = navigator.userAgent.indexOf("MSIE") !=- 1;

function showObj(a, obj, boo, key) {
	if (oo && obj != oo || sr && sr != a) {
		oo.style.visibility = "hidden";
		oo.style.display = "none";
	}
	oo = obj;
	currBoo[key] = boo;
	if (obj.style.visibility == boo) return;
	var fm = document.getElementById("comp" + key);
	if (boo) {
		fm.url && (fm.src = fm.url, fm.url = null);
		showNextPosition(oo, a, key);
		clearInterval(stopit);
	} else
		stopit = setInterval(function () {
			if (!currBoo[key])
				oo.style.visibility = "hidden",
				oo.style.display = "none";
		}, 500);
	sr = a;
}

function showNextPosition(obj, a, key, bk) {
	var W = window.innerWidth ? innerWidth : document.all ? document.body.clientWidth : screen.availWidth;
	var H = window.innerHeight ? innerHeight : document.all ? document.body.clientHeight : screen.availHeight;
	var iebody = document.compatMode && document.compatMode != "BackCompat" ? document.documentElement : document.body;
	var dX = document.all ? iebody.scrollLeft : pageXOffset;
	var dY = document.all ? iebody.scrollTop : pageYOffset;
	obj.style.display = "";
	var oldScrol_str = "" + dX + " x " + dY + " - " + W + " x " + H;
	var tmpParent = obj.offsetParent;
	if (oldScrols[key] != oldScrol_str || a != sr) {
		oldScrols[key] = oldScrol_str;
		obj.style.marginLeft = "" + 0 + "px";
		obj.style.marginTop = "" + 0 + "px";
		var oTop = document.getElementById("top" + key);
		var oBot = document.getElementById("bot" + key);
		oTop.style.marginLeft = "" + 0 + "px";
		oTop.style.marginTop = "" + 0 + "px";
		oBot.style.marginLeft = "" + 0 + "px";
		oBot.style.marginTop = "" + 0 + "px";
		var imTop = document.getElementById("imtop" + key);
		var imBot = document.getElementById("imbot" + key);
		imTop.style.marginLeft = "" + 0 + "px";
		imTop.style.marginTop = "" + 0 + "px";
		imBot.style.marginLeft = "" + 0 + "px";
		imBot.style.marginTop = "" + 0 + "px";
		oTop.style.visibility = "visible";
		oBot.style.visibility = "visible";
		var objParent = obj.offsetParent;
		var pL = 0;
		var pT = 0;
		if (objParent) {
			pL = objParent.offsetLeft;
			pT = objParent.offsetTop;
		}
		ox = obj.offsetLeft + pL;
		oy = obj.offsetTop + pT;
		ow = obj.offsetWidth;
		oh = obj.offsetHeight;
		ax = a.offsetLeft;
		ay = a.offsetTop;
		aw = a.offsetWidth;
		ah = a.offsetHeight;
		var eX, eY;
		var evnt = window.event;
		var aParent = a.offsetParent;
		var x0 = 0, y0 = 0, lp = 0;
		while(objParent != aParent && lp++< 100) {
			try {
				x0 += aParent.offsetLeft;
				y0 += aParent.offsetTop;
				aParent = aParent.offsetParent;
			}
			catch(ign) {
			}
		}
		if (aParent) {
			x0 += aParent.offsetLeft;
			y0 += aParent.offsetTop;
		}
		eX = parseInt(x0 + ax + aw / 2);
		eY = parseInt(y0 + ay + ah / 2);
		var hh = 10;
		var moveX = 0, moveY = 0;
		var distX = eX - ox;
		var distY = eY - oy;
		moveX = distX - ow;
		moveY = distY - oh + (IE ? -hh : hh) - (IE ? -ah / 3 : ah / 2 + ah / 3);
		obj.style.textAlign = "right";
		var arrow = "top" + key;
		var outLeft = ox + moveX - dX;
		var outRight = dX + W - (ox + distX + ow);
		var leftVSright = outLeft >= 0 ? outLeft : outRight > 0 ? outLeft : outRight > outLeft ? outLeft : 0;
		var outTop = oy + moveY - dY;
		var outBot = dY + H - (oy + (distY - hh + (IE ? ah / 2 : ah)) + oh);
		var topVSbottom = outTop >= 0 ? outTop : outBot > 0 ? outTop : outBot > outTop ? outTop : 0;
		if (leftVSright < 0) {
			moveX = distX;
			obj.style.textAlign = "left"
		} else
			obj.style.textAlign = "right";
		if (topVSbottom < 0) {
			moveY = distY - hh + (IE ? ah / 2 : ah);
			arrow = "bot" + key;
		}
		outLeft = ox + moveX - dX;
		outRight = dX + W - (ox + moveX + ow);
		if (outLeft < 0 || outRight < 0) moveX = outLeft < 0 ? moveX + aw / 2 : moveX - aw / 2;
		obj.style.marginLeft = "" + parseInt(moveX) + "px";
		obj.style.marginTop = "" + parseInt(moveY) + "px";
		document.getElementById(arrow).style.visibility = "hidden";
	}
	obj.style.visibility = "visible";
}

function removeAmp(name) {
	var strArr = name.split('&amp;');
	var sb = "";
	for (var i = 0; i < strArr.length; i++) {
		sb += strArr[i];
		if (i < strArr.length - 1)
			sb += String.fromCharCode(38);
	}
	return sb;
}

function showTokenizedLink(aa, obj, name, title, i) {
	var ind0 = 0;
	var ind1 = name.indexOf(" ");
	var key = title + i;
	var zn = 0;
	var a;
	name = removeAmp(name);
	if (ind1 ==- 1)
		a = aa;
	else {
		aa.innerHTML = "";
		while(a === aa || ind1 !=- 1) {
			var tx;
			if (ind1 !=- 1) {
				tx = trim(name.substring(ind0, ind1));
				if (IE)
					aa.appendChild(document.createTextNode(tx.substring(0, 1)));
				a = document.createElement("acronym");
				var tn = document.createTextNode(IE ? tx.substring(1) : tx);
				a.appendChild(tn);
				aa.appendChild(a);
				if (ind1 != name.length)
					aa.appendChild(document.createTextNode(" "));
			}
			a.id = tx + i;
			a.onmouseover = function() {
				showObj(this, obj, true, key)
			};
			a.onmouseout = function() {
				showObj(this, obj, false, key)
			};
			if (ind1 == name.length)
				break;
			ind0 = ind1;
			ind1 = name.indexOf(" ", ind0 + 1);
			if (ind1 ==- 1)
				ind1 = name.length;
		}
	}
	document.body.appendChild(obj);
	obj.onmouseout = function() {
		currBoo[key] = false;
	};
	obj.onmouseover = function() {
		currBoo[key] = true;
	};
}

function showLink(a, obj, name, title, i) {
	var key = title + i;
	a.id = "z_vzt" + key;
	a.onmouseover = function() {
		showObj(this, obj, true, key)
	};
	a.onmouseout = function() {
		showObj(this, obj, false, key)
	};
	document.body.appendChild(obj);
}

function replaceAmp(str) {
	for (var i = 0; i < str.length; i++) {
		var ind = charCodeAt(i);
		if (ind == 38)
			var ss = str.substring(0, i);
	}
	return str;
}

function strt() {
	var title = null;
	var name = null;
	var h = document.getElementsByTagName("a");
	try {
		var lastDiv;
		for (var i = 0; i < h.length; i++) {
			var a = h[i];
			if (a.className == "fund") {
				var f = a.parentNode;
				var dv = document.createElement("div");
				name = a.innerHTML;
				title = removeAmp(trim(name.toLowerCase()));
				buildComementary(f, dv, name, title, i);
				if (name.indexOf(" ") !=- 1)
					showTokenizedLink(a, dv, name, title, i);
				else
					showLink(a, dv, name, title, i);
			}
		}
	}
	catch(ign) {
	}
}

function buildComementary(f, dv, name, title, i) {
	var kk = title + i;
	dv.style.visibility = "hidden";
	dv.id = "pop" + kk;
	dv.name = "pop" + kk;
	dv.vspace = 0;
	dv.hspace = 0;
	dv.allowTransparency = "true";
	dv.scrolling = "no";
	dv.marginWidth = 0;
	dv.marginHeight = 0;
	dv.frameBorder = 0;
	dv.style.border = 0;
	dv.style.zindex = 1000;
	dv.style.position = "absolute";
	dv.style.display = "none";
	dv.style.clear = "both";
	dv.style.margin = "0px";
	dv.style.padding = "0px";
	dv.style.lineHeight = "normal";
	var fchld = document.createElement("div");
	fchld.id = "top" + kk;
	fchld.name = "top" + kk;
	fchld.style.verticalAlign = "bottom";
	fchld.vspace = 0;
	fchld.hspace = 0;
	fchld.allowTransparency = "false";
	fchld.scrolling = "no";
	fchld.marginWidth = 0;
	fchld.marginHeight = 0;
	fchld.frameBorder = 0;
	fchld.style.border = 0;
	fchld.style.position = "relative";
	fchld.style.clear = "both";
	fchld.style.margin = "0px";
	fchld.style.visibility = "visible";
	fchld.style.padding = "0px";
	fchld.style.lineHeight = "normal";
	fchld.style.minHeight = 13;
	fchld.style.maxHeight = 13;
	var im = document.createElement("img");
	if (IE)
		im.style.cssText = "FLOAT: none;";
	im.src = IMGS + "remote_arrow_top.gif";
	im.border = 0;
	im.align = "bottom";
	im.style.clear = "both";
	im.style.borderWidth = 0;
	im.style.position = "relative";
	im.id = "imtop" + kk;
	im.style.margin = "0px";
	im.style.padding = "0px";
	im.style.cssFloat = "none";
	fchld.appendChild(im);
	dv.appendChild(fchld);
	var fm = document.createElement("iframe");
	fm.src = 'about:blank';
	fm.url = LOCAL + window.encodeURIComponent(title);
	fm.frameborder = 0;
	fm.vspace = 0;
	fm.hspace = 0;
	fm.width = 300;
	fm.height = 300;
	fm.marginwidth = 0;
	fm.marginheight = 0;
	fm.scrolling = "no";
	fm.id = "comp" + kk;
	fm.name = "comp" + kk;
	fm.style.border = 0;
	fm.style.margin = "0px";
	fm.style.padding = "0px";
	dv.appendChild(fm);
	fchld = document.createElement("div");
	fchld.id = "bot" + kk;
	fchld.name = "bot" + kk;
	fchld.vspace = 0;
	fchld.hspace = 0;
	fchld.allowTransparency = "false";
	fchld.scrolling = "no";
	fchld.marginWidth = 0;
	fchld.marginHeight = 0;
	fchld.frameBorder = 0;
	fchld.style.border = 0;
	fchld.style.position = "relative";
	fchld.style.clear = "both";
	fchld.style.visibility = "visible";
	fchld.style.margin = "0px";
	fchld.style.padding = "0px";
	fchld.style.lineHeight = "normal";
	fchld.style.minHeight = 13;
	fchld.style.maxHeight = 13;
	var im = document.createElement("img");
	if (IE)
		im.style.cssText = "FLOAT: none;";
	im.src = IMGS + "remote_arrow_bottom.gif";
	im.border = 0;
	im.align = "top";
	im.style.clear = "both";
	im.style.borderWidth = 0;
	im.style.position = "relative";
	im.id = "imbot" + kk;
	im.style.margin = "0px";
	im.style.padding = "0px";
	im.style.cssFloat = "none";
	fchld.appendChild(im);
	dv.appendChild(fchld);
}

function trim(s) {
	if (s == null || s == this._undef || s == "") return "";
	for (var i = 0; i < s.length; i++) {
		var c = s.charCodeAt(i);
		if ((c >= 33) && (c <= 126 ))
			break;
	}
	for (var j = s.length - 1; j >= i; j--) {
		var c = s.charCodeAt(j);
		if ((c >= 33) && (c <= 126 ))
			break;
	}
	s = s.substring(i, j + 1);
	return s;
}

IE ? attachEvent('onload', strt) : addEventListener('load', strt, false);
}())
