/**
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * JavaScript Simple Fx
 * Copyright (c) 2000-2002 Soft Trek Consulting Australia
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Fader class
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function FaderItem (whichID, title, titleColors)
{
	this.m_whichID = whichID;
	this.m_title = title;
	this.m_iTitle = 0;
	this.m_iTitleColor = 0;
	this.m_titleColors = titleColors;
	this.m_MaxTitlecolor = titleColors.length;
}

function runFader (faderItem)
{
	var cell = document.getElementById(faderItem.m_whichID);
	var html="<b><font size='+2'>";

	var normColor = "";
	normColor = faderItem.m_titleColors[faderItem.m_iTitleColor];

	html += "<font color="+normColor+">"+faderItem.m_title+"</font>";
	html += "</font></b>";

	faderItem.m_iTitle = 0;
	faderItem.m_iTitleColor++;
	if (faderItem.m_iTitleColor >= faderItem.m_MaxTitlecolor)
	{
		faderItem.m_iTitleColor = 0;
	}

	if (cell)
	{
		cell.innerHTML = html;
	}
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Highlight text
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function HighlightItem (totalText, iCurr, iPrev)
{
	this.m_totalText = totalText;
	this.m_iCurr = iCurr;
	this.m_iPrev = iPrev;
	this.m_prefix = "divText_s";
}

function runHighlight (item)
{
	var control = eval (item.m_prefix+item.m_iPrev);
	control.style.color= "black";
	control.style.weight= "";

	control = eval (item.m_prefix+item.m_iCurr);
	control.style.color= "red";
	control.style.weight= "bold";

	item.m_iPrev = item.m_iCurr;
	item.m_iCurr++;
	if (item.m_iCurr >= item.m_totalText)
	{
		item.m_iCurr= 0; // reset
	}
}
function resetHighlight (item, totalText, prefix)
{
	item.m_totalText = totalText;
	item.m_iCurr = 0;
	item.m_iPrev = 0;
	item.m_prefix = prefix;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Marquee helper - make it generic later
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var m_marqueeColors = new Array (
	"#0000ff", "#0011ff", "#0022ff", "#0033ff", "#0044ff", "#0055ff", "#0066ff", "#0077ff", "#0088ff", "#0088ff", "#00aaff", 
	"#00aaff", "#0099ff", "#0088ff", 	"#0077ff", "#0066ff", "#0055ff", "#0044ff", "#0033ff", "#0022ff", "#0011ff", "#0000ff"
	);
var m_iMarqueeColor = 0;
function animateMarqueeColor ()
{
	if (document.all.divMarquee)
	{
		document.all.divMarquee.style.color = m_marqueeColors[m_iMarqueeColor];
		m_iMarqueeColor++;
		if (m_iMarqueeColor >= m_marqueeColors.length)
			m_iMarqueeColor = 0;
	}
	m_MarqueeTimer = window.setTimeout("animateMarqueeColor ()", 2000);
}

function MarqueeTextItem (text)
{
	this.screenLimit = 80;
	this.step = 8;
	this.workText = "";
	for (i = 0; i < this.screenLimit; i++)
	{
		this.workText += "·";
	}
	this.workText += text;
}

function runMarqueeText (marqueeText)
{
	if (document.all.divMarquee)
	{
		var prefixText = marqueeText.workText.substring (0,marqueeText.step);
		var viewText = marqueeText.workText.substring (marqueeText.step, marqueeText.screenLimit+marqueeText.step);
		document.all.divMarquee.innerHTML = viewText;
		var text = marqueeText.workText.substring (marqueeText.step, marqueeText.workText.length)+ prefixText; // append to the end
		marqueeText.workText = text;
	}

}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// AnimateGlow class
// translated from an Italian page
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function AnimateGlowItem (selectedSubMenu, initialStrength, incStrength)
{
	this.m_selectedSubMenu = selectedSubMenu;
	this.m_strength = initialStrength;
	this.m_incStrength = incStrength;
}

var m_glowColors= new Array ("#ffff00", "#ffcc00");
function runGlow (glowItem)
{
	if (m_glowItem.m_selectedSubMenu)
	{
		var ran = Math.random()*100;
		var intValue = Math.round(ran) % m_glowColors.length;

		if (glowItem.m_selectedSubMenu)
		{
			glowItem.m_selectedSubMenu.filters(0).color = m_glowColors[intValue];
		}

		glowItem.m_strength = glowItem.m_strength+ glowItem.m_incStrength;
		if (glowItem.m_selectedSubMenu)
		{
			glowItem.m_selectedSubMenu.filters(0).strength = glowItem.m_strength;
		}
		if (glowItem.m_strength >= 10)
			glowItem.m_incStrength = -1;
		if (glowItem.m_strength <= 0)
			glowItem.m_incStrength = 1;
	}
}
function resetGlow (glowItem, control)
{
	if (glowItem.m_selectedSubMenu)
	{
		glowItem.m_selectedSubMenu.filters(0).strength = 0;
		glowItem.m_selectedSubMenu.filters(0).color = "#000000";
	}
	m_glowItem.m_selectedSubMenu= control;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// News class
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function NewsItem (htmlItem, arTxt, blendSeconds, maxLoops) 
{
	this.m_arNews = new Array();
	for (i=0; i< arTxt.length; i++) 
	{
		this.m_arNews[i] = new Array();
		this.m_arNews[i][0] = "#";
		this.m_arNews[i][1] = arTxt[i];
	}

	this.m_blendInt = blendSeconds;
	this.m_maxLoops = maxLoops;
	this.m_finite = (this.m_maxLoops > 0) ? 1 : 0;
	this.m_loopCount= 0;
	this.m_newsCount= 0;
	this.m_blendTimer = 0;
	this.m_htmlItem = htmlItem;

	if (this.m_finite) 
		this.m_loopCount = 0;
}

function News_run(item) 
{
	if (item.m_finite && item.m_loopCount==item.m_maxLoops) 
	{
		clearInterval(item.m_blendTimer);
		return;
	}
	var newsStr = "<A CLASS=newslink "
            + "HREF=" + item.m_arNews[item.m_newsCount][0] + ">"
            + item.m_arNews[item.m_newsCount][1] + "</A>"

	item.m_htmlItem.filters.blendTrans.Apply();
	item.m_htmlItem.innerHTML = newsStr;
	item.m_htmlItem.filters.blendTrans.Play();
	item.m_newsCount++;
	if (item.m_newsCount == item.m_arNews.length) 
	{
		item.m_newsCount=0;
		if (item.m_finite) 
			item.m_loopCount++;
	}
}

function News_setFunc(item, funcName) 
{
	item.m_blendTimer = setInterval(funcName,item.m_blendInt*1000)
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Mouse banner
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var m_mouseBanner = null;
function MouseBannerItem (msg)
{
	this.x = 0;
	this.y = 0;
	this.step = 10;
	this.flag = 0;
	this.message = msg.split("");
	this.xpos = new Array();
	for (i = 0; i <= this.message.length - 1; i++) 
	{
		this.xpos[i] = -50;
	}
	this.ypos = new Array();
	for (i = 0; i <= this.message.length - 1; i++) 
	{
		this.ypos[i]= -50;
	}
}
function MouseBanner_handleEvent(e) 
{
	m_mouseBanner.x = (document.layers) ? e.pageX : document.body.scrollLeft + event.clientX;
	m_mouseBanner.y = (document.layers) ? e.pageY : document.body.scrollTop + event.clientY;
	m_mouseBanner.flag = 1;
}


function MouseBanner_animate() 
{
	if (m_mouseBanner.flag == 1 && document.all) 
	{
		for (i = m_mouseBanner.message.length - 1; i >= 1; i--) 
		{
			m_mouseBanner.xpos[i] = m_mouseBanner.xpos[i - 1] + m_mouseBanner.step;
			m_mouseBanner.ypos[i] = m_mouseBanner.ypos[i - 1];
		}

		m_mouseBanner.xpos[0] = m_mouseBanner.x + m_mouseBanner.step;
		m_mouseBanner.ypos[0] = m_mouseBanner.y;
		for (i = 0; i < m_mouseBanner.message.length - 1; i++) 
		{
			var thisspan = eval("span" + (i) + ".style");
			thisspan.posLeft = m_mouseBanner.xpos[i];
			thisspan.posTop = m_mouseBanner.ypos[i];
		}
	}
	else if (m_mouseBanner.flag==1 && document.layers) 
	{
		for (i = m_mouseBanner.message.length - 1; i >= 1; i--) 
		{
			m_mouseBanner.xpos[i] = m_mouseBanner.xpos[i - 1] + m_mouseBanner.step;
			m_mouseBanner.ypos[i] = m_mouseBanner.ypos[i - 1];
		}
		m_mouseBanner.xpos[0] = m_mouseBanner.x + m_mouseBanner.step;
		m_mouseBanner.ypos[0] = m_mouseBanner.y;

		for (i = 0; i < m_mouseBanner.message.length - 1; i++) 
		{
			var thisspan = eval("document.span" + i);
			thisspan.left = m_mouseBanner.xpos[i];
			thisspan.top = m_mouseBanner.ypos[i];
		}
	}
	var timer = setTimeout("MouseBanner_animate()", 25);
}

// 1) call this
function MouseBanner_init (msg)
{
	if (true)
	{
		return;
	}

	m_mouseBanner = new MouseBannerItem (msg);
	for (i = 0; i <= m_mouseBanner.message.length-1; i++) 
	{
		document.write("<span id='span"+i+"' style='position:absolute;z-index:999;background-color:#f0f0f0;color:#ff0000;'>");
		document.write(m_mouseBanner.message[i]);
		document.write("</span>");
	}

	if (document.layers)
	{
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = MouseBanner_handleEvent;
	MouseBanner_animate();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Menu helpers
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function Menu_reset()
{
	elList = document.getElementsByTagName("A");

	for (i = 0; i < elList.length; i++)
	{
	    Menu_removeName(elList[i], "Disable");
	}
}
function Menu_disable(tabID)
{
	elList = document.getElementsByTagName("A");

	for (i = 0; i < elList.length; i++)
	{
		// Check if the link's target matches the tab being loaded.
		if (elList[i].id == tabID)
		{
			// mark it as disable
			elList[i].className += " Disable";
			elList[i].blur();
		}
	}
}
function Menu_checkDisable (disables)
{
	for( var i = 0 ; i < disables.length; i++ )
	{
		if (disables[i])
		{
			// this is 0 based
			var id = "menu"+i;
			Menu_disable (id);
		}
	}
}

/**
 * Horizontal Menu
 * To implement scrolling effects; best to set MENU_OFFSET to be 0
 * and to disable the setting of m_menuOffset from external
 */
