var g_enc = '0zMcmVokRsaqbdrfwihuGINALpTjnyxtgevE', g_encNext = 'Z', g_layers, g_tooltip, g_tooltipTable, g_tooltipTd, g_hilite, g_iframe, g_lastMenuA = 0, g_username = '';


function g_Init(tooltip)
{
	_ = ce('div');
	_.className = 'layers';
	document.body.appendChild(_);
	g_layers = _;

	if(tooltip)
	{
		_ = g_CreateTooltip();
		_.style.cursor = 'default';
		_.style.position = 'absolute';
		_.style.left = _.style.top = '-2323px';
	
		document.body.appendChild(_);
		g_tooltip      = _;
		g_tooltipTable = gE(_, 'table')[0];
		g_tooltipTd    = gE(g_tooltipTable, 'td')[0];

		_ = ce('div');
		_.className = 'wowhilite';
		g_hilite = _;
	
//		if(isIE6)
//		{
//			_ = ce('iframe');
//			_.src = 'javascript:0;';
//			_.frameBorder = 0;
//			g_layers.appendChild(_);
//			g_iframe = _;
//			document.write('<div style="visibility: hidden; position: absolute; left: -2323px; top: -2323px"><img src="http://www.wowhead.com/images/icon_border_small.gif"><img src="http://www.wowhead.com/images/icon_border_medium.gif"><img src="http://www.wowhead.com/images/map_party.gif"></div>');
//		}
	}
}

function g_ToggleDisplay(el)
{
	if(el.style.display == 'none')
	{
		el.style.display = '';
		return true;
	}
	else
	{
		el.style.display = 'none';
		return false;
	}
}

function g_FixTooltip(ttContainer, noShrink, visible)
{
	var tooltipTd = gE(ttContainer, 'td')[0];
	var c = tooltipTd.childNodes;

	if(c.length >= 2 && c[0].nodeName == 'TABLE' && c[1].nodeName == 'TABLE')
	{
		var m;
		if(c[1].offsetWidth > 300)
			m = Math.max(300, c[0].offsetWidth) + 20;
		else
			m = Math.max(c[0].offsetWidth, c[1].offsetWidth) + 20;

		var t = tooltipTd.parentNode.parentNode.parentNode,
		    d = t.parentNode;

		if(m > 20)
		{
			d.style.width = m + 'px';
			c[0].width = c[1].width = '100%';

			if(!noShrink && d.offsetHeight > document.body.clientHeight)
				t.className = 'shrink';
		}
	}
	
	if(visible)
		ttContainer.firstChild.style.visibility = 'visible';
}

function g_ShowTooltip(_this, text, x, y, spanClass)
{
	if(spanClass != null)
		text = '<span class="' + spanClass + '">' + text + '</span>';

	g_tooltip.style.width = '350px';
	g_tooltip.style.left = '-2323px';
	g_tooltip.style.top  = '-2323px';
//	text = '<table><tr><td><b class="q3">Belt of the Sand Reaver</b><br>Binds when picked up<table width="100%"><tr><td>Waist</td><th>Plate</th></tr></table>494 Armor<br>+17 Strength<br>+18 Stamina<br>Durability 45 / 45<br>Requires Level 60</td></tr></table><table><tr><td><span class="q2">Equip: <a href="?spell=7518">Increases defense rating by 7.</a></span></td></tr></table>';
	g_tooltipTd.innerHTML = text;
	g_tooltip.style.display = '';

	g_FixTooltip(g_tooltip, 0, 0);
	g_MoveTooltip(_this, g_tooltip, x, y, g_tooltipTable.offsetWidth, g_tooltipTable.offsetHeight, 'contents');
}

function g_MoveTooltip(_this, tooltip, x, y, tow, toh, clip)
{
	var c = ac(_this);

	var left = c[0],
	    top  = c[1],
	    minx = 0,
	    miny = 0,
	    w1   = _this.offsetWidth  + x,
	    h1   = _this.offsetHeight + y,
	    bsl  = document.body.scrollLeft,
	    bst  = document.body.scrollTop,
	    bch  = document.body.clientHeight,
	    bcw  = document.body.clientWidth;

	tooltip.style.width = tow + 'px';

	if(clip != null)
	{
		_ = ge(clip);
		if(_)
		{
			c = ac(_);
			minx = c[0];
			miny = c[1];

			if(_.offsetWidth + minx <= bsl + bcw)
				bcw = _.offsetWidth  + minx - bsl;

			if(_.offsetHeight + miny <= bst + bch)
				bch = _.offsetHeight + miny - bst;
		}
	}

	if(left + w1 + tow > bcw)
		left = Math.max(left - tow - x, minx);
	else
		left += w1;

	if(left < minx)
		left = minx;
	else if(left + tow > bsl + bcw)
		left = bsl + bcw - tow;

	if(top - toh - y > Math.max(bst, miny))
		top = top - toh - y;
	else
		top += h1;

	if(top < miny)
		top = miny;
	else if(top + toh > bst + bch)
		top = Math.max(bst, bst + bch - toh);

	tooltip.style.left = left + 'px';
	tooltip.style.top  = top  + 'px';

	tooltip.style.visibility = 'visible';

//	if(isIE6)
//	{
//		_ = g_iframe;
//		_.style.left = left + 'px';
//		_.style.top  = top + 'px';
//		_.style.width  = tow + 'px';
//		_.style.height = toh + 'px';
//		_.style.display = '';
//		_.style.visibility = 'visible';
//	}
}

function g_HideTooltip()
{
	g_tooltip.style.display = 'none';
	g_tooltip.style.visibility = 'hidden';
	g_tooltipTable.className = '';
//	if(isIE6)
//		g_iframe.style.display = 'none';
}

function g_AppendTooltip(id, tooltip)
{
	var el = ge(id);
	el.appendChild(g_CreateTooltip(tooltip));
//	if(isIE)
//		setTimeout("g_FixTooltip(ge('" + id + "'), 1, 1)", 1);
//	else
		g_FixTooltip(el, 1, 1);
}

function g_CreateTooltip(tooltip)
{
	var d = ce('div'), t = ce('table'), tb = ce('tbody'), tr1 = ce('tr'), tr2 = ce('tr'), td = ce('td'), th1 = ce('th'), th2 = ce('th'), th3 = ce('th');
	
	d.className = 'wowtooltip';
	
	t.cellSpacing = 0;
	t.cellPadding = 0;
	
	th1.style.backgroundPosition = 'top right';
	th2.style.backgroundPosition = 'bottom left';
	th3.style.backgroundPosition = 'bottom right';
	
	td.innerHTML = tooltip;
	tr1.appendChild(td);
	tr1.appendChild(th1);
	tb.appendChild(tr1);
	tr2.appendChild(th2);
	tr2.appendChild(th3);
	tb.appendChild(tr2);
	t.appendChild(tb);
	d.appendChild(t);
	return d;
}

function g_MoneyHonorOver()
{
	g_ShowTooltip(this, '<b>Honor Points</b>', 0, 0, 'q');
}

function g_MoneyArenaOver()
{
	g_ShowTooltip(this, '<b>Arena Points</b>', 0, 0, 'q');
}

function g_AppendMoney(d, money, zero, honorPoints, arenaPoints, costItems)
{
	var ns = 0;

	if(money >= 10000)
	{
		ns = 1;

		_ = ce('span');
		_.className = 'moneygold';
		_.appendChild(ct(Math.floor(money / 10000)));
		d.appendChild(_);
		money %= 10000;
	}

	if(money >= 100)
	{
		if(ns) d.appendChild(ct(' ')); else ns = 1;

		_ = ce('span');
		_.className = 'moneysilver';
		_.appendChild(ct(Math.floor(money / 100)));
		d.appendChild(_);
		money %= 100;
	}

	if(money >= 1 || zero != null)
	{
		if(ns) d.appendChild(ct(' ')); else ns = 1;

		_ = ce('span');
		_.className = 'moneycopper';
		_.appendChild(ct(money));
		d.appendChild(_);
	}

	if(honorPoints != 0)
	{
		if(ns) d.appendChild(ct(' ')); else ns = 1;

		_ = ce('span');
		_.className = 'money' + (honorPoints < 0 ? 'horde' : 'alliance') + ' tip';
		_.onmouseover = g_MoneyHonorOver;
		_.onmouseout = g_HideTooltip;
		_.appendChild(ct(number_format(Math.abs(honorPoints))));
		d.appendChild(_);
	}

	if(arenaPoints >= 1)
	{
		if(ns) d.appendChild(ct(' ')); else ns = 1;

		_ = ce('span');
		_.className = 'moneyarena tip';
		_.onmouseover = g_MoneyArenaOver;
		_.onmouseout = g_HideTooltip;
		_.appendChild(ct(number_format(arenaPoints)));
		d.appendChild(_);
	}

	for(var i = 0; i < costItems.length; ++i)
	{
		if(ns) d.appendChild(ct(' ')); else ns = 1;

		var itemId = costItems[i][0];
		var count = costItems[i][1];

		var sp = ce('span');
		sp.className = 'q';
		_ = ce('a');
		_.href = '?item=' + itemId;
		_.className = 'moneyitem';
		_.style.backgroundImage = 'url(/images/icons/money/' + g_items[itemId][0] + '.gif)';
		eval('_.onmouseover = function() { g_ShowTooltip(this, g_items[' + itemId + '][1], 0, 0) };');
		_.onmouseout = g_HideTooltip;
		_.appendChild(ct(count));
		sp.appendChild(_);
		d.appendChild(sp);
	}
}

