/*****************************************************************************/
/* Marquee v1.3 3.6.2009 JanciB                                            */
/*****************************************************************************/

var MARQUEES = [];

function Marquee ( a_setup )
{
	this.a_setup = a_setup;

	this.Check = _Check;
	this.Init = _Init;
	this.Scroll = _Scroll;
	this.Move = _Move;
	this.Pause = _Pause;
	this.Continue = _Continue;
	this.Recalculate = _Recalculate;
	
	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' )
	{
		s_error += 'text:string\n';		
	}
	
	if ( s_error != '' ) s_error = 'Marquee configuration error!\n\nRequired parameters:\n\n' + s_error;
	
	return s_error;
}

function _Init ()
{
	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 + '].Pause()" onmouseout="MARQUEES[' + this.i_id + '].Continue()">\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 );	
	
	this.Recalculate ();
/*	
	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_prechod = 0;
	this.i_max = this.i_pos;	
	this.e_son.style.display = 'block';
	this.b_paused = false;	
}

function _Recalculate ()
{
	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';
	}
}

function _Move ()
{
	if ( this.b_paused ) return;
	this.i_pos -= this.a_setup['step'];
	if ( this.i_pos < this.i_min )
	{		
		this.i_prechod++;
		
		if ( ( this.i_prechod % 2 ) == 1 )
		{
			if ( typeof this.a_setup['text1'] != 'undefined' )
			{
				this.e_son.innerHTML = this.a_setup['text1'];
			}
		}else if ( ( this.i_prechod % 2 ) == 0 )
		{
			this.e_son.innerHTML = this.a_setup['text'];
		}
		
		this.Recalculate ();

		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 ()
{
	setInterval ( 'MARQUEES[' + this.i_id + '].Move()', this.a_setup['speed'] );
}

function _Pause ()
{
	this.b_paused = true;
}

function _Continue ()
{
	this.b_paused = false;
}
