//================================= CLASS CONSTRUCTOR ========================================
function MsgSlider(idocument,ioffset)
{
//MEMBER VARIABLES
 this.document = idocument;
 this.offset = ioffset;
 this.cParentDiv = null;
 this.cTextDiv = null;
 this.positions = new Array();
 this.posId = 0;
 this.sliding = false;
 this.tmSlider = null;
 this.tmStay = null;
 thisobj = this;

 this.create();
 this.updatePositions();
 this.moveToPosId(MsgSlider.POSID_START);
}

//====================================== STATIC ==============================================
MsgSlider.WIDTH = 300;
MsgSlider.HEIGHT = 16;
MsgSlider.IMG_WIDTH = 16;
MsgSlider.IMG_HEIGHT = 16;
MsgSlider.TEXT_FONT = 'Verdana';
MsgSlider.TEXT_SIZE = 10;
MsgSlider.MOVE_DELAY = 10;
MsgSlider.MOVE_SPEED = 10;
MsgSlider.TIME_PAUSE = 5000;
MsgSlider.POSID_START = 0;
MsgSlider.POSID_MIDDLE = 1;
MsgSlider.POSID_END = 2;

//====================================== MEMBERS =============================================
MsgSlider.prototype.create = function()
{
 var
  cImgDiv1,cImgDiv2 = null,
  cImg = null;

 this.cTextDiv = this.document.createElement("<DIV>");
 this.cTextDiv.align = 'center';
 this.cTextDiv.style.position = 'absolute';
 this.cTextDiv.style.left = MsgSlider.IMG_WIDTH;
 this.cTextDiv.style.top = 0;
 this.cTextDiv.style.width = MsgSlider.WIDTH-(2*MsgSlider.IMG_WIDTH);
 this.cTextDiv.style.height = MsgSlider.HEIGHT;
 this.cTextDiv.style.overflow = 'hidden';
 this.cTextDiv.style.border = '1 solid white';
 this.cTextDiv.style.fontFamily = MsgSlider.TEXT_FONT;
 this.cTextDiv.style.fontSize = MsgSlider.TEXT_SIZE;
 this.cTextDiv.style.color = "white";

 cImg = this.document.createElement("<IMG>");
 cImg.src = "/adiJed/res/img/Common/sliderinfo.gif";
 cImg.tag = this;
 cImg.attachEvent('onmouseenter',this.onImgMouseEnter);

 cImgDiv1 = this.document.createElement("<DIV>");
 cImgDiv1.style.position = 'absolute';
 cImgDiv1.style.left = 0;
 cImgDiv1.style.top = 0;
 cImgDiv1.style.width = MsgSlider.IMG_WIDTH;
 cImgDiv1.style.height  = MsgSlider.IMG_HEIGHT;
 cImgDiv1.appendChild(cImg);

 cImgDiv2 = cImgDiv1.cloneNode(true);
 cImgDiv2.style.left = MsgSlider.WIDTH - MsgSlider.IMG_WIDTH;

 this.cParentDiv = this.document.createElement("<DIV>");
 this.cParentDiv.style.position = 'absolute';
 this.cParentDiv.style.left = 0;
 this.cParentDiv.style.top = this.offset;
 this.cParentDiv.style.width = MsgSlider.WIDTH;
 this.cParentDiv.style.height = MsgSlider.HEIGHT;
 this.cParentDiv.style.overflow = 'hidden';
 this.cParentDiv.appendChild(this.cTextDiv);
 this.cParentDiv.appendChild(cImgDiv1);
 this.cParentDiv.appendChild(cImgDiv2);

 this.document.body.appendChild(this.cParentDiv);
}

MsgSlider.prototype.updatePositions = function()
{
 this.positions[MsgSlider.POSID_START] = (-MsgSlider.WIDTH + MsgSlider.IMG_WIDTH);
 this.positions[MsgSlider.POSID_MIDDLE] = Math.floor((this.document.body.clientWidth-MsgSlider.WIDTH)/2);
 this.positions[MsgSlider.POSID_END] = this.document.body.clientWidth + MsgSlider.WIDTH;
}

MsgSlider.prototype.getPosByPosId = function(iposId)
{
 return this.positions[iposId];
}

MsgSlider.prototype.moveToPosId = function(iposId)
{
//Changing slider's position ...
 this.cParentDiv.style.pixelLeft = this.getPosByPosId(iposId);
 this.posId = iposId;
}

MsgSlider.prototype.getNextPosId = function()
{
 return (this.posId+1)%(this.positions.length);
}

MsgSlider.prototype.onPauseEnd = function()
{
 thisobj.onSlide();
}

MsgSlider.prototype.onPosIdArrive = function(iposId)
{
 switch (iposId)
 {
  case MsgSlider.POSID_MIDDLE:
   this.tmStay = setTimeout(this.onPauseEnd,MsgSlider.TIME_PAUSE);
   break;

  case MsgSlider.POSID_END:
//Moving the slider to start ...
   this.moveToPosId(MsgSlider.POSID_START);
   this.sliding = false;
   break;
 }
}

MsgSlider.prototype.onSlide = function()
{
 var
  posX = 0;
  nextPosId = 0;
  nextPos = 0;

 with (thisobj)
 {
  posX = cParentDiv.style.pixelLeft;
  nextPosId = getNextPosId();
  nextPos = getPosByPosId(nextPosId);
 //Sliding to the right once...
  if (posX + MsgSlider.MOVE_SPEED > nextPos)
  {
   moveToPosId(nextPosId);
   onPosIdArrive(nextPosId);
  }
  else
  {
   cParentDiv.style.pixelLeft = posX + MsgSlider.MOVE_SPEED;
   tmSlider = setTimeout(onSlide,MsgSlider.MOVE_DELAY);
  }
 }
}

MsgSlider.prototype.onImgMouseEnter = function()
{
 var
  thisobj = event.srcElement.tag;

 thisobj.slide();
}

MsgSlider.prototype.slide = function()
{
 if (this.sliding)
  return;
//Updating screen positions ...
 this.updatePositions();
//Now we're sliding ...
 this.sliding = true;
//Starting the slider ...
 this.tmSlider = setTimeout(this.onSlide,MsgSlider.MOVE_DELAY);
}

MsgSlider.prototype.setText = function(itext)
{
 this.cTextDiv.innerHTML = itext;
}