function g_CreateIcon(image, size, tooltip, link, num, qty)
{
	var icon = ce('div'), tile = ce('div'), hover = ce('div');
	var sizes = ['small', 'medium', 'large'];

	icon.className = 'wowicon' + sizes[size];
	if(image != null)
		icon.style.backgroundImage = 'url(http://www.wowhead.com/images/icons/' + sizes[size] + '/' + image + '.jpg)';
	
	tile.className = 'tile';
	
	hover.className = 'hover';
	if(tooltip)
	{
		hover.tooltip = (tooltip.length ? tooltip : null);
		hover.onmouseover = g_IconOver;
		hover.onmouseout  = g_IconOut;
	}

	if(typeof(link) == 'string')
	{
		var a = ce('a');
		a.href = link;
		hover.appendChild(a);
	}

	if(num != null && (num > 1 || num.length))
	{
		_ = g_CreateGlow(num, 'q1');
		_.style.right = '0';
		_.style.bottom = '0';
		_.style.position = 'absolute';
		tile.appendChild(_);
	}
		
	if(qty != null && qty > 0)
	{
		_ = g_CreateGlow('(' + qty + ')', 'q');
		_.style.left = '0';
		_.style.top = '0';
		_.style.position = 'absolute';
		tile.appendChild(_);
	}

	tile.appendChild(hover);
	icon.appendChild(tile);
	
	return icon;
}

function g_CreateGlow(txt, cn)
{
	var s = ce('span');

	for(var i = -1; i <= 1; ++i)
	{
		for(var j = -1; j <= 1; ++j)
		{
			var d = ce('div');
			d.style.position = 'absolute';
			d.style.whiteSpace = 'nowrap';
			d.style.left = i + 'px';
			d.style.top = j + 'px';

			if(i == 0 && j == 0)
				d.style.zIndex = 4;
			else
			{
				d.style.color = 'black';
				d.style.zIndex = 2;
			}
			d.appendChild(ct(txt));
			s.appendChild(d);
		}
	}

	s.style.position = 'relative';
	s.className = 'glow' + (cn != null ? ' ' + cn : '');

	var ph = ce('span');
	ph.style.visibility = 'hidden';
	ph.appendChild(ct(txt));
	s.appendChild(ph);

	return s;
}

function g_MouseOver()
{
	g_hilite.style.display = '';

	if(this.tooltip != null)
		g_ShowTooltip(this, this.tooltip, 0, 0);
}
function g_IconOver()
{
	this.parentNode.insertBefore(g_hilite, this.parentNode.lastChild.nextSibling);
	g_hilite.style.display = '';

	if(this.tooltip != null)
		g_ShowTooltip(this, this.tooltip, 0, 0);
}

function g_IconOut()
{
	g_hilite.style.display = 'none';
	g_HideTooltip();
}

function g_WriteTopBar(query, username)
{
	var s = '<table cellpadding="2" cellspacing="0" width="100%" id="topbar"><tr><td nowrap><table cellspacing="0" cellpadding="0" border="0"><tr><td id="topmenuleft" class="topmenu"></td><td class="morelinks"><a href="?more" id="more-link">more&nbsp;&#187;</a></td></tr></table></td><td width="100%" align="center">&nbsp;</td><td id="topmenuright" class="topmenu" nowrap></td><form action="./" name="topf" onsubmit="if(rtrim(this.elements[0].value, \' \').length == 0) return false"><td nowrap><input name="search" size="25" value="';
	if(query)
		s += query;
	s += '"></td><td style="padding-right: 4px"><input type="submit" value="Search"></td></form></tr></table>';

	document.write(s);

	g_AddBaseMenu('topmenuleft');
	g_AddUserMenu('topmenuright', username);
	g_AddMoreMenu();
}

function g_AddBaseMenu(d)
{
	var t = ce('table'), tb = ce('tbody'), tr = ce('tr'), td, a, span;
	t.cellPadding = t.cellSpacing = 0;
	for(var i = 0; i < mn_base.length; ++i)
	{
		td = ce('td');
		a = ce('a');
		span = ce('span');
		
		if(mn_base[i][2])
			a.href = mn_base[i][2];
		else
		{
			a.href = 'javascript:;';
			a.style.cursor = 'default';
			a.onmousedown = a.onclick = rf;
		}

		span.className = 'menuarrowd';
		span.appendChild(ct(mn_base[i][1]));
		a.appendChild(span);
		a.menu = mn_base[i][3];
		a.onmouseover = mn_Show2;
		a.onmouseout = mn_Hide2;
		
		td.appendChild(a);
		tr.appendChild(td);
	}
	
	tb.appendChild(tr);
	t.appendChild(tb);
	ge(d).appendChild(t);
}

function g_AddUserMenu(d, username)
{
	if(username)
	{
		mn_user[1] = username;
		mn_user[3] = mn_member;
		mn_member[0][2] = '?user=' + username;
	}
	else
	{
		mn_user[1] = 'Guest';
		mn_user[3] = mn_guest;
	}

	var t = ce('table'), tb = ce('tbody'), tr = ce('tr');
	t.cellPadding = t.cellSpacing = 0;
	
	var td = ce('td'), link = ce('a'), span = ce('span');

	link.href = 'javascript:;';
	link.style.whiteSpace = 'nowrap';
	link.style.cursor = 'default';
	link.onmousedown = link.onclick = rf;
	link.menu = mn_user[3];
	link.onmouseover = mn_Show2;
	link.onmouseout = mn_Hide2;
	
	span.className = 'menuarrowd';
	span.appendChild(ct(mn_user[1]));
	link.appendChild(span);
	td.appendChild(link);
	tr.appendChild(td);
	
	tb.appendChild(tr);
	t.appendChild(tb);
	ge(d).appendChild(t);
}

function g_WritePath(z)
{
	var t = ce('table'), tb = ce('tbody'), tr = ce('tr');
	t.cellPadding = t.cellSpacing = 0;
	var a = mn_base, lastTd = 0, error = 0;

	for(var i = 0; i < z.length; ++i)
	{
		var td, link, found = 0;

		for(var j = 0; j < a.length; ++j)
		{
			if(a[j][0] == z[i])
			{
				found = 1;
				a = a[j];
				a[4] = 1;
				break;
			}
		}
		if(!found)
		{
			error = 1;
			break;
		}

		td = ce('td')
		if(i < z.length - 1 && a[3])
			td.className = 'menuarrow';

		if(a[2])
		{
			link = ce('a');
			link.href = a[2];
		}
		else
			link = ce('span');
		link.appendChild(ct(a[1]));
		if(!g_lastMenuA)
			link.menu = mn_base;
		else
			link.menu = g_lastMenuA[3];
		link.onmouseover = mn_Show2;
		link.onmouseout = mn_Hide2;

		td.appendChild(link);
		tr.appendChild(td);
		lastTd = td;
		g_lastMenuA = a;

		a = a[3];
		if(!a)
		{
			error = 1;
			break;
		}
	}
	if(error && lastTd)
		lastTd.className = '';
	
	tb.appendChild(tr);
	t.appendChild(tb);
	ge('path').appendChild(t);
}

function g_AddMoreMenu()
{
	_ = ge('more-link');
	_.menu = mn_more;
	_.onmouseover = mn_Show2;
	_.onmouseout = mn_Hide2;
}

function g_AddSubcatMenu()
{
	if(typeof g_lastMenuA == 'object' && g_lastMenuA[3] != null)
	{
		_ = ge('subcat');
		_.menu = g_lastMenuA[3];
		_.menuappend = '&filter';
		_.onmouseover = mn_Show2;
		_.onmouseout = mn_Hide2;
	}
}

function g_CreateXmlHttpRequest()
{
	var xmlhttp = false;

	/*@cc_on @*/
	/*@if(@_jscript_version >= 5)
 	try
 	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
	   		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  	}
		catch(E)
		{
			xmlhttp = false;
		}
	}
	@end @*/

	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch(e)
		{
			xmlhttp=false;
		}
	}

	if(!xmlhttp && window.createRequest)
	{
		try
		{
			xmlhttp = window.createRequest();
		}
		catch (e)
		{
			xmlhttp=false;
		}
	}

	if(!xmlhttp)
		alert('Please upgrade to a modern browser (such as Firefox) that supports XMLHttpRequest.');

	return xmlhttp;
}

function g_FormatTimeElapsed(delay, removeOne)
{
	var range = [1, 60, 3600, 86400, 604800, 2629800, 31557600];
	var unit = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year'];

	delay = Math.max(delay, 1);

	for(var i = unit.length; i >= 0; --i)
	{
		if(delay >= range[i])
		{
			delay = Math.floor(delay / range[i]);
			var s = '';
			if(!removeOne || delay != 1)
				s += delay + ' ';
			s += unit[i];
			if(delay > 1)
				s += 's';
			return s;
		}
	}
}