var MENU_START_POSITION=-600; // this is only for our case! adjust this if menu is longer
var MENU_OFFSET=300;
var MENU_TOP_POSITION=20;

var m_menuPos=MENU_START_POSITION;
var m_timerHide = -1;
var m_timerShow;
var m_elmnt = null;
var m_menuOffset = MENU_OFFSET;
function HMenu_show()
{
	if (m_menuPos<0)
	{
		m_menuPos=m_menuPos+m_menuOffset;
		document.all(m_elmnt).style.top=MENU_TOP_POSITION;
		document.all(m_elmnt).style.left=m_menuPos;
	}
}

function HMenu_hide()
{
	if (m_menuPos> MENU_START_POSITION)
	{
		document.all(m_elmnt).style.left=MENU_START_POSITION;
	}
	else
	{
		// no more swapping - turn the current element off
		m_elmnt = null;
	}
}

function HMenu_stopHidingChecks()
{
	if (-1 != m_timerHide)
	{
        window.clearTimeout (m_timerHide);
		m_timerHide= -1;
	}
}

function HMenu_startHidingChecks()
{
	HMenu_stopHidingChecks();
	m_timerHide=window.setTimeout("HMenu_hide()", 2000);
}

/**
 * Horizontal menu
 * The requirement is simple
 * you need to define <div> ... </div>
 */
