/***********************************************
* Cross browser Marquee script- © Dynamic Drive (www.dynamicdrive.com)
* For full source code, 100's more DHTML scripts, and Terms Of Use, visit http://www.dynamicdrive.com
* Credit MUST stay intact
***********************************************/
function cMarqueeScroller( strOuterDivID, strInnerDivID, strFloatingDivID, 
	strHiddenSpanForSizingID, intMarqueeWidth, intMarqueeSpeed,
	blnPauseOnMouseOver, strXmlData )
{
	this.m_strOuterDivID = strOuterDivID;
	this.m_strInnerDivID = strInnerDivID;
	this.m_strFloatingDivID = strFloatingDivID;
	this.m_strHiddenSpanForSizingID = strHiddenSpanForSizingID;
	this.m_strXmlData = strXmlData;
    
	this.m_ctrlOuterDiv = null;
	this.m_ctrlInnerDiv = null;
	this.m_ctrlFloatingDiv = null;
	this.m_ctrlHiddenSpanForSizing = null;

	//Specify the marquee's width (in pixels)
	this.m_intMarqueeWidth = intMarqueeWidth;

	//Specify the marquee's marquee speed (larger is faster 1-10)
	this.m_intMarqueeSpeed = intMarqueeSpeed;

	//Pause marquee onMousever (0=no. 1=yes)?
	if( blnPauseOnMouseOver )
	{
		this.m_intPauseOnMouseover = 1;
	}
	else
	{
		this.m_intPauseOnMouseover = 0;
	}

	this.m_intMarqueeSpeed = (document.all)? this.m_intMarqueeSpeed : Math.max(1, this.m_intMarqueeSpeed-2); //slow speed down by 1 for NS
	this.m_intCopySpeed = this.m_intMarqueeSpeed;
	this.m_intPauseSpeed = (this.m_intPauseOnMouseover==0)? this.m_intCopySpeed: 0;
	this.m_blnIeDom = document.all||document.getElementById;
	this.m_intActualWidth = 0;

	// Populate the marquee
	//
	this.populate = function()
	{
		if (this.m_blnIeDom)
		{
			this.m_ctrlFloatingDiv.style.left = parseInt(this.m_intMarqueeWidth)+8+"px";
			this.m_ctrlFloatingDiv.innerHTML = this.m_strMarqueeContent;
			this.m_intActualWidth = this.m_ctrlHiddenSpanForSizing.offsetWidth;

			// Reposition the floating div to center it vertically within the container div
			var intSpace = this.m_ctrlOuterDiv.offsetHeight - this.m_ctrlFloatingDiv.offsetHeight;
			this.m_ctrlFloatingDiv.style.top = Math.round( (intSpace / 2 ) - 1 ) + "px";
		}
		lefttime=setInterval(this.selfName+".scrollmarquee()",20);
	};

	// Scroll the marquee
	//
	this.scrollmarquee = function()
	{
		if (this.m_blnIeDom)
		{
			if (parseInt(this.m_ctrlFloatingDiv.style.left)>(this.m_intActualWidth*(-1)+8))
				this.m_ctrlFloatingDiv.style.left=parseInt(this.m_ctrlFloatingDiv.style.left)-this.m_intCopySpeed+"px";
			else
				this.m_ctrlFloatingDiv.style.left=parseInt(this.m_intMarqueeWidth)+8+"px";
		}
	};

	// When mouse is rolled over, pause the scroller IF in that mode
	//
	this.onMouseOver = function( ev )
	{
		if( this.m_intPauseOnMouseover != 0 )
		{
			this.m_intCopySpeed = this.m_intPauseSpeed;
		}
	}

	// When mouse out...
	//
	this.onMouseOut = function( ev )
	{
		this.m_intCopySpeed = this.m_intMarqueeSpeed;
	}

	// Function that runs when the page loads
	this.onLoad = function()
	{
		this.m_ctrlOuterDiv = document.getElementById( this.m_strOuterDivID );
		this.m_ctrlInnerDiv = document.getElementById( this.m_strInnerDivID );
		this.m_ctrlFloatingDiv = document.getElementById( this.m_strFloatingDivID );
		this.m_ctrlHiddenSpanForSizing = document.getElementById( this.m_strHiddenSpanForSizingID );

		var result = SharedUL.parseXML( this.m_strXmlData );
		var objThis = this;
		var objRoot = result.firstChild;
		if( objRoot != null )
		{
			var objNodes = objRoot.getElementsByTagName( "item" );
			this.m_intCountItems = objNodes.length;
			var strTmp = '';
			for( ii = 0; ii < this.m_intCountItems; ii++ )
			{
				if( objNodes[ii].firstChild != null )
				{
					strTmp += objNodes[ii].firstChild.nodeValue;
					strTmp += ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;';
				}
			}

			// Cleanup the text
			strTmp = this.convertToPlainText( strTmp );
		
			this.m_strMarqueeContent = '<nobr>' + strTmp + '</nobr>';
			this.m_ctrlHiddenSpanForSizing.innerHTML = this.m_strMarqueeContent;

			this.populate();
		}
	};
	
	// Replace some special characters with hex encoded values
	// and remove the all tags (like html tags)
	this.convertToPlainText = function( strSource )
	{
		// Remove tags
		str1 = strSource.replace( /<[^>]*>/g, " " );

		// Replace these characters with their hex escaped values
		str1 = str1.replace( "%", "\x25" );
		str1 = str1.replace( "'", "\x27" );
		str1 = str1.replace( "\"", "\x22" );

		// Get rid of line feeds, since this is a single line marquee
		str1 = str1.replace( "\r\n", " " );
		str1 = str1.replace( "\n", " " );
		str1 = str1.replace( "\r", " " );

		return str1;
	};

	return this;
}