function g_GetTextContent(el)
{
	var txt = '';
	for(var i = 0; i < el.childNodes.length; ++i)
	{
		if(el.childNodes[i].nodeValue)
			txt += el.childNodes[i].nodeValue;
		else if(el.childNodes[i].nodeName == 'BR')
		{
			if(isIE)
				txt += '\r';
			else
				txt += '\n';
		}
		txt += g_GetTextContent(el.childNodes[i]);
	}
	return txt;
}

function g_TextboxClick()
{
	this.focus();
	this.select();
	this.onclick = null;
}

function g_TextboxBlur()
{
	this.onclick = g_TextboxClick;
}

function g_ApplyTextboxFix()
{
	var e = document.getElementsByTagName('input');
	for(var i = 0; i < e.length; ++i)
	{
		if(e[i].type == 'text')
		{
			e[i].onclick = g_TextboxClick;
			e[i].onblur = g_TextboxBlur;
		}
	}
}

/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

var mn_iframes = [], mn_divs = [], mn_selection = [], mn_currentLink = null, mn_upcomingLink, mn_timer = 0, mn_append = null;

function mn_Show(_this)
{
	if(mn_currentLink != _this)
	{
		var c = ac(_this);

		mn_append = _this.menuappend;

		mn_Hide();
		mn_selection = [-1];
		mn_ShowDepth(0, _this.menu, c[0], c[1] + _this.offsetHeight + 1 + (_this.nodeName != 'A' ? 1 : 0), _this.offsetHeight + 8, 0, c[1]);
		mn_currentLink = _this;
		_this.className = 'open';
	}
	else
	{
		mn_Truncate(0);
		mn_Clean(0);
	}
}

function mn_Show2()
{
	clearTimeout(mn_timer);
	if(mn_currentLink)
		mn_Show(this);
	else
	{
		this.className = 'open';
		mn_upcomingLink = this;
		mn_timer = setTimeout('mn_Show(mn_upcomingLink)', 100);
	}
}

function mn_Hide()
{
	for(var i = 0; i < mn_selection.length; ++i)
	{
		mn_divs[i].style.display = 'none';
		mn_divs[i].style.visibility = 'hidden';
		if(isIE6)
			mn_iframes[i].style.display = 'none';
	}

	mn_selection = [];
	if(mn_currentLink)
		mn_currentLink.className = '';
	mn_currentLink = null;
}

function mn_Hide2()
{
	clearTimeout(mn_timer);
	if(mn_currentLink)
		mn_timer = setTimeout(mn_Hide, 333);
	else
		this.className = '';
}

function mn_ElemOver()
{
	var d = this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
	var depth = d.i;

	var i = this.i;
	var hasSub = this.firstChild.className == 'menusub';

	mn_Truncate(depth + hasSub);

	if(hasSub && i != mn_selection[depth])
	{
		var c = ac(this);
		mn_selection[depth + 1] = -1;
		mn_ShowDepth(depth + 1, d.menuArray[i][3], c[0], c[1] - 2, this.offsetHeight, this.offsetWidth - 3, 0);
	}

	mn_Clean(depth);

	mn_selection[depth] = i;
	if(this.className.length)
		this.className += ' open';
	else
		this.className = 'open';
}

function mn_GetIframe(i)
{
	var d;
	if(mn_iframes[i] == null)
	{
		d = ce('iframe');
		d.src = 'javascript:0;';
		d.frameBorder = 0;
		g_layers.appendChild(d);
		mn_iframes[i] = d;
	}
	else
		d = mn_iframes[i];
	
	return d;
}

function mn_GetDiv(i, menuArray)
{
	var d;
	if(mn_divs[i] == null)
	{
		d = ce('div');
		d.className = 'menu';
		g_layers.appendChild(d);
		mn_divs[i] = d;
	}
	else
		d = mn_divs[i];

	d.i = i;
	d.menuArray = menuArray;

	return d;
}

function mn_ShowDepth(i, menuArray, x, y, h, w, cropH)
{
	var d = mn_GetDiv(i, menuArray);
	if(d.firstChild)
		d.removeChild(d.firstChild);

	var t = ce('table'), tb = ce('tbody'), tr = ce('tr'), td = ce('td'), div = ce('div'), div2 = ce('div');
	t.cellSpacing = 0;

	var m = 999;
	var bch = document.body.clientHeight,
	    bcw = document.body.clientWidth,
	    bsl = document.body.scrollLeft,
	    bst = document.body.scrollTop;

	if(h > 0) // Height is provided, let's calculate how many menu items will fit in the screen.
	{
		if((h + 1) * menuArray.length > bch - 25 - cropH)
		{
			for(var j = 2; j < 4; ++j)
				if(h / j * menuArray.length + 30 < bch - cropH)
					break;
			m = Math.floor(menuArray.length / j);
		}
	}

	var row = 0;
	for(var j in menuArray)
	{
		var a = ce('a');
		
		a.i = j;

		if(menuArray[j][2])
		{
			if(mn_append != null)
				a.href = menuArray[j][2] + mn_append;
			else
				a.href = menuArray[j][2];
			a.onmouseover = mn_ElemOver;
		}
		else
		{
			a.href = 'javascript:;';
			a.onmouseover = mn_ElemOver;
			a.style.cursor = 'default';
			a.onmousedown = a.onclick = rf;
		}

		var s = ce('span'), s2 = ce('span');
		if(menuArray[j][3])
			s.className = 'menusub';

		if(menuArray[j][4])
			s2.className = 'menucheck';

		s2.appendChild(ct(menuArray[j][1]));
		s.appendChild(s2);			
		a.appendChild(s);
		div2.appendChild(a);

		if(row++ == m)
		{
			div.onmouseover = mn_DivOver;
			div.onmouseout  = mn_DivOut;
			div.appendChild(div2);
			td.appendChild(div);
			tr.appendChild(td);
			td = ce('td');
			div = ce('div');
			div2 = ce('div');
			row = 0;
		}
	}
	div.onmouseover = mn_DivOver;
	div.onmouseout  = mn_DivOut;
	div.appendChild(div2);
	td.appendChild(div);
	tr.appendChild(td);
	tb.appendChild(tr);
	t.appendChild(tb);
	d.appendChild(t);

	d.style.left = d.style.top = '-2323px';
	d.style.display = '';
	
	var tow = t.offsetWidth,
	    toh = t.offsetHeight;
	
	if(x + w + tow + 15 > bcw)
		x = Math.max(0, x - tow - 3);
	else
		x += w;

	if(y + toh > bch + bst)	
		y = Math.max(bst + 5, bch + bst - toh - 5);

	d.style.left = x + 'px';
	d.style.top  = y + 'px';
	
	if(isIE6)
	{
		_ = mn_GetIframe(i);
		_.style.left = x + 'px';
		_.style.top  = y + 'px';
		_.style.width  = tow + 'px';
		_.style.height = toh + 'px';
		_.style.display = '';
		_.style.visibility = 'visible';
	}

	d.style.visibility = 'visible';
}

function mn_DivOver()
{
	clearTimeout(mn_timer);
}

function mn_DivOut()
{
	clearTimeout(mn_timer);
	mn_timer = setTimeout(mn_Hide, 333);
}

function mn_Truncate(a)
{
	while(mn_selection.length - 1 > a)
	{
		_ = mn_selection.length - 1;
		mn_divs[_].style.display = 'none';
		mn_divs[_].style.visibility = 'hidden';
		if(isIE6)
			mn_iframes[_].style.display = 'none';
		mn_selection.pop();
	}
}

function mn_Clean(a)
{
	for(var j = a; j < mn_selection.length; ++j)
	{
		if(mn_selection[j] != -1)
		{
			d = gE(mn_divs[j], 'a')[mn_selection[j]];
			if(d.className.indexOf('sub') != -1)
				d.className = 'sub';
			else
				d.className = '';
			mn_selection[j] = -1;
		}
	}
}

/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

var lv_table, lv_thead, lv_tbody, lv_navTop, lv_navBot, lv_currTab = -1, lv_tabs = [], lv_tab = -1, lv_dat, lv_rep, lv_ta, lv_flags = 0, lv_atop;

