/* ************************************************************
 * CVS Header: This header is generated automatically.
 *             Do not remove
 * ************************************************************
 * $Header: /cvsprojekte/baershop/jshop/resources/scroller.js,v 1.3.2.1 2009/01/19 09:19:57 schofield Exp $
 *
 * $Name: orbis-3_1_0 $ 
 *
 ************************************************************ */

/**
 *
 */
function Scroller( id, width, height, bgColor, margin, padding, speed, pauseOnMouseOver, textSeparator )
{
	var _id				  = id;
	var _width	 		  = width;
	var _height  		  = height;
	var _bgColor 		  = bgColor;
	var _margin			  = margin;
	var _padding 		  = padding;
	var _speed	 		  = speed;
	var _pauseOnMouseOver = pauseOnMouseOver;
	var _text			  = "";
	var _textSeparator    = textSeparator;
	
	var _scroller		  = null;
	var _scrollTextWidth  = 0;
	var _scrollSpeed	  = 1;
	
	this.addText = function( text )
	{
		if( _text == "" )
		{
			_text = text;
		}
		else
		{
			_text += _textSeparator + text;
		}
	}
	
	this.start = function()
	{
		var element = document.createElement( "span" );
		var elementText = document.createTextNode( _text.replace( /&nbsp;/g, ' ' ) );
		
		element.setAttribute( "id", "temp" + _id );
		element.appendChild( elementText );
		
		document.getElementById( "scrollData" ).appendChild( element );
		
		var margin = null;
		
		if( isNaN( _margin ) )
		{
			margin = _margin;
		}
		else
		{
			margin 		  = new Object();
			margin.top 	  = _margin;
			margin.bottom = _margin;
			margin.left   = _margin;
			margin.right  = _margin;
		}
		
		var tableStyle = "width: " + ( parseInt( _width ) + 6 ) + "px; " +
						 "background-color: " + _bgColor + "; " +
						 "padding: " + _padding + "; " +
						 "margin-top: " + margin.top + "px; " + 
						 "margin-bottom: " + margin.bottom + "px; " + 
						 "margin-left: " + margin.left + "px; " + 
						 "margin-right: " + margin.right + "px; " + 
						 "border: 0px;";
		
		var divStyle = "width: " + _width + "px; " +
					   "height: " + _height + "px;";
		
		var mouseHandler = "";
		
		if( _pauseOnMouseOver )
		{
			mouseHandler = 'onMouseOver="' + _id + '.stop()" onMouseOut="' + _id + '.resume()"';
		}

		document.write( '<table border="0" cellspacing="0" cellpadding="0" style="' + tableStyle + '">');
		document.write( '    <tr>' );
		document.write( '        <td>' );
        document.write( '            <div style="position: relative; overflow: hidden; ' + divStyle + '" ' + mouseHandler + '>' );
        document.write( '                <div id="scroller' + _id + '" style="margin-top: 1px; margin-left: -20px; position: absolute; left: 0px; top: 0px; valign: bottom;">&nbsp;</div>' );
        document.write( '            </div>' );
        document.write( '        </td>' );
        document.write( '    </tr>' );
        document.write( '</table>' );
		
		_scrollTextWidth = document.getElementById( "temp" + _id ).offsetWidth + 50;
		
		_scroller = document.getElementById( "scroller" + _id );
		_scroller.style.left = ( _width + 8 ) + "px";
		
		_scroller.innerHTML = "<nobr>" + _text + "</nobr>";
		
		window.setInterval( _id + ".scroll()", 20 );
	}
	
	this.scroll = function()
	{
		if( parseInt( _scroller.style.left ) > ( _scrollTextWidth * ( -1 ) + 8 ) )
        {
            _scroller.style.left = ( parseInt( _scroller.style.left ) - _scrollSpeed ) + "px";
        }
        else
        {
            _scroller.style.left = ( parseInt( _width ) + 8 ) + "px";
        }
    }
    
    this.stop = function()
    {
    	_scrollSpeed = 0;
    }
    
    this.resume = function()
    {
    	_scrollSpeed = _speed;
    }
}