
// Create a hex convertor array (Dex2Hex[])
var hexbase= new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
var value=0;
var Dec2Hex=new Array();
for (x=0; x<16; x++){
	for (y=0; y<16; y++){
		Dec2Hex[value]= hexbase[x] + hexbase[y];
		value++;
	}
}

// Convert RGB colour to string base
function RGB2STR(rgbcolor)
{
	return Dec2Hex[rgbcolor>>16] + Dec2Hex[(rgbcolor>>8)&0xFF] + Dec2Hex[rgbcolor&0xFF];
}

// Check the following variables to see if they exist. If not use default value
if (String(NT_colorFG)=="undefined") var NT_colorFG = 0x0000FF;	// Text color
if (String(NT_colorBG)=="undefined") var NT_colorBG = 0xFFFFFF;	// Background color
if (String(NT_ymax)   =="undefined") var NT_ymax    = 50;		// How many pixel to move
if (String(NT_ystep)  =="undefined") var NT_ystep   = 1;		// 1 or -1 only (Scroll direction)
if (String(NT_speed)  =="undefined") var NT_speed   = 2;		// The smaller the faster
if (String(NT_pause)  =="undefined") var NT_pause   = 600;		// Pause time(milisecond) between messages
if (String(NT_fadestep)=="undefined") {
	var NT_fadestep = NT_ymax>>1;
} else {
	if (NT_fadestep > (NT_ymax>>1)) NT_fadestep = NT_ymax>>1;
}

// check if user defined messages exist
if (String(NT_message)=="undefined") {
	// use the default messages
	var NT_message = new Array();
	NT_message[0] = 'No News Items Found';
}

var NT_ypos    = 0;
var NT_yposOrg = 0;
var NT_color   = NT_colorBG;
var NT_curMsg  = 0;
NT_last_direction = NT_ystep;

// Calculate the difference between background and foreground color
var half_NT_ymax = (NT_ymax)>>1
var dfRed   = -((NT_colorBG>>16) - (NT_colorFG>>16)) / NT_fadestep;
var dfGreen = -(((NT_colorBG>>8)&0xFF) - ((NT_colorFG>>8)&0xFF)) / NT_fadestep;
var dfBlue  = -((NT_colorBG&0xFF) - (NT_colorFG&0xFF)) / NT_fadestep;
var NT_opColor  = (dfRed<<16) + (dfGreen<<8) + (dfBlue);

var timer;
var NT;

function UnloadMe()
{
	clearTimeout(timer);
}

var isReadForNextText = 0;
var isChangeText = 0;