function lv_Init(flags)
{
	var _lv, t, the, tbo, tfo, tr, td, ul, li, a;
	if(flags)
		lv_flags = flags;

	_lv = ge('lv');
	
	ul = ce('ul');
	ul.className = 'tabs';

	for(var i = 0; i < lv_data.length; ++i)
	{
		a = ce('a');
		a.href = 'javascript:;';
		a.onmousedown = a.onclick = rf;
		a.appendChild(ce('div'));

		_ = lv_data[i][2].length;
		if(_ > 0)
			a.appendChild(ct(lv_data[i][1] + ' (' + _ + ')'));
		else
			a.appendChild(ct(lv_data[i][1]));

		li = ce('li');
		li.appendChild(a);
		li.i = i;

		li.onclick = lv_TabClick;
		ul.appendChild(li);

		if(lv_data[i][5] != null && typeof(lv_data[i][5]) == 'object')
			lv_reports[lv_data[i][0]][2] = lv_data[i][5];

		var nCellsPerRow = lv_reports[lv_data[i][0]][0][2];
		var nRowsPerPage = lv_nRowsPerPage;
		if(nCellsPerRow == 4) nRowsPerPage = (lv_nRowsPerPage == 25 ? 20 : lv_nRowsPerPage == 50 ? 40 : 100);

		lv_tabs[i] = [li, 0, Math.ceil(lv_data[i][2].length / nRowsPerPage) - 1, lv_reports[lv_data[i][0]][2][0], [].concat(lv_reports[lv_data[i][0]][2]),, []];
		lv_tabs[i].nRowsPerPage = nRowsPerPage;
	}

	if(lv_flags & 1)
		ul.style.display = 'none';
		
	_lv.appendChild(ul);

	var navTop = ce('div'), navBot = ce('div');
	lv_navTop = [navTop];
	lv_navBot = [navBot];

	var nav = [lv_navTop, lv_navBot];
	for(var i = 0; i < 2; ++i)
	{
		nav[i][0].className = 'band' + (i + 1);;
		nav[i][0].onmousedown = nav[i][0].onselectstart = rf;
		if(lv_flags & 2)
			nav[i][0].style.display = 'none';
		nav[i][1] = ce('div');
		nav[i][2] = ce('span');
		_ = ce('a');
		_.href = 'javascript:;';
		_.onmousedown = _.onclick = rf;
		_.onmouseup = lv_FirstPage;
		_.appendChild(ct(String.fromCharCode(171) + ' First'));
		nav[i][3] = _;
		_ = ce('span');
		_.appendChild(ct(String.fromCharCode(160, 160)));
		nav[i][4] = _;
		_ = ce('a');
		_.href = 'javascript:;';
		_.onmousedown = _.onclick = rf;
		_.onmouseup = lv_PreviousPage;
		_.style.display
		_.appendChild(ct(String.fromCharCode(8249) + ' Previous'));
		nav[i][5] = _;
		_ = ce('span');
		_.appendChild(ct(String.fromCharCode(160, 160)));
		nav[i][6] = _;
		nav[i][7] = ce('span');
		_ = ce('span');
		_.appendChild(ct(String.fromCharCode(160, 160)));
		nav[i][8] = _;
		_ = ce('a');
		_.href = 'javascript:;';
		_.onmousedown = _.onclick = rf;
		_.onmouseup = lv_NextPage;
		_.appendChild(ct('Next ' + String.fromCharCode(8250)));
		nav[i][9] = _;
		_ = ce('span');
		_.appendChild(ct(String.fromCharCode(160, 160)));
		nav[i][10] = _;
		_ = ce('a');
		_.href = 'javascript:;';
		_.onmousedown = _.onclick = rf;
		_.onmouseup = lv_LastPage;
		_.appendChild(ct('Last ' + String.fromCharCode(187)));
		nav[i][11] = _;
		
		for(var j = 3; j < nav[i].length; ++j)
		{
			if(j >= 3 && j != 7)
				nav[i][j].style.display = 'none';
			nav[i][1].appendChild(nav[i][j]);
		}
		nav[i][0].appendChild(nav[i][1]);
		nav[i][0].appendChild(nav[i][2]);
	}
	
	_lv.appendChild(navTop);

	t = ce('table');
	lv_table = t;

	the = ce('thead');/*
	_ = ce('tr');
	lv_atop = ce('td');
	lv_atop.style.background = 'red';
	lv_atop.style.textAlign = 'center';
	lv_atop.style.padding = '0';
	lv_atop.appendChild(ct('salut'));
	_.appendChild(lv_atop);
	the.appendChild(_);*/
	lv_thead = the;
	t.appendChild(the);

	tbo = ce('tbody');
	lv_tbody  = tbo;
	t.appendChild(tbo);

	_ = ce('div');
	_.className = 'report-wrapper';
	_.appendChild(t);
	_lv.appendChild(_);

	_ = ce('div');
	_.className = 'clear';
	_lv.appendChild(_);

	_lv.appendChild(navBot);

	lv_ta = ge('lvta');

	var specialHash = 0;

	_ = location.hash.indexOf('go-to-comment-');
	if(_ != -1)
	{
		var id = parseInt(location.hash.substring(_ + 14));
		if(!isNaN(id))
		{
			_ = lv_data[lv_data.length - 2][2];
			for(var i = 0; i < _.length; ++i)
			{
				if(_[i][0] == id)
				{
					lv_SetTab(lv_data.length - 2, 1);
					lv_GoToPage(Math.ceil(i / lv_nRowsPerPage));
					
					_ = ge('commenth' + id);
					if(_)
						scrollTo(document.body.scrollLeft, ac(_)[1] - _.offsetHeight);

					specialHash = 1;
					break;
				}
			}
		}
	}
	else if(location.hash.indexOf('add-your-comment') != -1)
		specialHash = 1;

	if(!specialHash)
	{
		var a, str, tab = 0;
		if(lv_ta.value.length)
		{
			str = lv_ta.value;
			a = g_enc.indexOf(str.charAt(0));
			if(a >= 0 && a < lv_tabs.length)
			{
				tab = a;
				str = str.substr(1);
				a = str.split(g_encNext);
				for(var i = 0; i < a.length; ++i)
					lv_ParseTab(i, a[i]);
			}
		}
		else if(location.hash.length)
		{
			str = location.hash.substr(1);
			a = g_enc.indexOf(str.charAt(0));
			if(a >= 0 && a < lv_tabs.length)
			{
				tab = a;
				lv_ParseTab(a, str.substr(1));
			}
		}
		lv_SetTab(tab, 1);
	}

	if(lv_currTab == -1)
		lv_SetTab(0, 1);

	_lv.removeChild(_lv.firstChild);
}

function lv_FocusTab(i)
{
	var tabI = null;

	if(i >= 0 && i < lv_tabs.length)
		tabI = i;
	else if(i < 0 && (-i - 1) < lv_tabs.length)
		tabI = lv_tabs.length + i;

	if(tabI != null)
	{
		lv_SetTab(tabI);
		scrollTo(document.body.scrollLeft, ac(ge('lv'))[1] - parseInt(document.body.clientHeight / 3));
	}
}


function lv_ParseTab(i, enc)
{
	if(i < 0 || i >= lv_tabs.length || enc.length == 0)
		return;
		
	var sortCol = -1;

	var a = g_enc.indexOf(enc.charAt(0)), nCols = lv_reports[lv_data[i][0]][3].length;
	if(a >= 0 && a <= lv_tabs[i][2])
	{
		lv_tabs[i][1] = a;
		enc = enc.substring(1);
		for(var j = 0; j < enc.length && j < nCols; ++j)
		{
			a = g_enc.indexOf(enc.charAt(j));

			if(a != -1)
			{
				var col, asc;
				asc = a % 2;
				col = (a - asc) / 2;

				if(col >= 0 && col < nCols && (asc == 0 || asc == 1))
				{
					if(j == 0)
						sortCol = col;
					lv_tabs[i][4][j] = [col, asc];
				}
				else
					return;
			}
		}
	}
}


function lv_SetTab(i, doNotUpdateHash)
{
	if(i >= 0 && i < lv_tabs.length && lv_currTab != i)
	{
		if(lv_tab != -1)
			lv_tab[0].firstChild.className = '';

		lv_currTab = i;
		lv_tab = lv_tabs[i];
		lv_dat = lv_data[i];
		lv_rep = lv_reports[lv_dat[0]];

		lv_tab[0].firstChild.className = 'selected';

		if(!lv_tab[7])
			lv_InitTab();

		if(lv_thead.childNodes.length > 0)
			lv_thead.removeChild(lv_thead.firstChild);

		lv_thead.appendChild(lv_tab[7]);

		//lv_atop.colSpan = lv_rep[1];

		if(lv_dat[0] < 0)
			lv_table.className = 'report';
		else
			lv_table.className = 'hoverable report';

		if(lv_dat[2].length == 0 || lv_flags & 2)
		{
			lv_navTop[0].style.display = 'none';
			lv_navBot[0].style.display = 'none';
		}
		else
		{
			lv_navTop[0].style.display = '';
			lv_navBot[0].style.display = '';
		}

		lv_RefreshRows();
		lv_UpdateNav(0);
		
		if(lv_rep[8] != null)
		{
			lv_rep[8](lv_navTop[2], lv_dat[2]);
		}
		else
		{
			var b = '';
			if(lv_dat[3] != null)
			{
				if(typeof lv_dat[3] == 'string')
					b = lv_dat[3];
				else
				{
					_ = lv_dat[3];
					if(_ >= 1 && _ <= 4)
					{
						if(lv_dat[4] != null && lv_dat[4] > 200)
						{
							b = lv_messages[lv_dat[3]];
							b = b.replace('$1', lv_dat[4]);
							b = b.replace('$2', lv_rep[0][1]);
						}
					}
					else
					{
						b = lv_messages[lv_dat[3]];
						b = b.replace('$1', lv_dat[4]);
					}
				}
			}
			lv_navTop[2].innerHTML = b;
		}

		if(doNotUpdateHash == null)
			lv_UpdateHash();
	}
}

