var topMsg = new Array();
var topMsgDiv = null;
var startLeft;
var topUpdaterNum = 0;
var totalSize = 0;

function updateTopMsg()
{
	startLeft -= 3;
	if( startLeft < -totalSize )
		startLeft = map_zone_width;
	topMsgDiv.style.left = startLeft + "px";
	topUpdaterNum = setTimeout( "updateTopMsg()", 50 );
}

var accueil_top = function()
{
	var id;
	var isPlaying;
	var contained;
	var txtMarquee;
	var formXHR;
	
	var me = null;
	
	var isLoading = false;
	
	this.start = function( node )
	{
		isPlaying = false;
		
		formXHR = initXHR();
		me = this;
		
		id = node.getAttribute('id');
		
		isLoading = true;
		ajaxRequest( "././php/getTopMsg.php", formXHR, this.loadingDone, "" );
	}
	
	this.loadingDone = function( result )
	{
		isLoading = false;
		if( trackSqlError( result ) )
		{
			if( topMsgDiv != null )
			{
				removeAllNodes( topMsgDiv, true );
				topMsgDiv = null;
			}
			startLeft = 300;
			totalSize = 0;
			var i = topMsg.length - 1;
			while( i > 0-1 )
			{
				topMsg.pop();
				i--;
			}
			topMsg = result.split( '&' );
			var i = topMsg.length - 1;
			while( i > -1 )
			{
				totalSize += 7.4 * topMsg[i].length + 140;
				i--;
			}
		}
		
		// First time
		makeNextObject();
	}

	this.play = function( parent )
	{
		if( isPlaying == false )
		{
			contained = document.createElement("div");

			contained.setAttribute("id", id);

			contained.style.top = "0px";
			contained.style.left = "0px";
			contained.style.width = "100%";
			contained.style.height = "20px";
			contained.style.position = "absolute";
			contained.style.border = "solid";
			contained.style.borderWidth = "1px";
			contained.style.color = "#227722";
			contained.style.fontWeight = "bold";
			contained.style.background = "#EEEEEE";
			contained.style.overflow = "hidden";
			
			topMsgDiv = document.createElement("div");
			topMsgDiv.style.position = "absolute";
			topMsgDiv.style.left = startLeft + "px";
			topMsgDiv.style.width = totalSize + "px";
			
			var i = 0;
			while( i < topMsg.length )
			{
				var temp = document.createTextNode(topMsg[i]);
				topMsgDiv.appendChild(temp);
				var space = document.createElement("span");
				space.style.position = "relative";
				space.style.marginLeft = "150px";
				topMsgDiv.appendChild(space);
				
				i++;
			}
			
			contained.appendChild(topMsgDiv);
			document.getElementById('map_map_int').appendChild(contained);
			
			updateTopMsg();

			isPlaying = true;
		}
	}
	
	this.stop = function()
	{
		if( isPlaying == true )
		{
			removeAllNodes( contained, true );
			isPlaying = false;
		}
	}
}