/* Version: site 5.5.0.0, script 1.0.0.0 */
var imgCollapse = "articles/images/collapse.png";
var imgExpand = "articles/images/expand.png";
var statusExpand = "Expand";
var statusCollapse = "Collapse";
var expandAll = "Expand All";
var collapseAll = "Collapse All";
var allExpanded = false;

function GetPanelStyle(panelId)
{
	var panel = null;
	if (document.getElementById)
	{
		panel = document.getElementById(panelId).style;
	}
	else
	{
		panel = document.all(panelId).style;
	}
	return panel;
}
function GetImage(imgId)
{
	var image = null;
	if (document.getElementById)
	{
		image = document.getElementById(imgId);
	}
	else
	{
		image = document.all(imgId);
	}
	return image;
}
function TogglePanel(imgId, panelId)
{
	var expanded = false;
	
	var panel = GetPanelStyle(panelId);
	if (panel != null)
	{
		if (panel.display == 'none')
		{
			// Expand...
			panel.display = '';
			expanded = true;
		}
		else
		{
			// Collapse...
			panel.display = 'none';
		}
	}
	var img = GetImage(imgId);
	if (img != null)
	{
		if (expanded)
		{
			img.src = imgCollapse;
			img.alt = statusCollapse;
			img.title = statusCollapse;
		}
		else
		{
			img.src = imgExpand;
			img.alt = statusExpand;
			img.title = statusExpand;
		}
	}
	return false;
}
function ExpandCollapseAll(baseId, total, allImgId, allCaptionId)
{
	// baseId like 'sampleCode'...
	var baseImgId = baseId + "Img";
	var basePanelId = baseId + "Panel"
	var imageId, panelId;
	var image, panel;
	
	for (index = 1; index <= total; index++)
	{
		imageId = baseImgId + index.toString();
		panelId = basePanelId + index.toString();
		panel = GetPanelStyle(panelId);
		if (panel != null)
		{
			if (allExpanded)
			{
				panel.display = 'none';
			}
			else
			{
				panel.display = '';
			}
		}
		image = GetImage(imageId);
		if (image != null)
		{
			if (allExpanded)
			{
				image.src = imgExpand;
				image.alt = statusExpand;
				image.title = statusExpand;
			}
			else
			{
				image.src = imgCollapse;
				image.alt = statusCollapse;
				image.title = statusCollapse;
			}
		}
	}
	var allImage, allImageCaption;
	if (document.getElementById)
	{
		allImage = document.getElementById(allImgId);
		allImageCaption = document.getElementById(allCaptionId);
	}
	else
	{
		allImage = document.all(allImgId);
		allImageCaption = document.all(allCaptionId);
	}
	if (allImage != null)
	{
		if (allExpanded)
		{
			allImage.src = imgExpand;
			allImage.alt = expandAll;
			allImage.title = expandAll;
		}
		else
		{
			allImage.src = imgCollapse;
			allImage.alt = collapseAll;
			allImage.title = collapseAll;
		}
	}
	if (allImageCaption != null)
	{
		if (allExpanded)
		{
			allImageCaption.innerHTML = expandAll;
		}
		else
		{
			allImageCaption.innerHTML = collapseAll;
		}
	}
	allExpanded = !allExpanded;
	return false;
}
var customTip = new CustomTip;
function CustomTip()
{
	var _id = 'tip';
	var _tip;
	var _maxWidth = 300;
	var _interval = 10000;
	var _timerRef;
	this.Show = Show;
	this.Hide = Hide;

	function Show(e, tipText)
	{
		if (_tip == null)
		{
			// Create the custom tool tip div...
			_tip = document.createElement('div');
			_tip.setAttribute('id', _id);
			_tip.style.display = 'none';
			document.body.appendChild(_tip);
		}
		_tip.style.display = 'block';
		_tip.innerHTML = tipText;
		_tip.style.width = 'auto';
		if(_tip.offsetWidth > _maxWidth)
		{
			_tip.style.width = _maxWidth + 'px';
		}
		var x = e.clientX;
		var offsetX = OffsetLeft(e);
		var y = e.clientY;
		var offsetY = OffsetTop(e);
		
		var winWidth = 0;
		var winHeight = 0;
		if (window.innerWidth)
		{
		    winWidth = window.innerWidth - 16;
			winHeight = window.innerHeight - 16;
		}
		else
		{
			winWidth = (document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth);
			winHeight = (document.documentElement ? document.documentElement.clientHeight : document.body.clientHeight);
		}
		if ((x + _tip.offsetWidth) > winWidth)
		{
			offsetX = winWidth  - _tip.offsetWidth;
		}
		if ((y + _tip.offsetHeight) > winHeight)
		{
			offsetY -= _tip.offsetHeight;
		}
		else
		{
			// Below(ish) cursor...
			offsetY += 18;
		}
		_tip.style.top = offsetY + 'px';
		_tip.style.left = offsetX + 'px';
		_timerRef = setTimeout(Hide, _interval);
	}
	function OffsetLeft(e)
	{
		var x = e.clientX;
		if (e.pageX)
		{
			x = e.pageX;
		}
		else
		{
			x = e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		}
		return x;
	}
	function OffsetTop(e)
	{
		var y = e.clientY;
		if (e.pageY)
		{
			y = e.pageY;
		}
		else
		{
			y = e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		}
		return y;
	}
	function Hide()
	{
		if (_tip != null)
		{
			clearTimeout(_timerRef);
			_tip.style.display = 'none';
		}
	}
}