function lv_UpdateHash()
{
	var b, h = g_enc.charAt(lv_currTab);
	
	var page = lv_tab[1];

	if(lv_nRowsPerPage == 25)
		page = Math.floor(page / 2);
	else if(lv_nRowsPerPage == 100)
		page = Math.floor(page * 2);
	
	page = g_enc.charAt(page);
	
	b = page;
	for(var j = 0; j < lv_tab[4].length; ++j)
		b += g_enc.charAt(lv_tab[4][j][0] * 2 + lv_tab[4][j][1]);
		
	b = h + b;

	location.replace('#' + b);

	b = '';
	for(var i = 0; i < lv_tabs.length; ++i)
	{
		if(lv_tabs[i].length > 1)
		{
			if(i > 0)
				b += g_encNext;

			b += page;
			for(var j = 0; j < lv_tabs[i][4].length; ++j)
				b += g_enc.charAt(lv_tabs[i][4][j][0] * 2 + lv_tabs[i][4][j][1]);
		}
	}
	lv_ta.value = h + b;
}

function lv_HeaderClick()
{
	lv_Sort(this.i);
}

function lv_TabClick()
{
	lv_SetTab(this.i);
}

function lv_RowClick(_event)
{
	if(this.link)
	{
		if(!_event) _event = event;
	
		if(!_event.shiftKey && !_event.ctrlKey)
			location = this.link;
	}
}

function lv_RowOver()
{
	this.style.backgroundColor = '#202020';
}

function lv_RowOut()
{
	this.style.backgroundColor = '#181818';
}

function lv_InitTab()
{
	var tr = ce('tr');

	if(lv_dat[0] < 0)
	{
		var td = ce('td');
		tr.appendChild(td);
		if(lv_rep[0][2] != null)
			td.colSpan = lv_rep[0][2];
		td.style.padding = '0';
	}
	else
	{
		for(var i in lv_rep[3])
		{
			var th = ce('th');
			th.width = lv_rep[3][i][1];
			th.align = lv_rep[3][i][2];
			th.onmousedown = rf;
			th.onselectstart = rf;
			th.i = i;
			th.colSpan = lv_rep[4](i);
			th.onmouseup = lv_HeaderClick;

			var a = ce('a');
			a.href = 'javascript:;';
			a.onmousedown = a.onclick = rf;
			a.appendChild(ct(lv_rep[3][i][0]));

			th.appendChild(a);
			tr.appendChild(th);
			lv_tab[6][i] = th;
		}
	}
	
	lv_tab[7] = tr;

	if(lv_dat[0] >= 0 && lv_rep[2] != null && lv_rep[2].length)
		lv_Sort(lv_tab[4][0][0], 1);
}

function lv_CreateRow(firstN, lastN)
{
	var tr = ce('tr'), td, na, fields = lv_dat[2][firstN];
	fields.row = tr;

	if(lv_dat[0] >= 0)
	{
		tr.onclick = lv_RowClick;

		if(isIE)
		{
			tr.onmouseover = lv_RowOver;
			tr.onmouseout  = lv_RowOut;
		}
		lv_rep[5](tr, fields);
	}

	for(var n = firstN; n <= lastN; ++n)
	{
		fields = lv_dat[2][n];

		if(fields != null)
		{
			for(var j = 0; j < lv_rep[3].length; ++j)
			{
				i = lv_rep[3][j][4];
				td = ce('td');
				td.width = lv_rep[3][j][1];
				td.align = lv_rep[3][j][2];

				na = 0;

				if(lv_rep[6][i] != null)
					na = lv_rep[6][i](tr, td, fields);
				else
				{
					if(fields[i] != null)
						na = fields[i];
					else
						na = -1;
				}

				if(na == -1)
				{
					_ = ce('span');
					_.className = 'q0';
					_.appendChild(ct('n/a'));
					td.insertBefore(_, td.firstChild);
				}
				else if(na != null)
				{
					td.insertBefore(ct(na), td.firstChild);
				}

				tr.appendChild(td);
			}
		}
		else
		{
			td = ce('td');
			td.width = lv_rep[3][0][1];
			tr.appendChild(td);
		}
	}
}

function lv_CreateZeroRow()
{
	var fields = lv_dat[2], tr = ce('tr'), td = ce('td');

	if(lv_rep[7] != null)
		lv_rep[7](td);
	else
	{
		_ = ce('div');
		_.style.textAlign = 'center';
		_.appendChild(ct('There is no data to display.'));
		td.appendChild(_);
	}

	tr.appendChild(td);
	fields.row = tr;
}

function lv_RefreshRows()
{
	var f, t;

	if((lv_flags & 2) == 0)
	{
		f = lv_tab[1] * lv_tab.nRowsPerPage;
		t = Math.min(lv_dat[2].length, f + lv_tab.nRowsPerPage) - 1;
	}
	else
	{
		f = 0;
		t = lv_dat[2].length - 1;
	}
	
	while(lv_tbody.firstChild)
		lv_tbody.removeChild(lv_tbody.firstChild);

	var items = lv_data[lv_currTab][2];
	var nCellsPerRow = lv_rep[0][2];
	if(nCellsPerRow == null) nCellsPerRow = 1;

	if(items.length > 0)
	{
		for(var i = f; i <= t; i += nCellsPerRow)
		{
			if(!items[i].row)
				lv_CreateRow(i, i + nCellsPerRow - 1);

			lv_tbody.appendChild(items[i].row);
		}
	}
	else
	{
		if(!items.row)
			lv_CreateZeroRow();
		lv_tbody.appendChild(items.row);
	}
}

function lv_FirstPage()
{
	lv_tab[1] = 0;
	lv_RefreshRows();
	lv_UpdateNav(1);
	lv_UpdateHash();
}

function lv_PreviousPage()
{
	if(lv_tab[1] > 0)
		--lv_tab[1];		
	lv_RefreshRows();
	lv_UpdateNav(1);
	lv_UpdateHash();
}

function lv_NextPage()
{
	if(lv_tab[1] < lv_tab[2])
		++lv_tab[1];
	lv_RefreshRows();
	lv_UpdateNav(1);
	lv_UpdateHash();
}

function lv_LastPage()
{
	lv_tab[1] = lv_tab[2];
	lv_RefreshRows();
	lv_UpdateNav(1);
	lv_UpdateHash();
}

function lv_GoToPage(i)
{
	if(i >= 0 && i <= lv_tab[2] && i != lv_tab[1])
	{
		lv_tab[1] = i;
		lv_RefreshRows();
		lv_UpdateNav(1);
		lv_UpdateHash();
	}
}

function lv_UpdateNav(autoScroll)
{
	var str = '';
	var f = lv_tab[1] * lv_tab.nRowsPerPage,
	    t = Math.min(lv_dat[2].length, f + lv_tab.nRowsPerPage) - 1;

	var nav = [lv_navTop, lv_navBot];
	for(var i = 0; i < 2; ++i)
	{
		if(lv_tab[1] > 1)
		{
			nav[i][3].style.display = '';
			nav[i][4].style.display = '';
		}
		else
		{
			nav[i][3].style.display = 'none';
			nav[i][4].style.display = 'none';
		}

		if(lv_tab[1] > 0)
		{
			nav[i][5].style.display = '';
			nav[i][6].style.display = '';
		}
		else
		{
			nav[i][5].style.display = 'none';
			nav[i][6].style.display = 'none';
		}

		nav[i][7].innerHTML = '<b>' + (f + 1) + '</b> - <b>' + (t + 1) + '</b> of <b>' + lv_dat[2].length + '</b>';

		if(lv_tab[1] < lv_tab[2])
		{
			nav[i][8].style.display = '';
			nav[i][9].style.display = '';
		}
		else
		{
			nav[i][8].style.display = 'none';
			nav[i][9].style.display = 'none';
		}
		
		if(lv_tab[1] < lv_tab[2] - 1)
		{
			nav[i][10].style.display = '';
			nav[i][11].style.display = '';
		}
		else
		{
			nav[i][10].style.display = 'none';
			nav[i][11].style.display = 'none';
		}
	}

	if(autoScroll)
	{
		var t = ac(ge('lv'))[1];
		if(document.body.scrollTop > t)
			scrollTo(document.body.scrollLeft, t);
	}
}

function lv_SortCallback(a, b)
{
	var res = 0;
	var i = 0;

	while(res == 0 && i < lv_tab[4].length)
	{
		res = strcmp(a[lv_rep[3][lv_tab[4][i][0]][3][lv_tab[4][i][1]]], b[lv_rep[3][lv_tab[4][i][0]][3][lv_tab[4][i][1]]]);
		++i;
	}

	return res ? (lv_tab[4][i-1][1] ? 1 : -1) * res : 0;
}


function lv_Sort(i, init)
{
	var _this = lv_tab[6][i];

	if(!init)
	{
		if(i == lv_tab[3])
			lv_tab[4][0][1] = lv_tab[4][0][1] ? 0 : 1;
		else
		{
			var s = 0;
			var asc = 1;

			for(var j = lv_tab[4].length - 1; j > 0; --j)
			{
				if(lv_tab[4][j][0] == i)
				{
					s = 1;
					asc = lv_tab[4][j][1];
				}

				if(s)
				{
					lv_tab[4][j][0] = lv_tab[4][j - 1][0];
					lv_tab[4][j][1] = lv_tab[4][j - 1][1];
				}
			}

			if(s == 1)
				lv_tab[4][0] = [i, asc];
			else
				lv_tab[4].unshift([i, asc]);
		}
	}

	if(!init || (init && lv_rep[2].toString() != lv_tab[4].toString()))
		lv_dat[2].sort(lv_SortCallback);
	
	if(!init)
	{
		lv_RefreshRows();
		lv_UpdateHash();
	}

	if(lv_tab[5])
		lv_tab[5].firstChild.innerHTML = lv_rep[3][lv_tab[5].i][0];
	lv_tab[3] = i;
	lv_tab[5] = _this;

	_this.firstChild.innerHTML = '<span class="sort' + (lv_tab[4][0][1] ? 'asc' : 'desc') + '">' + lv_rep[3][i][0] + '</span>';
}