function HMenu_showmenu(elmnt, eltLen)
{
	if (eltLen > 0)
	{
		m_menuOffset = eltLen;
	}

	if (m_elmnt)
	{
		document.all(m_elmnt).style.left=MENU_START_POSITION;
	}
	m_elmnt = elmnt;
	m_menuPos = MENU_START_POSITION;
	m_timerShow=setInterval("HMenu_show()",10);
	HMenu_stopHidingChecks();
}

/**
 * These two Menu_setActive, Menu_removeName is one way to set an active flag
 * By creating an appropriate item in the css "xxxx.Active" then we can differentiate
 * the two items.
 */
function Menu_removeName(el, name)
{
	var i, curList, newList;

	if (el.className == null)
		return;

	// Remove the given class name from the element's className property.
	newList = new Array();
	curList = el.className.split(" ");
	for (i = 0; i < curList.length; i++)
	{
		if (curList[i] != name)
			newList.push(curList[i]);
	}
	el.className = newList.join(" ");
}

function Menu_setActive(tabID)
{
	var elList = document.getElementsByTagName("A");

	for (var i = 0; i < elList.length; i++)
	{
		// Check if the link's target matches the tab being loaded.
		if (elList[i].id == tabID)
		{
			// If the link's URL matches the page being loaded, activate it.
			// Otherwise, make sure the tab is deactivated.

			elList[i].className += " Active";
			elList[i].blur();
		}
		else
		{
		    Menu_removeName(elList[i], "Active");
		}
	}
}
/**
 * Sets the title of the menu.
 * Strips the [] if any
 */
function Menu_setTitle (hmenuID)
{
	var ctrl = eval ("document.all."+hmenuID);
	if (ctrl)
	{
		var value = ctrl.innerHTML;
		ctrl = eval ("document.all.menuTitleID");
		if (ctrl)
		{
			var startIdx = value.indexOf ('[');
			if (startIdx != -1)
			{
				startIdx++;
				var endIdx = value.indexOf (']');
				if (endIdx != -1 && endIdx > startIdx)
				{
					value = value.substring (startIdx, endIdx- startIdx+1);
				}
			}
			ctrl.innerHTML = value;
		}
	}
}
