// ScrollDiv.js
// Include ScrollDiv.js at the top of the body, before start of any tables or other tags


var ScrollDiv_timer;


function ScrollDiv_scrollLeft(scrollDivId)
{
	ScrollDiv_timer = setInterval("document.getElementById('" + scrollDivId + "').scrollLeft -= 2;", 15);
}


function ScrollDiv_scrollRight(scrollDivId)
{
	ScrollDiv_timer = setInterval("document.getElementById('" + scrollDivId + "').scrollLeft += 2;", 15);
}


function ScrollDiv_stopScroll()
{
	clearInterval(ScrollDiv_timer);
}


function ScrollDiv_getStringWidth(s)
{ 
	if(document.getElementById) {
		var rulerSpan = document.getElementById('ScrollDivRuler');
		rulerSpan.innerHTML = s;
		width = rulerSpan.offsetWidth;
		rulerSpan.innerHTML = "";
		return(width);
	}

	return 0;
}


function ScrollDiv_initialize(className)
{
	// This is used by ScrollDiv_getStringWidth() to calculate width of text
	document.write('<span class="' + className + '" id="ScrollDivRuler" style="visibility:hidden; position:absolute"></span>');
}


function ScrollDiv_create(id, className, width, text)
{
	var textWidth = ScrollDiv_getStringWidth(text);
	
	document.write('<table border="0" cellspacing="0" cellpadding="0"><tr>');

	if(textWidth < width) {
		document.write('<td align="left" width="10px"></td>');
	}
	else {
		document.write('<td align="left" width="30px">');
		document.write('<input type="button" value="&lt;" title="Scroll left" style="width:25px; font-size:14px" onmousedown="ScrollDiv_scrollLeft(\'' + id + '\')" onmouseup="ScrollDiv_stopScroll()" onmouseout="ScrollDiv_stopScroll()">');
		document.write('</td>');
	}
	
	document.write('<td>');
	document.write('<div class="' + className +'" id="' + id + '" style="width:' + width + 'px; border:none; overflow:hidden;">');
	document.write('<nobr>' + text + '</nobr>');
	document.write('</div>');
	document.write('</td>');

	if(textWidth < width) {
		document.write('<td align="right" width="10px"></td>');
	}
	else {
		document.write('<td align="right" width="30px">');
		document.write('<input type="button" value="&gt;" title="Scroll right" style="width:25px; font-size:14px" onmousedown="ScrollDiv_scrollRight(\'' + id + '\')" onmouseup="ScrollDiv_stopScroll()" onmouseout="ScrollDiv_stopScroll()">');
		document.write('</td>');
	}
	
	document.write('</tr></table>');
}