/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

var mp_div = 0, mp_span = 0, mp_divs = [], mp_last = 0, mp_zIndex = 0, mp_zoom = 1, mp_sizes=[[488,325,'normal'],[772,515,'zoom']], mp_clear = ['none','both'];

function mp_DivOver()
{
	g_ShowTooltip(this, parseFloat(this.parentNode.style.left).toFixed(1) + ', ' + parseFloat(this.parentNode.style.top).toFixed(1), 0, 0);
}

function mp_GetDiv(i)
{
	if(!mp_divs[i])
	{
		var d = ce('div');
		d.className = 'party';
		_ = ce('div');
		_.className = 'party2';
		_.onmouseover = mp_DivOver;
		_.onmouseout = g_HideTooltip;
		d.appendChild(_);
		mp_span.appendChild(d);
		mp_divs[i] = d;
	}
	return mp_divs[i];
}

function mp_Click(_event)
{
	if(!_event) _event = event;
	var button = _event.which ? _event.which : _event.button;
	if(button < 2)
		mp_ToggleSize();
}

function mp_ToggleSize(noBg)
{
	mp_zoom = 1 - mp_zoom;

	mp_span.style.width  = mp_div.style.width  = mp_sizes[mp_zoom][0] + 'px';
	mp_span.style.height = mp_div.style.height = mp_sizes[mp_zoom][1] + 'px';

	mp_div.style.clear = mp_clear[mp_zoom];

	if(noBg == null)
		mp_span.style.backgroundImage = mp_span.style.backgroundImage.replace(mp_sizes[1 - mp_zoom][2], mp_sizes[mp_zoom][2]);

	var bst = document.body.scrollTop;
	var bch = document.body.clientHeight;
	var top = ac(mp_span)[1] - 13;
	var h = mp_sizes[mp_zoom][1] + 13;

	if(mp_zoom)
	{
		if(top + h > bst + bch)
		{
			if(h > bch)
				scrollTo(document.body.scrollLeft, top);
			else
				scrollTo(document.body.scrollLeft, top + (h / 2) - bch / 2 + 13);
		}
	}
	else if(top < bst)
		scrollTo(document.body.scrollLeft, top);
}

function mp_Embed(area, coords, _this)
{
	if(!mp_div)
	{
		mp_div = ge('mp');
		mp_div.className = 'map';
		mp_span = ce('span');
		mp_div.appendChild(mp_span);
		
		mp_ToggleSize(1);
		mp_span.onmouseup = mp_Click;
		mp_span.onmousedown = mp_span.onselectstart = rf;
		_ = g_CreateGlow('click to toggle zoom');
		_.style.position = 'absolute';
		mp_span.appendChild(_);
	}

	mp_span.style.backgroundImage = 'url(http://www.wowhead.com/images/maps/' + mp_sizes[mp_zoom][2] + '/' + str_replace(str_replace(area, ' ', '_'), "'", '_') + '.jpg)';
	
	if(mp_last)
		mp_last.className = '';
	if(_this != null)
	{
		_this.className = 'selected';
		mp_last = _this;
	}

	if(coords != null)
	{
		var i;
		for(i = 0; i < coords.length; ++i)
		{
			_ = mp_GetDiv(i);
			_.style.left = coords[i][0] + '%';
			_.style.top  = coords[i][1] + '%';
			_.style.display = '';
		}

		for(; i < mp_divs.length; ++i)
			mp_divs[i].style.display = 'none';
	}
	
	return false;
}

/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

var bk_page = 0, bk_text, bk_navPage, bk_navPrev, bk_navNext, bk_navSpacing1, bk_navSpacing2;

function bk_Init()
{
	_ = ge('bk');

	var sp = ce('span');

	var a = ce('a');
	a.appendChild(ct(String.fromCharCode(8249) + ' Previous'));
	a.href = 'javascript:;';
	a.onmouseup = bk_PrevPage;
	a.onmousedown = a.onclick = rf;
	sp.appendChild(a);
	bk_navPrev = a;
	
	a = ce('p');
	a.appendChild(ct(String.fromCharCode(160, 160)));
	sp.appendChild(a);
	bk_navSpacing1 = a;
	
	a = ce('b');
	a.appendChild(ct(' '));
	bk_navPage = a;
	sp.appendChild(a);

	a = ct(' of ');
	sp.appendChild(a);
	
	a = ce('b');
	a.appendChild(ct(bk_data.length));
	sp.appendChild(a);

	a = ce('p');
	a.appendChild(ct(String.fromCharCode(160, 160)));
	sp.appendChild(a);
	bk_navSpacing2 = a;
	
	a = ce('a');
	a.appendChild(ct('Next ' + String.fromCharCode(8250)));
	a.href = 'javascript:;';
	a.onmouseup = bk_NextPage;
	a.onmousedown = a.onclick = rf;
	sp.appendChild(a);
	bk_navNext = a;

	if(bk_data.length > 1)
	{
		sp.style.cursor = 'default';
		sp.onmousedown = sp.onselectstart = rf;
		_.appendChild(sp);
	}

	bk_text = ce('div');
	bk_UpdateNav();
	
	_.appendChild(bk_text);
}

function bk_UpdateNav()
{
	if(bk_page > 0)
		bk_navPrev.style.display = '';
	else
		bk_navPrev.style.display = 'none';

	bk_navSpacing1.style.display = bk_navPrev.style.display;

	if(bk_page < bk_data.length - 1)
		bk_navNext.style.display = '';
	else
		bk_navNext.style.display = 'none';

	bk_navSpacing2.style.display = bk_navNext.style.display;

	bk_navPage.firstChild.nodeValue = bk_page + 1;
	
	bk_text.innerHTML = bk_data[bk_page];
}

function bk_PrevPage()
{
	if(bk_page > 0)
	{
		--bk_page;
		bk_UpdateNav();
	}
}

function bk_NextPage()
{
	if(bk_page < bk_data.length - 1)
	{
		++bk_page;
		bk_UpdateNav();
	}
}

/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

function fi_Toggle(_this)
{
	_ = ge('fi');
	var a = g_ToggleDisplay(_), n;

	if(a)
	{
		_this.firstChild.nodeValue = 'Hide filter options';
		_ = gE(_, 'form')[0];
		_ = _.elements['na'] ? _.elements['na'] : _.elements['ti'];
		_.focus();
		_.select();
	}
	else
		_this.firstChild.nodeValue = 'Create a filter';
}

function fi_Submit(_this)
{
	var sum = 0;

	_ = _this.elements;
	for(var i = 0; i < _.length; ++i)
	{
		switch(_[i].nodeName)
		{
			case 'INPUT':
				if(_[i].type == 'text' && rtrim(_[i].value, ' ').length > 0)
					++sum;
				break;

			case 'SELECT':
				if(_[i].selectedIndex != -1 && _[i].options[_[i].selectedIndex].value.length > 0)
					++sum;
				break;
		}
	}

	if(sum == 0)
	{
		alert('Please fill in some criteria.');
		return false;
	}

	return true;
}

function fi_Reset(_this)
{
	_ = ge(_this.name + '_criteria');
	if(_ != null)
	{
		var d;
		while(_.childNodes.length > 1)
		{
			d = _.childNodes[1];

			while(d.childNodes.length > 1)
				d.removeChild(d.childNodes[1]);

			_.removeChild(d);
		}

		d = _.childNodes[0];

		while(d.childNodes.length > 1)
			d.removeChild(d.childNodes[1]);
		d.firstChild.i = null;

		_.nextSibling.firstChild.style.display = '';
	}

	_ = _this.elements;
	for(var i = 0; i < _.length; ++i)
	{
		switch(_[i].nodeName)
		{
			case 'INPUT':
				if(_[i].type == 'text')
					_[i].value = '';
				else if(_[i].type == 'checkbox')
					_[i].checked = false;
				else if(_[i].type == 'radio' && _[i].value.length == 0)
					_[i].checked = true;
				break;

			case 'SELECT':
				_[i].selectedIndex = _[i].multiple ? -1 : 0;
				break;
		}
	}

	return false;
}

function fi_AddCriterion(_this, cr)
{
	_ = ge(_this.id.replace('add', ''));

	if(_.childNodes.length == 8)
		_this.style.display = 'none';

	var a = _.childNodes[0].lastChild;
	if(a.nodeName != 'A')
		fi_AppendRemoveLink(_.childNodes[0]);
	else
	{
		a.firstChild.nodeValue = 'remove';
		a.onmouseup = fi_RemoveCriterion;
	}
	
		

	var d = ce('div'), c = _.childNodes[0].childNodes[0].cloneNode(true);
	c.i = null;

	if(cr != null)
	{
		var opts = c.getElementsByTagName('option');
		for(var i = 0; i < opts.length; ++i)
		{
			if(opts[i].value == cr)
			{
				opts[i].selected = true;
				break;
			}
		}
	}
	else
		c.firstChild.selected = true;

	d.appendChild(c);
	fi_AppendRemoveLink(d);
	_.appendChild(d);

	return c;
}

