// --- Global variable stuff here

       var theItemCount;

       var theCurrentStory;

       var theCurrentLength;

       var theStorySummary;

       var theTargetLink;

       var theCharacterTimeout;

       var theStoryTimeout;

       var theBrowserVersion;

       var theWidgetOne;

	   var theWidgetTwo;

	   var theWidgetThree;

       var theWidgetFour;

       var theSpaceFiller;

       var theLeadString;

       var theStoryState;





// --- Check for old browser and force applet

       theBrowserVersion = parseInt(navigator.appVersion);



       if (theBrowserVersion < 4)

       {

          location.href = "http://www.cts.com.tw";

       }







// --- Only run for V4 browsers (check browser again here - some old browsers won't do this inline)

       function startTicker()

       {

// ------ Play Video
	try {
		PlayNewsVideo();
	}
	catch (ex) {}
	try {
		PlayVodsVideo();
	}
	catch (ex) {}

          return;

          theBrowserVersion = parseInt(navigator.appVersion);



          if (theBrowserVersion < 4)

          {

             location.href = "http://www.cts.com.tw";

             return;

          }







// ------ Check and fixup incoming data block

          if(!document.body.children.incoming.children.properties)

          {

             document.all.incoming.innerHTML = "<DIV ID=\"properties\"><DIV ID=\"itemcount\">1</DIV></DIV><DIV ID=\"stories\"><DIV ID=\"1\"><DIV ID=\"Summary\">Copy Right By CTS COM</DIV><DIV ID=\"SiteLink\">/index.htm</DIV><DIV ID=\"UrlLink\"></DIV></DIV></DIV>";

          }





// ------ Set up initial values

          theCharacterTimeout = 50;

          theStoryTimeout     = 5000;

          theWidgetOne        =  "|";

          theWidgetTwo        =  "/";

		  theWidgetThree        =  "-";

		  theWidgetFour        =  "\\";







// ------ Set up initial values

          theStoryState       = 1;

          theItemCount        = document.body.children.incoming.children.properties.children.itemcount.innerText;

          theCurrentStory     = 0;

          theCurrentLength    = 0;

          theLeadString       = " ";

          theSpaceFiller      = " ";





// ------ Begin the ticker       

          runTheTicker();

       }


// --- The basic rotate function

       function runTheTicker()

       {

          if(theStoryState == 1)

          {

             setupNextStory();

          }



          if(theCurrentLength != theStorySummary.length)

          {

             drawStory();

          }

          else

          {

             closeOutStory();

          }

       }







// --- Index to next story

       function setupNextStory()

       {

          theStoryState = 0;



          theCurrentStory++;



          theCurrentStory = theCurrentStory % theItemCount;

          

          theStorySummary = document.body.children.incoming.children.stories.children[theCurrentStory].children.Summary.innerText;



          theTargetLink   = document.body.children.incoming.children.stories.children[theCurrentStory].children.SiteLink.innerText;



          if(theTargetLink == "")

          {

             theTargetLink = document.body.children.incoming.children.stories.children[theCurrentStory].children.UrlLink.innerText;

          }

   

          theCurrentLength = 0;



          document.all.hottext.href = theTargetLink;

       }







// --- Draw a teletype line

       function drawStory()

       {

          var myWidget;

          

          if((theCurrentLength % 4) == 1)

          {

             myWidget = theWidgetOne;

          }

          else

          {

             if ((theCurrentLength % 4) == 2)
             {
				 myWidget = theWidgetTwo;
             }
			 else
				 {
			      if ((theCurrentLength % 4) == 3)
					 {
				      myWidget = theWidgetThree;
					 }
				  else
					 {
				      myWidget = theWidgetFour;
					 }
				 }
			 }

          
          document.all.hottext.innerHTML = theLeadString + theStorySummary.substring(0,theCurrentLength) + myWidget + theSpaceFiller;

          theCurrentLength++;

          setTimeout("runTheTicker()", theCharacterTimeout);

       }







// --- Finalise the item

       function closeOutStory()

       {

          document.all.hottext.innerHTML = theLeadString + theStorySummary + theSpaceFiller;

          theStoryState = 1;

          setTimeout("runTheTicker()", theStoryTimeout);

       }
