/*****************************************************************************/
/* Marquee v1.5 12.12.2006 JanciB & Tomy                                     */
/*****************************************************************************/

var MARQUEES = [];

function Marquee ( a_setup )
{
	this.a_setup = a_setup;

	this.i_speed = 0;
	this.i_step = 0;
	this.o_interval = null;

	this.Check = _Check;
	this.Init = _Init;
	this.Scroll = _Scroll;
	this.Move = _Move;
	this.Over = _Over;
	this.Out = _Out;

	this.i_id = MARQUEES.length;
	MARQUEES[this.i_id] = this;
	if ( ( this.s_error = this.Check () ) != '' )
	{
		alert ( this.s_error );
		return;
	}
	this.Init ();
	this.Scroll ();
}

function _Check ()
{
	var s_error = '';
	
	if ( typeof this.a_setup['horizontal'] == 'undefined' )
	{
		s_error += 'horizontal:boolean|true|false\n';		
	}
	if ( typeof this.a_setup['width'] == 'undefined' )
	{
		s_error += 'width:string_number|px|%\n';		
	}
	if ( typeof this.a_setup['height'] == 'undefined' )
	{
		s_error += 'height:string_number|px|%\n';		
	}
	if ( typeof this.a_setup['step'] == 'undefined' )
	{
		s_error += 'step:integer\n';		
	}
	if ( typeof this.a_setup['speed'] == 'undefined' )
	{
		s_error += 'speed:integer\n';		
	}
	if ( typeof this.a_setup['text'] == 'undefined' && typeof this.a_setup['text_from'] == 'undefined' )
	{
		s_error += 'text:string\n';
		s_error += 'text_from:string\n';
	}
	
	if ( s_error != '' ) s_error = 'Marquee configuration error!\n\nRequired parameters:\n\n' + s_error;
	
	return s_error;
}

function _Init ()
{
	this.i_speed = this.a_setup['speed'];
	this.i_step = this.a_setup['step'];

	if ( typeof this.a_setup['over_speed'] == 'undefined' )
	{
		this.a_setup['over_speed'] = 0;
	}

	if ( typeof this.a_setup['over_step'] == 'undefined' )
	{
		this.a_setup['over_step'] = this.a_setup['step'];
	}

	if ( typeof this.a_setup['text_from'] != 'undefined' )
	{
		var o_tmp = document.getElementById ( this.a_setup['text_from'] );

		if ( o_tmp != null )
		{
			this.a_setup['text'] = o_tmp.innerHTML;
		}else this.a_setup['text'] = '';
	}

	document.write ( '<div id="mp' + this.i_id + '" style="width: ' + this.a_setup['width'] + '; height: ' + this.a_setup['height'] + '; position: relative; overflow: hidden"' + ( typeof this.a_setup['class'] != 'undefined' ? ' class="' + this.a_setup['class'] + '"' : '' ) + ' onmouseover="MARQUEES[' + this.i_id + '].Over()" onmouseout="MARQUEES[' + this.i_id + '].Out()">\n' );
	document.write ( '<div id="ms' + this.i_id + '" style="' + ( this.a_setup['horizontal'] ? 'white-space: nowrap; display: inline' : '' ) + '; position: absolute; visibility: hidden">\n' );
	document.write ( this.a_setup['text'] );
	document.write ( '</div>\n' );
	document.write ( '</div>\n' );

	this.e_prn = document.getElementById ( 'mp' + this.i_id );
	this.e_son = document.getElementById ( 'ms' + this.i_id );	
	
	if ( this.a_setup['horizontal'] )
	{
		this.i_pos = this.e_prn.offsetWidth;
		this.e_son.style.left = this.i_pos + 'px';
		this.e_son.style.visibility = 'visible';
		this.i_min = 0 - this.e_son.offsetWidth;
		this.e_son.style.width = this.e_son.offsetWidth + 'px';
	}else
	{
		this.i_pos = this.e_prn.offsetHeight;		
		this.e_son.style.top = this.i_pos + 'px';
		this.e_son.style.visibility = 'visible';
		this.i_min = 0 - this.e_son.offsetHeight;
		this.e_son.style.height = this.e_son.offsetHeight + 'px';
	}

	this.i_max = this.i_pos;	
	this.e_son.style.display = 'block';
}

function _Move ()
{
	if ( this.i_speed == 0 ) return;
	this.i_pos -= this.i_step;
	if ( this.i_pos < this.i_min ) this.i_pos = this.i_max;
	if ( this.a_setup['horizontal'] ) this.e_son.style.left = this.i_pos + 'px';
	else this.e_son.style.top = this.i_pos + 'px';	
}

function _Scroll ()
{
	this.o_interval = setInterval ( 'MARQUEES[' + this.i_id + '].Move()', this.i_speed );
}

function _Over ()
{
	this.i_speed = this.a_setup['over_speed'];
	this.i_step = this.a_setup['over_step'];
	clearInterval ( this.o_interval );
	this.Scroll ();
}

function _Out ()
{
	this.i_speed = this.a_setup['speed'];
	this.i_step = this.a_setup['step'];
	clearInterval ( this.o_interval );
	this.Scroll ();
}