function fi_RemoveCriterion()
{
	var d = this.parentNode, c = d.parentNode;
	c.removeChild(d);

	if(c.childNodes.length == 1)
	{
		_ = c.firstChild;
		if(_.firstChild.selectedIndex > 0)
		{
			var a = _.lastChild;
			a.firstChild.nodeValue = 'clear';
			a.onmouseup = fi_ClearCriterion;
		}
		else
		{
			_.removeChild(_.lastChild);
			_.removeChild(_.lastChild);
		}
	}

	c.nextSibling.firstChild.style.display = '';
}

function fi_ClearCriterion()
{
	var d = this.parentNode;
	d.firstChild.selectedIndex = 0;
	fi_CriterionChange(d.firstChild);
}

function fi_AppendRemoveLink(d)
{
	d.appendChild(ct(String.fromCharCode(160, 160)));
	var a = ce('a');
	a.href = 'javascript:;';
	a.appendChild(ct('remove'));
	a.onmouseup = fi_RemoveCriterion;
	a.onmousedown = a.onclick = rf;
	d.appendChild(a);
}

function fi_AppendClearLink(d)
{
	d.appendChild(ct(String.fromCharCode(160, 160)));
	var a = ce('a');
	a.href = 'javascript:;';
	a.appendChild(ct('clear'));
	a.onmouseup = fi_ClearCriterion;
	a.onmousedown = a.onclick = rf;
	d.appendChild(a);
}

function fi_CriterionChange(_this, crs, crv)
{
	if(_this.selectedIndex != _this.i)
	{
		var o = _this.options[_this.selectedIndex], d = _this.parentNode;

		if(d.childNodes.length > 1)
		{
			if(_this.i != null && o.className == _this.options[_this.i].className)
				return;

			while(d.childNodes.length > 1)
				d.removeChild(d.childNodes[1]);
		}

		if(fi_criteria[o.className] != null)
		{
			var _c = fi_criteria[o.className];
			_ = ce('select');
			_.name = 'crs[]';
			for(var i = 0; i < _c.length; ++i)
			{
				var o2 = ce('option');
				o2.value = _c[i][0];
				o2.appendChild(ct(_c[i][1]));
				if(crs != null && crs == _c[i][0])
					o2.selected = true;
				_.appendChild(o2);
			}

			d.appendChild(ct(' '));
			d.appendChild(_);

			var n = (o.className == '__num');
			
			if(n)
				d.appendChild(ct(' '));

			_ = ce('input');
			_.type = 'text';

			if(crv != null)
				_.value = crv.toString();
			else
				_.value = '0';
			_.name = 'crv[]';
			
			if(n)
			{
				_.maxLength = 7;
				_.style.textAlign = 'center';
				_.style.width = '4.5em';
			}
			else
				_.type = 'hidden';
			
			d.appendChild(_);
		}

		if(d.parentNode.childNodes.length == 1)
		{
			if(_this.selectedIndex > 0)
				fi_AppendClearLink(d);
		}
		else if(d.parentNode.childNodes.length > 1)
			fi_AppendRemoveLink(d);

		_this.i = _this.selectedIndex;
	}
}

function fi_SetCriteria(name, cr, crs, crv)
{
	_ = ge('fi_' + name + '_criteria');
	
	var i, c = _.childNodes[0].childNodes[0];
	_ = c.getElementsByTagName('option');
	for(i = 0; i < _.length; ++i)
	{
		if(_[i].value == cr[0])
		{
			_[i].selected = true;
			break;
		}
	}
	fi_CriterionChange(c, crs[0], crv[0]);

	var a = ge('fi_' + name + '_addcriteria');
	for(i = 1; i < cr.length; ++i)
		fi_CriterionChange(fi_AddCriterion(a, cr[i]), crs[i], crv[i]);
}

function fi_DropdownSync(_this)
{
	if(_this.selectedIndex >= 0)
		_this.className = _this.options[_this.selectedIndex].className;
}


/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

var co_Reqs = [], co_CommentIds = [];

function co_Rate(commentId, rating)
{
	var req = g_CreateXmlHttpRequest();
	if(req)
	{
		_ = ge('comment-rating' + commentId);
		_.style.display = 'none';
		_.previousSibling.style.display = '';

		_ = co_Reqs.length;
		co_Reqs[_] = req;
		co_CommentIds[_] = commentId;

		req.open('GET', '?comment=rate&id=' + commentId + '&rating=' + rating, true);
		eval('req.onreadystatechange = function(){ co_RateCallback(' + _ + '); }');
		req.send(null);
	}
}

function co_RateCallback(reqId)
{
	var req = co_Reqs[reqId], commentId = co_CommentIds[reqId];

	if(req.readyState == 4)
	{
		var showControls = true;
		var errorCode = 0;

		if(req.status == 200)
		{
			var num = parseInt(req.responseText);
			showControls = false
			if(isNaN(num))
				errorCode = 1;
		}
		else
			errorCode = 2;
		
		if(showControls)
		{
			_ = ge('comment-rating' + commentId);
			_.style.display = '';
			_.previousSibling.style.display = 'none';
		}
		else
		{
			_ = ge('comment-rating' + commentId).previousSibling;
			_.style.display = 'none';
			if(errorCode == 0)
			{
				_ = _.previousSibling.firstChild;
				_.nodeValue = (num > 0 ? '+' : '') + num;
			}
		}

		if(errorCode == 1)
			alert('Rating rejected by server.');
		else if(errorCode == 2)
			alert('Unable to reach server.');
	}
}

function co_Reply(commentId, username)
{
	co_replyTo = commentId;
	document.forms['addcomment'].elements['replyto'].value = commentId;
	_ = ge('comment-reply');
	gE(_, 'span')[0].innerHTML = username;
	_.style.display = '';
	co_AddYourComment();
}

function co_CancelReply()
{
	document.forms['addcomment'].elements['replyto'].value = '';
	ge('comment-reply').style.display = 'none';
}

function co_ToggleComment(_this, commentId)
{
	_ = ge('comment' + commentId);
	if(g_ToggleDisplay(_))
	{
		_this.firstChild.nodeValue = 'Hide comment';
		_ = _.nextSibling;
		if(_)
			_.style.display = '';
		_ = ge('comment-rating' + commentId);
		if(_)
			_.style.display = '';
	}
	else
	{
		_this.firstChild.nodeValue = 'Show comment';
		_ = _.nextSibling;
		if(_)
			_.style.display = 'none';
	}
}

function co_ShowEdit(commentId)
{
	_ = ge('comment' + commentId);
	_.editing = true;
	_.style.display = 'none';
	ge('edit-comment' + commentId).style.display = 'none';

	var di = ce('div');

	var ta = ce('textarea');
	ta.style.marginTop = ta.style.marginBottom = '3px';
	ta.rows = 8;
	ta.appendChild(ct(g_GetTextContent(_)));
	ta.className = 'edit-comment';
	di.appendChild(ta);

	var ip = ce('input');
	ip.type = 'button';
	ip.value = 'Update';
	eval('ip.onclick = function(){ co_Edit(' + commentId + '); }');
	di.appendChild(ip);

	var sp = ce('span');
	sp.appendChild(ct(' '));
	di.appendChild(sp);

	ip = ce('input');
	ip.type = 'button';
	ip.value = 'Cancel';
	eval('ip.onclick = function(){ co_CancelEdit(' + commentId + ',true); }');
	di.appendChild(ip);

	_.parentNode.insertBefore(di, _.nextSibling);

	ta.originalValue = ta.value;
	ta.focus();
}

function co_CancelEdit(commentId, allowEditing)
{
	_ = ge('comment' + commentId);
	_.editing = false;
	_.style.display = '';
	if(allowEditing)
		ge('edit-comment' + commentId).style.display = '';
	_.parentNode.removeChild(_.nextSibling);
}

function co_Edit(commentId)
{
	_ = ge('comment' + commentId);
	var c = _.nextSibling.childNodes;

	if(c[0].originalValue == c[0].value)
	{
		co_CancelEdit(commentId, true);
		return;
	}

	if(!co_Validate(c[0]))
		return;

	var req = g_CreateXmlHttpRequest();
	if(req)
	{
		c[1].value = 'Sending...';
		c[0].disabled = c[1].disabled = true;
		c[2].style.display = c[3].style.display = 'none';

		var params = 'commentbody=' + urlencode(c[0].value);

		_ = co_Reqs.length;
		co_Reqs[_] = req;
		co_CommentIds[_] = commentId;

		req.open('POST', '?comment=edit&id=' + commentId, true);
		eval('req.onreadystatechange = function(){ co_EditCallback(' + _ + '); }');
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(params);
	}
}

