var func = "", timeout = 0; 
var timeout_handler = setTimeout(func, timeout);

function newTimeout(f, t)
{
	timeout_handler = setTimeout(f, t);
	func = f;
	timeout = t;
}

function stopTimeout()
{
	clearTimeout(timeout_handler);
}

function resetTimeout()
{
	newTimeout(func, 1500);
}

function text_pagination(str, chars, placement)
{
	if(str!="" && document.getElementById(placement))
	{
		if(str.length>chars && str.length-chars > 20)
		{
			show = str.substr(0, chars);
			next = str.substr(chars, str.length);
			while(show.substring(show.length-1, show.length)!=" ")
			{
				next = show.substr(show.length-1, show.length)+next;
				show = show.substr(0, show.length-1);
			}
			document.getElementById(placement).innerHTML = "<a>"+show+"</a>";
			newTimeout('text_pagination("'+next+'", '+chars+', "'+placement+'")', 5000);
		}
		else
		{
			document.getElementById(placement).innerHTML = "<a>"+str+"</a>";
			newTimeout("new_quote("+chars+")", 5000);
		}
	}
}
function new_quote(chars)
{
	ajax_action("show_quote", "/ajax-get_random_quote-server", "", "", "");
}
function show_quote(text)
{
	text_pagination(text, 115, "dynamic_quote");
}

function set_external_links()
{
	links = document.getElementsByTagName('a');
	for(i in links)
	{
		if (links[i].className=="external_link")
		{
			links[i].onclick=function linkblank(event)
			{
				window.open(this.href,'_blank');
				return false;
			}
		}
	}
}

function whoisonline()
{
	var w = screen.availWidth;
	var h = screen.availHeight;
	var popW = 352, popH = 320;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	window.open("/popup-whoisonline-html", "whoisonline", "height="+popH+", width="+popW+",top="+topPos+", left="+leftPos+", toolbar=0, menubar=0, resizable=0, location=0, status=0, scrollbars=0");
}