////////////////////////////////////////////////////////////////////////////////
// SCRIPT NAME: Scrolling News 2.2                                            //
//   COPYRIGHT: ©2003-2004 Matthew J. Drollinger                              //
//              Strong Interactive Media, Inc. - www.strongim.com             //
// DESCRIPTION: This script will create scrolling messages witnin a defined   //
//              area.  The message color and style, message spacing, scroll   //
//              speed, scroller dimensions, scroll direction (horizontal or   //
//              vertical), and scroller background color can be adjusted.     //
//              Each message can be given a specific URL, target window, and  //
//              message.  Scrolling stops when a cursor is over the scroller. //
//              This script works on Netscape 6+ and IE 5+ browsers.          //
//              Unsupported browsers will not display anything.               //
//       USAGE: This script is free to use in any non-commercial application. //
//              My requirement is that you retain this comment block and      //
//              specify any changes to the code using code comments.          //
//              For commercial use contact Strong Interactive Media.          //
////////////////////////////////////////////////////////////////////////////////

// BUILD THE SCROLLER
function createScrollerElement()
{
   if(document.getElementById)
   {
      var scrlrbgcolorcss = "";
      if(scrollerbgcolor != "")
         scrlrbgcolorcss = " background-color:" + scrollerbgcolor + ";";

      if(scrollertextalign != "center")
         scrollertextalign = "left";

      var scrollercode = "<STYLE TYPE=\"text/css\">\n"
       + "<!--\n"
       + "       .scrlr{" + scrollerregtextstyle + "}\n"
       + "      A.scrlr{" + scrollerlinkoffstyle + "}\n"
       + "A:hover.scrlr{" + scrollerlinkovrstyle + "}\n"
       + "\/\/-->\n"
       + "</STYLE>\n"
       + "<TABLE WIDTH=\"" + scrollerwidth + "\" HEIGHT=\"" + scrollerheight + "\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">\n"
       + "<TR>\n"
       + "	<TD>\n";

      if(scrollerdirection == "horizontal")
      {
         scrollerspeed *= 2;
         scrollercode += "		<DIV ID=\"containerdiv\" STYLE=\"position:relative; width:" + scrollerwidth + "px; height:" + scrollerheight + "px;" + scrlrbgcolorcss + " overflow:hidden;\" onMouseOver=\"scroller_isStopped=1\" onMouseOut=\"scroller_isStopped=0\">\n"
          + "			<DIV ID=\"scrollerdiv\" STYLE=\"position:relative; height:" + eval(scrollerheight-(2*scrollergutter)) + "px; top:" + scrollergutter + "px; left:" + scrollerwidth + "px;\">\n"
          + "				<TABLE HEIGHT=\"" + eval(scrollerheight-(2*scrollergutter)) + "\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\"><TR><TD VALIGN=\"center\" NOWRAP><FONT CLASS=\"scrlr\">\n";
      }
      else
      {
         scrollercode += "		<DIV ID=\"containerdiv\" STYLE=\"position:relative; width:" + scrollerwidth + "px; height:" + scrollerheight + "px;" + scrlrbgcolorcss + " overflow:hidden;\" onMouseOver=\"scroller_isStopped=1\" onMouseOut=\"scroller_isStopped=0\">\n"
          + "			<DIV ID=\"scrollerdiv\" STYLE=\"position:relative; width:" + eval(scrollerwidth-(2*scrollergutter)) + "px; top:" + scrollerheight + "px; left:" + scrollergutter + "px;\">\n"
          + "				<TABLE WIDTH=\"" + eval(scrollerwidth-(2*scrollergutter)) + "\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\"><TR><TD ALIGN=\"" + scrollertextalign + "\"><FONT CLASS=\"scrlr\">\n";
      }

      for(i=0;i<newsMessage.length;i++)
      {
         var newsurl    = newsMessage[i][0];
         var newstarget = newsMessage[i][1];
         var newstext   = newsMessage[i][2];

         if(newstarget == "")
            newstarget = defaultlinktarget;

         var nl_pretag = "";
         var nl_posttag = "";

         if(newsurl != "")
         {
            nl_pretag = "<A HREF=\"" + newsurl + "\" onFocus=\"blur()\" TARGET=\"" + newstarget + "\" CLASS=\"scrlr\">";
            nl_posttag = "</A>";
         }

         if(scrollerdirection == "horizontal")
         {
            scrollercode += nl_pretag + newstext + nl_posttag;
            if(i < newsMessage.length-1)
               scrollercode += "<IMG SRC=\"" + transparentgifsrc + "\" WIDTH=\"" + messagespacing + "\" HEIGHT=\"1\" BORDER=\"0\" ALT=\"\">";
         }
         else
         {
            scrollercode += "		" + nl_pretag + newstext + nl_posttag + "<BR>";
            if(i < newsMessage.length-1)
               scrollercode += "<IMG SRC=\"" + transparentgifsrc + "\" WIDTH=\"1\" HEIGHT=\"" + messagespacing + "\" BORDER=\"0\" ALT=\"\"><BR>\n";
         }
      }

      scrollercode += "</FONT></TD></TR></TABLE>\n"
       + "			</DIV>\n"
       + "		</DIV>\n"
       + "	</TD>\n"
       + "</TR>\n"
       + "</TABLE>\n";

      document.write(scrollercode);
   }
}

// MAKE THE SCROLLER MESSAGES MOVE
var scroller_isStopped = 0;
function scrollIt()
{
   if(document.getElementById)
   {
      if(!scroller_isStopped)
      {
         if(scrollerdirection == "horizontal")
         {
            if(parseInt(document.getElementById("scrollerdiv").style.left + scrollerwidth) >= -document.getElementById("scrollerdiv").scrollWidth)
               document.getElementById("scrollerdiv").style.left = eval(parseInt(document.getElementById("scrollerdiv").style.left)-1) + "px";
            else
               document.getElementById("scrollerdiv").style.left = scrollerwidth + "px";
         }
         else
         {
            if(parseInt(document.getElementById("scrollerdiv").style.top + scrollerheight) >= -document.getElementById("scrollerdiv").scrollHeight)
               document.getElementById("scrollerdiv").style.top = eval(parseInt(document.getElementById("scrollerdiv").style.top)-1) + "px";
            else
               document.getElementById("scrollerdiv").style.top = scrollerheight + "px";
         }
      }
      setTimeout("scrollIt()",150/scrollerspeed);
   }
}

// CREATE AND START THE SCROLLER
createScrollerElement();
scrollIt();