function co_EditCallback(reqId)
{
	var req = co_Reqs[reqId], commentId = co_CommentIds[reqId];

	if(req.readyState == 4)
	{
		var success = false;
		var errorCode = 0;

		if(req.status == 200)
		{
			if(req.responseText.length > 0)
			{
				success = true

				co_CancelEdit(commentId, true);

				_ = ge('comment' + commentId);
				_.innerHTML = req.responseText;
			}
			else
				errorCode = 1;
		}
		else
			errorCode = 2;
		
		if(!success)
		{
			_ = ge('comment' + commentId);
			_ = _.nextSibling.childNodes;

			_[1].value = 'Update';
			_[0].disabled = _[1].disabled = false;
			_[2].style.display = _[3].style.display = '';

			if(errorCode == 1)
				alert('Edited comment rejected by server.');
			else if(errorCode == 2)
				alert('Unable to reach server.');
		}
	}
}

function co_Validate(textarea)
{
	var v = rtrim(textarea.value, ' ');

	if(v.length < 10)
	{
		if(v.length == 0)
			alert('Please enter some comment.');
		else
			alert('Your comment is too short. Please elaborate a little.');

		textarea.focus();
		return false
	}
	else if(v.length > 4000)
		return confirm('Your comment is longer than 4000 characters and will be truncated after \'' + v.substring(3980, 4000) + '\'.\n\nDo you want to continue?');
	else
		return true;
}

function co_TimeLeft(commentId, expireDate)
{
	var timeOffset = (g_localTime - g_serverTime) / 1000;
	var delay = (new Date(expireDate) - new Date() + timeOffset) / 1000;

	_ = ge('commenth' + commentId);
	
	if(_ == null)
		return true;

	var sp = gE(_, 'span')[2],
	    sp2 = sp.lastChild;

	if(delay >= 1)
	{
		var s = g_FormatTimeElapsed(delay, 1);
		if(sp2.innerHTML != s)
		{
			if(delay < 30 && !sp2.style.color.length)
				sp2.style.color = 'red';
			sp2.innerHTML = s;
		}
		return true;
	}
	else
	{
		sp.style.display = 'none';
		_ = ge('comment' + commentId);
		if(_.editing)
			co_CancelEdit(commentId, false);
		else
			ge('edit-comment' + commentId).style.display = 'none';
	}
}

function co_TimeLeftTick(commentId, expireDate)
{
	if(co_TimeLeft(commentId, expireDate))
		setTimeout('co_TimeLeftTick(' + commentId + ',\'' + expireDate + '\')', 1000);
}

function co_ShowCaptcha()
{
	_ = ge('comment-captcha');
	if(gE(_, 'img').length > 0) return;
	var img = ce('img');
	img.src = 'http://www.wowhead.com/common/images/captcha.php?' + Math.random();
	img.width = 150;
	img.height = 40;
	img.style.border = '1px solid #404040';
	img.style.visibility = 'hidden';
	img.vspace = 8;
	img.onload = function(){this.style.visibility='visible'};
	_.insertBefore(img, _.firstChild);
	_.style.display = '';
}

function co_AddYourComment()
{
	_ = ge('add-your-comment');
	if(_)
		scrollTo(document.body.scrollLeft, ac(_)[1]);

	_ = ge('add-comment');
	if(_)
		_.focus()
}

/**********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
***********************************************************************
**********************************************************************/

var ss_page = 0, ss_navTop, ss_border, ss_img, ss_by, ss_ago, ss_desc, ss_hd, ss_path = 'http://www.wowhead.com/images/screenshots/';

function ss_CellOver()
{
	this.style.backgroundColor = '#202020';

	var b = gE(this, 'div');
	if(b[2].innerHTML)
	{
		b[2].className = 'ss-alt-over';

		if(!isIE)
			b[2].style.left = '-1px';	
		b[2].style.top = '-2px';
		b[1].style.zIndex = '1';
	}
}

function ss_CellOut()
{
	this.style.backgroundColor = '#181818';

	var b = gE(this, 'div');
	if(b[2].innerHTML)
	{
		b[2].className = 'ss-alt';
		b[2].style.left = b[2].style.top = '0';
		b[1].style.zIndex = '0';
	}
}

function ss_CellClick(_event)
{
	if(this.link)
	{
		if(!_event) _event = event;
	
		if(!_event.shiftKey && !_event.ctrlKey)
			location = this.link;
	}
}

function ss_Init()
{
	var _ss = ge('ss');

	var a, i, d, s, b;

	d = ce('div');

	a = ce('a');	
	a.appendChild(ct(String.fromCharCode(8249) + ' Previous'));
	a.href = 'javascript:;';
	a.onclick = ss_PrevPage;
	a.onmousedown = rf;
	a.style.cursor = 'pointer';
	a.style.cssFloat = a.style.styleFloat = 'left';
	d.appendChild(a);
	a = ce('a');
	a.style.marginLeft = '1.5em';
	a.appendChild(ct('Next ' + String.fromCharCode(8250)));
	a.href = 'javascript:;';
	a.onclick = ss_NextPage;
	a.onmousedown = rf;
	a.style.cursor = 'pointer';
	a.style.cssFloat = a.style.styleFloat = 'right';
	d.appendChild(a);
	b = ce('b');
	b.appendChild(ct(' '));
	d.appendChild(b);
	d.appendChild(ct(' of '));
	b = ce('b');
	b.appendChild(ct(ss_data.length));
	d.appendChild(b);
	ss_nav = d;
	d.className = 'ss-band';
	if(ss_data.length > 1)
	{
		_ss.appendChild(d);

		d = ce('div');
		d.className = 'pad';
		_ss.appendChild(d);

		aE(document, 'keydown', ss_KeyDown);
	}

	b = ce('div');
	b.className = 'ss-border';

	i = ce('img');
	i.onload = function() { this.style.visibility = 'visible' };
	if(isIE6)
		i.galleryimg = 'no';
	ss_border = b;
	ss_img = i;

	if(ss_data.length > 1)
	{
		b.onclick = ss_NextPage;
		b.onmousedown = rf;
		b.style.cursor = 'pointer';
	}

	b.appendChild(i);
	_ss.appendChild(b);

	d = ce('div');
	d.className = 'pad';
	_ss.appendChild(d);

	d = ce('div');
	_ = ce('div');
	_.className = 'ss-desc';
	_.style.display = 'none';
	ss_desc = _;
	d.appendChild(_);
	
	_= ce('div');
	_.className = 'ss-by';
	_.appendChild(ct('From '));
	a = ce('a');
	a.appendChild(ct(' '));
	a.style.fontWeight = 'bold';
	_.appendChild(a);
	s = ce('span');
	s.appendChild(ct(' '));
	ss_ago = s;
	_.appendChild(s);
	ss_by = _;
	d.appendChild(_);

	_ = ce('div');
	_.className = 'ss-hd';
	_.style.display = 'none';
	a = ce('a');
	a.appendChild(ct('View'));
	_.appendChild(a);
	_.appendChild(ct(' '));
	ss_hd = _;
	d.appendChild(_);
	d.className = 'ss-band';
	_ss.appendChild(d);

	ssId = parseInt(location.hash.substr(1));
	if(!isNaN(ssId) && ssId > 0)
	{
		for(var i = 0; i < ss_data.length; ++i)
		{
			if(ss_data[i][0] == ssId)
			{
				ss_page = i;
				break;
			}
		}
	}

	ss_UpdateNav(1);
}

function ss_KeyDown(event)
{
	if(event.keyCode == 37)
		ss_PrevPage();
	else if(event.keyCode == 39)
		ss_NextPage();
}

function ss_UpdateNav(first)
{
	ss_nav.childNodes[2].firstChild.nodeValue = ss_page + 1;

	var fields = ss_data[ss_page];
	var path = ss_path;
	
	if(fields[1] != fields[3] || fields[2] != fields[4])
	{
		ss_hd.firstChild.href = ss_path + fields[0] + '.jpg';
		ss_hd.childNodes[1].nodeValue = ' high resolution version (' + fields[3] + 'x' + fields[4] + ', ' + fields[5] + ')';
		ss_hd.style.display = '';
		path += 'resized/';
	}
	else
		ss_hd.style.display = 'none';

	var postedOn = new Date(fields[6]),
	    elapsed  = (g_serverTime - postedOn) / 1000;

	ss_border.style.width = fields[1] + 'px';
	ss_border.style.height = fields[2] + 'px';
	ss_img.width = fields[1];
	ss_img.height = fields[2];
	ss_img.style.visibility = 'hidden';
	ss_img.src = path + fields[0] + '.jpg';
	ss_by.childNodes[1].firstChild.nodeValue = fields[7];
	ss_by.childNodes[1].href = '?user=' + fields[7];
	ss_by.childNodes[2].firstChild.nodeValue = ' ' + g_FormatTimeElapsed(elapsed, 0) + ' ago';

	if(fields[8])
	{
		ss_desc.innerHTML = fields[8];
		ss_desc.style.display = '';
	}
	else
		ss_desc.style.display = 'none';

	if(!first)
		location.replace('#' + ss_data[ss_page][0]);
}

function ss_PrevPage()
{
	if(ss_page > 0)
		--ss_page;
	else
		ss_page = ss_data.length - 1;
	ss_UpdateNav(0);
	return false;
}

function ss_NextPage()
{
	if(ss_page < ss_data.length - 1)
		++ss_page;
	else
		ss_page = 0;
	ss_UpdateNav(0);
	return false;
}
