var PInstanceCreatedNums=0;  
var PInstanceMaxCreateNums=100;  
function Marquee()
{
 var mStoptime=0;
 var offsetcount=0;
 var thisObj=this;
 var speed=0;   
 var parentdiv ="";  
 var maindiv = ""; 
 var copydiv = ""; 
 var speed = 0;   
 var direction = "";  
 var pauseDistance = 0; 
 var pauseTime = 0;  
 var startStatus =0; 
 var parentdivWidth=0; 
 var parentdivHeight=0;  
 PInstanceCreatedNums++;
 thisObj.start=function()
 {
  try
  {
   if(PInstanceCreatedNums>=PInstanceMaxCreateNums)
   {
    alert("max");
    return false;
   }
   with(thisObj)
   {
    parentdiv=document.getElementById(parentDiv);
    maindiv=document.getElementById(mainDiv);
    divCopy();
    if(parentdiv.style)
    {
     parentdiv.style.overflow='hidden';
     parentdiv.style.width=parentdivWidth;
     parentdiv.style.height=parentdivHeight;
    }
    parentdiv.onmouseover=Pause;
    parentdiv.onmouseout=Begin;
    switch(direction)
    {
    case "up":
     maindiv.style.display='block';
     copydiv.style.display='block';
     parentdiv.scrollTop=0;
     break;
    case "down":
     maindiv.style.display='block';
     copydiv.style.display='block';
     parentdiv.scrollTop=maindiv.offsetHeight*2-parentdivHeight;
     break;
    case "left":
     parentdiv.style.whiteSpace='nowrap';
     maindiv.style.display='inline';
     copydiv.style.display='inline';
     parentdiv.scrollLeft=0;
     break;
    case "right":
     parentdiv.style.whiteSpace='nowrap';
     maindiv.style.display='inline';
     copydiv.style.display='inline';
     parentdiv.scrollLeft=maindiv.offsetWidth*2-parentdivWidth;
     break;    
    }
    offsetcount=pauseDistance;
    Begin();
   }
  }
  catch(e)
  {
   alert('erro['+e.message+']');
  }
 }
 thisObj.divCopy=function()
 {
  with(thisObj)
  {
   copydiv=document.createElement("div");
   copydiv.id='copy'+maindiv.id;
   parentdiv.appendChild(copydiv);   
   copydiv.innerHTML=maindiv.innerHTML;
  }
 }
 thisObj.doPause=function()
 {
  mStoptime+=1;
  if(mStoptime==thisObj.pauseTime)
  {
   mStoptime=0;
   offsetcount=0;
   return true;
  }
  return false;
 }
 thisObj.iMarquee=function()
 {
  with(thisObj)
  { 
   switch(direction)
   {
   case "up":
    if(offsetcount>=pauseDistance)
    {
     if(parentdiv.scrollTop>=copydiv.offsetTop) 
     {
      if(doPause())
      {
       parentdiv.scrollTop-=maindiv.offsetHeight; 
      }
     }
     else
     {
      doPause();
     }
    }
    else
    {
     parentdiv.scrollTop++;
     offsetcount++;
    }   
    break;
   case "down":
    if(offsetcount>=pauseDistance) 
    {
     if(parentdiv.scrollTop<=maindiv.offsetHeight-parentdivHeight) 
     {
      if(doPause())
      {
       parentdiv.scrollTop=maindiv.offsetHeight*2-parentdivHeight;
      }
     }
     else
     {
      doPause();
     }
    }
    else
    {
     parentdiv.scrollTop--;
     offsetcount++;
    }   
    break;
   case "left":
    if(offsetcount>=pauseDistance)
    {
      
     if(parentdiv.scrollLeft>=copydiv.offsetWidth)
     {
      if(doPause())
      {
       parentdiv.scrollLeft-=maindiv.offsetWidth;
      }
      }
      else
      {
      doPause();
      }
     }
    else
    {
     parentdiv.scrollLeft++;
     offsetcount++;
    }
    break;
   case "right":
    if(offsetcount>=pauseDistance)
    {
     if(parentdiv.scrollLeft<=0)
     {
      if(doPause())
      {
       parentdiv.scrollLeft+=maindiv.offsetWidth;
      }     
      }
      else
      {
      doPause();
      }
     }
    else
    {
     parentdiv.scrollLeft--;
     offsetcount++;
    }   
    break;
   }
  }
 }
 thisObj.Begin=function() 
 {
  thisObj.timer=setInterval(thisObj.iMarquee,thisObj.speed);
 }
 thisObj.Pause=function()
 {
  clearInterval(thisObj.timer);
 }
}