function ScrollText(currentstate)
{

	NT_ypos += NT_ystep;
	
	// Ready to change text?
	if (NT_ypos >= NT_ymax || NT_ypos <= 0)
		isChangeText = 1;
	else
		isChangeText = 0;

	// Need to set the timer first so that it will go smoothly
	if (isChangeText) {
		if (NT_pause < NT_speed)
			timer = setTimeout('ScrollText(0)', NT_speed);
		else
			timer = setTimeout('ScrollText(1)', NT_pause);
	} else
		timer = setTimeout('ScrollText(0)', NT_speed);

	// Change text
	if (isReadForNextText) {
		// For IE only
		TextScroll.innerHTML = NT_message[NT_curMsg];
		isReadForNextText = 0;
	}

	// Change the color of the text
	if (document.all) {
		// IE
		if (NT_last_direction != NT_ystep && (NT_ypos >= NT_ymax || NT_ypos <= 0)){
			//NT.paddingTop = NT_ypos;
		}
		else {
			NT.paddingTop = NT_ypos;
		}
		NT.color = NT_color;
	} else if (document.layers) {
		// Netscape
		NT.top = NT_ypos + NT_yposOrg;
		
		// Clip the text
		var calc = (NT.top-NT_yposOrg) + NT.document.height - 20
		if (calc > NT_ymax) {
			NT.clip.bottom=(NT.document.height) - (calc-NT_ymax);
		} else {
			NT.clip.bottom=NT.document.height;
		}

		// Display the text
		text  = '<SPAN CLASS="TextScrollStyle">' +
				'<FONT COLOR='+NT_colorFG+'>' +
				NT_message[NT_curMsg] +
				'</FONT></SPAN>';
		NT.backgroundColor = NT_colorBG;
		NT.backgroundColor = 'black';
             if (currentstate==1){
		NT.document.write(text);
		NT.document.close();
             }
	}
	if (NT_ypos < NT_fadestep || (NT_ymax - NT_ypos) < NT_fadestep) {
		//NT_color += NT_opColor
		if (NT_last_direction == NT_ystep){
			NT_color += NT_opColor
		}
		else{
			NT_color = NT_colorFG
			NT_last_direction = NT_ystep
			NT_opColor *= -1;
		}
	}

	// Check to see if in the middle, if so, change colour direction
	if (NT_ypos == half_NT_ymax) NT_opColor *= -1;
	
	// Prepare for next text please
	if (isChangeText) {
		NT_color = NT_colorBG;
		NT_opColor *= -1;

		if (NT_ystep > 0) {
			NT_ypos = 0;
		} else {
			NT_ypos = NT_ymax;
		}

		if (++NT_curMsg > NT_message.length-1) {
			NT_curMsg = 0;
		}

		// Change text
		if (document.all) {
			// IE
			TextScroll.innerHTML = " ";
			NT.paddingTop = NT_ypos;
			isReadForNextText = 1;
		} else if (document.layers) {
			NT.document.write('');
			NT.document.close();
			NT.top = NT_ypos + NT_yposOrg;
		}
	}
}

function startani(){
      if (document.layers)
      document.TextScroll.visibility="show"
      timer = setTimeout('ScrollText()', 1000)
}

function ScrollTextDisplay()
{
	var navName=navigator.appName;
	var navVer=parseInt(navigator.appVersion)
	var fNetscape = 0;
	
	if (! ((navName=="Netscape" && navVer>=4) || (navName=="Microsoft Internet Explorer" && navVer>=4)) ) {
		return;
	}
	if (navName=="Microsoft Internet Explorer") {
		NT_speed = 20 + NT_speed;
	} else if (navName=="Netscape") {
		fNetscape=1;
	}
	
	document.write('<ILAYER NAME="TextScroll" CLASS="TextScrollStyle" WIDTH="'+NT_scrollwidth+'" HEIGHT=' + (NT_ymax+20) + ' BGCOLOR=' + RGB2STR(NT_colorBG) + ' VISIBILITY="hide">');
	document.write('<LAYER NAME="Content" WIDTH="'+NT_scrollwidth+'">');
	document.write('<SPAN ID="TextScroll" CLASS="TextScrollStyle">');
	if (fNetscape) document.write('<FONT COLOR='+NT_colorFG+'>');
	document.write(NT_message[0]);
	if (fNetscape) document.write('</FONT>');
	document.write('</SPAN>');
	document.write('</LAYER>');
	document.write('</ILAYER>');

	if (NT_ystep > 0) {
		NT_ypos = 0;
	} else {
		NT_ypos = NT_ymax;
	}

	if (document.all) {
		// IE
		NT = TextScroll.style;
	} else if (document.layers) {
		// Netscape
		NT = document.TextScroll.document.Content;
		NT_yposOrg = NT.top;
	}
	NT.height = NT_ymax+20;
	NT.color = NT_color;
	NT.visibility = "visible";
	NT.backgroundColor = NT_colorBG;
	
	window.onload=startani
	window.onunload=UnloadMe;
}

ScrollTextDisplay()

//
// Navigation Functions
//
function nt_stop()
{
	UnloadMe()
}
//
function nt_start()
{
	setTimeout('ScrollText()', 500)
}
//
function nt_up()
{
	setCookie(javaCookieName,-1);
	UnloadMe();
	NT_ystep=-1;
	ScrollText()
}
//
function nt_down()
{
	setCookie(javaCookieName,1);
	UnloadMe();
	NT_ystep=1;
	ScrollText()
}
//
