function Message(msg,timedelay)
{
 this.msg=msg;
 this.timedelay=timedelay;
 this.height=0;
}

function VNewsTicker(name,variable_name,yPos,xPos,view_width,view_height,messages,default_timedelay,pixel_trans_img,step,scroll_speed,bgcolor)
{
 this.settime_id=0;
 this.variable_name=variable_name;
 this.name=name;
 this.xPos=xPos;
 this.yPos=yPos;
 this.vcount=0;
 this.view_width=view_width;
 this.view_height=view_height;
 this.messages=messages;
 this.default_timedelay=default_timedelay;
 this.pixel_trans_img=pixel_trans_img;
 this.bgcolor=bgcolor;
 if (this.bgcolor=="")
 	this.bgcolor="red";
 this.step=step;
 this.message_number=0;
 this.scroll_speed=scroll_speed;
 this.message_part=0;
 this.temp_count=0;
 
 if (this.messages.length<=0)
 	this.message_number=-1;
 
 this.getMessageHeight();
 this.setActiveMessage(this.message_number); 
}

VNewsTicker.prototype.doMove = function(newXPos,newYPos)
{
 this.doStop();
 this.doHide();
 this.xPos=newXPos;
 this.yPos=newYPos;
 //this.setActiveMessage(0);
 //this.setActiveMessage(this.message_number);
 this.doShow();
 this.doScroll();
}

VNewsTicker.prototype.getMessageHeight = function()
{
 var strContent="";
 
 for(var i=0;i<this.messages.length;i++)
 {
  strContent=this.getBlankArea()+this.getMessage(i)+this.getBlankArea();
  writeIntoLayer(this.name,strContent);
  this.messages[i].height=getLayerHeight(this.name);
 }
}

VNewsTicker.prototype.getBlankArea = function()
{
 var strBlankHtml= "<table bgcolor=\""+this.bgcolor+"\" cellspacing=0 cellpadding=0 border=0 width=\""+this.view_width+"\" height=\""+this.view_height+"\">\n"
     strBlankHtml+="<tr><td width=\""+this.view_width+"\" height=\""+this.view_height+"\"><img src=\""+this.pixel_trans_img+"\" width=\""+this.view_width+"\" height=\""+this.view_height+"\" border=0></td></tr>\n"
     strBlankHtml+="</table>\n";
                 
 return strBlankHtml;
}


VNewsTicker.prototype.getMessage = function(msg_number)
{
 var strMsgHtml="";
 
 if (msg_number!=-1)
     strMsgHtml= "<table bgcolor=\""+this.bgcolor+"\" cellspacing=0 cellpadding=0 border=0 width=\""+this.view_width+"\">\n"
     strMsgHtml+="<tr><td width=\""+this.view_width+"\" height=\""+this.view_height+"\" align=left valign=middle>"+this.messages[msg_number].msg+"</td></tr>\n"
     strMsgHtml+="</table>\n";
                 
 return strMsgHtml;
}

VNewsTicker.prototype.setActiveMessage = function(msg_number)
{
 if (msg_number==-1)
 {
  strContent=this.getBlankArea();
 }
 else
 {
  this.message_number=msg_number;
  this.vcount=0;
  this.temp_count=0;
  strContent=this.getBlankArea()+this.getMessage(this.message_number)+this.getBlankArea();
 }
 
 set_layer_position(this.name,this.xPos,this.yPos);
 set_clip_area(this.name,0,this.view_width,this.view_height,0);
 writeIntoLayer(this.name,strContent);	
}

VNewsTicker.prototype.doScroll = function()
{
 var time_delay;

 if (this.message_number!=-1)
 { 
  if ((this.vcount+this.step)>(this.messages[this.message_number].height-this.view_height))
 	this.vcount=this.messages[this.message_number].height-this.view_height;
  else
  {
 	this.vcount+=this.step;
  }

  this.temp_count+=this.step;

  set_layer_position(this.name,this.xPos,this.yPos-this.vcount);
  set_clip_area(this.name,0,this.view_width,this.view_height,this.vcount);

  
  if ((this.view_height<=this.vcount) && (this.vcount<=(this.messages[this.message_number].height-this.view_height)))
  {
   if (this.vcount==(this.messages[this.message_number].height-this.view_height))
 	this.setActiveMessage((this.message_number+1) % this.messages.length);
  
   if (this.temp_count<this.view_height)
	time_delay=this.scroll_speed;
   else
   {
    this.temp_count=0;
    if (this.messages[this.message_number].timedelay>-1)
        time_delay=this.messages[this.message_number].timedelay;
    else
        time_delay=this.default_timedelay;
   }
  }
  else
	time_delay=this.scroll_speed;

  this.settime_id=setTimeout(this.variable_name+".doScroll()",time_delay);
 }
}

VNewsTicker.prototype.doStop = function()
{
  clearTimeout(this.settime_id);
}

// versteck Textbrowser
VNewsTicker.prototype.doHide = function()
{
 hide_layer(this.name);
}

// zeigt Textbrowser
VNewsTicker.prototype.doShow = function()
{
 show_layer(this.name);
}
