/*<!--[CDATA[*/

/*--------------------------------------------------------------------------------*/
// Thang Nguyen 2005 -- All rights reserved.
/*--------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------*/
/* Ki-a News for NTKS                                        */
/*--------------------------------------------------------------------------------*/

var timeOutForTyping; 
var lineIndex = 0; 
var charIndex = 0; 
var clearContent = true; 
var textLines = new Array (); 
var theLayer = null;	// where text is typed to
var speed = 100;		// typing speed
var pause = 3000;		// pause between lines

 
 
function InitKiaNews(theLayerId)
{
	textLines = new Array (		
		//"The Toronto 2006 Tournament of Martial Arts Champions will be held in November.",
		"Calendar of Events for February 2010 has been posted.",
		"Start your karate training today in a friendly and positive work-out atmosphere.",
		"Visit different convenient class locations of N.T.K.S.",
		"E-mail your friends about the news from N.T.K.S's Web site.",
		"Check out flexible schedules and classes offered by N.T.K.S."
	   // "Post your message, comment on N.T.K.S  Guest Book..."
	);
	
	theLayer = document.getElementById(theLayerId);
	if (theLayer)
	{
		theLayer.title = "Go to this page";
		TypeText();
	}
}

function goToNewsPage (news)
{
	// current page - default;
	var url = window.location.href;
	var newWin = false;

	// Base on the FIRST CHAR of the in the news textline
	// redirect the user to the news page.
	if(news.indexOf('C') == 0) {
		url = "http://www.northtorontokarate.com/docs/Calendar_of_events_Feb_2010.doc";
		newWin = true;
	}
	else if(news.indexOf('T') == 0)
		url = "http://www.northtorontokarate.com/tourney2006.htm";	
	else if (news.indexOf('S') == 0)
		url = "http://www.northtorontokarate.com/gettingstarted.htm";
	else if (news.indexOf('V') == 0)
		url = "http://www.northtorontokarate.com/locations.htm";
	else if (news.indexOf('E') == 0)
		url = "http://www.northtorontokarate.com/tellfriend.php";
	else if (news.indexOf('C') == 0)
		url = "http://www.northtorontokarate.com/schedule.htm";
	else if (news.indexOf('P') == 0)
		url = "http://www.northtorontokarate.com/gb/index.php";
	

	if (newWin)
	{
		window.open(url, "nw");
	}
	else {
		window.location = url;
	}
}


function TypeText() 
{ 
	if (clearContent == true) 
	{ 
		theLayer.innerHTML = ""; 
	} 

	if (lineIndex >= textLines.length -1  &&  (charIndex >= textLines[lineIndex].length)) 
	{ 
		clearContent = true; 
		lineIndex = 0; 
		charIndex = 0;  
		timeOutForTyping = setTimeout("TypeText()", speed);
	   // clearTimeout(timeOutForTyping); 
	} 
	else 
	{ 
	   clearContent = false; 
	   //var currentSpeed = speed;
	   var isPaused = false;
	  
	   if(charIndex == textLines[lineIndex].length-1)
	   {
			isPaused = true;
	   }
	   else if (charIndex >= textLines[lineIndex].length) 
	   {      
		   
		   //theLayer.innerHTML += "<br>"; 
		   theLayer.innerHTML = ""; 
		   lineIndex++; 
		   charIndex = 0;        			   
	   }     
		
	   var s = theLayer.innerHTML;
	   var len = s.length;
		
	   if(s.lastIndexOf('_') == (len-1)) len--; // trip off the last char which is the underscore (_)
	
	   theLayer.innerHTML = s.substr(0, len) + textLines[lineIndex].charAt(charIndex) + "_"; 

	   charIndex++; 
	   timeOutForTyping = setTimeout("TypeText()", (isPaused) ? pause : speed); 
	} 
} 


/*// ]]-->*/
