<!--
// Author : Anoop Koshy
// Date   : 2000-Nov-30

// this marquee has a fixed left and right.
// this marquee goes from right to left, right to left and alternate;

// Following are the changes/includes in the <HEAD>

// <SCRIPT LANGUAGE="JavaScript1.2" SRC="marquee.js">
// </SCRIPT>
// <SCRIPT LANGUAGE="JavaScript1.2">
//   var intShift = 2;			// the bigger this, the faster marquee goes.
//   var strMarDirection = "LR";	// the direction of the marquee
// </SCRIPT>
//   LR - left to right    RL - right to left    AL - Alternate

// Following are the changes/includes in the <BODY>
// Define the marquee text as
// 	<DIV ID="ticktext" STYLE="position:absolute;visibility:hidden;" NOWRAP>
//		<A NAME="leftLocator"> </A>This is a simple line<A NAME="rightLocator"> </A>
// 	</DIV>
// in the beginning of the body. Use HTML tags to decorate your text.

// Define the left of the marquee as
// 	<A NAME="marqueeLeft"> </A>
// Define the right of the marquee as
// 	<A NAME="marqueeRight"> </A>
// A suggestion : Use a table with no border, the leftcolumn (width 1)for the left indicator,
//                the rightmost column (width 1) for the right indicator.
//                Make sure to  put atleast one &nbsp in the cell.

var isIE = document.all ? true : false ;				// browser identifier

var intLeftSide = 0;							// the left side in pixels
var intRightSide = 0;							// the right side in pixels
var intWidth = 0;

var intStartPos = 0;							// the start of marquee
var intEndPos =0;							// the end of marquee
var intStartPosY = 0;

var intMarLeft = 0;					// the moving marquee's left edge

var blnFirst = true;

function start()
{
	getMeasures();
	getLocation();
	switch(strMarDirection)
	{
		case "LR":
		case "AL":
			intMarLeft = intEndPos;
			break;
		case "RL":
			intMarLeft = intStartPos-intWidth;
			break;
	}
	
	if (isIE)
	{
		ticktext.style.posTop = intStartPosY;
		ticktext.style.visibility = "visible";
	}
	else
	{
		document.ticktext.pageY = intStartPosY;
		document.ticktext.visibility = "show";
	}
	setInterval('tick()', 10);
}

function getMeasures()
{
	if (isIE)
	{
    	pos = document.all['leftLocator'];
    	intLeftSide = getLeft(pos);
    	pos = document.all['rightLocator'];
    	intRightSide = getLeft(pos);
    	intEndPos = document.body.clientWidth;
	}
	else
	{
		pos = document.layers["ticktext"].document.anchors["leftLocator"];
		intLeftSide = pos.x;
		pos = document.layers["ticktext"].document.anchors["rightLocator"];
		intRightSide = pos.x;
		intEndPos = window.innerWidth;
	}

	intWidth = intRightSide - intLeftSide;

	if ((intStartPos + intWidth) >= intEndPos)
	{
		intEndPos = intStartPos + intWidth + 50;		// just make the width 50 more
	}

	//alert("left, right, width " + intStartPos + ", " + intEndPos + ", " + intWidth);

}

function getLeft(ll)
{
	if (ll.offsetParent)
		return (ll.offsetLeft + getLeft(ll.offsetParent));
	else
		return (ll.offsetLeft);
}

function getTop(ll)
{
	if (ll.offsetParent)
		return (ll.offsetTop + getTop(ll.offsetParent));
	else
		return (ll.offsetTop);
}

function getLocation()
{
	if (isIE)
	{
    	pos = document.all['marqueeLeft'];
    	intStartPos = getLeft(pos);
    	intStartPosY = getTop(pos);
    	pos = document.all['marqueeRight'];
    	intEndPos = getLeft(pos);

	}
	else
	{
		pos = document.anchors['marqueeLeft'];
		intStartPos = pos.x;
    		intStartPosY = pos.y;
		pos = document.anchors['marqueeRight'];
		intEndPos = pos.x;
	}
}

function tick()
{
	switch(strMarDirection)
	{
		case "RL":
			tickRL();
			break;
		case "LR":
			tickLR();
			break;
		case "AL":
			tickAL();
			break;
		case "AR":
			tickAR();
			break;
	}
	displayTick();
}


function tickRL()
{

	intMarLeft -= intShift;
	if (intMarLeft < (intStartPos-intWidth))
	{
		getLocation();						// after every scroll reevaluate the screen;
		if (strMarDirection == "AL") 
		{
			strMarDirection = "AR";
		}
		else
		{
			intMarLeft = intEndPos;
		}
	}
}

function tickLR()
{

	intMarLeft += intShift;
	if (intMarLeft > intEndPos)
	{
		getLocation();						// after every scroll reevaluate the screen;
		if (strMarDirection == "AR") 
			strMarDirection = "AL";
		else
			intMarLeft = intStartPos-intWidth;
	}
}

function tickAL()
{

	intMarLeft -= intShift;
	if (intMarLeft < intStartPos)
	{
		getLocation();						// after every scroll reevaluate the screen;
		strMarDirection = "AR";
	}
}

function tickAR()
{

	intMarLeft += intShift;
	if (intMarLeft > (intEndPos - intWidth))
	{
		getLocation();						// after every scroll reevaluate the screen;
		strMarDirection = "AL";
	}
}

function displayTick()
{
	intCutLeft = intStartPos - intMarLeft;
	intCutRight = intEndPos - intMarLeft;
	if (isIE)
	{
		ticktext.style.posLeft = intMarLeft;
		ticktext.style.clip = "rect(auto "+ intCutRight+"px auto "+intCutLeft+"px)";
	}
	else
	{
		document.ticktext.pageX = intMarLeft;
		document.ticktext.clip.left = intCutLeft;
		document.ticktext.clip.right = intCutRight;
	}
}

// -->
