// when the DOM is ready...
$(document).ready(function () {
  // load the ticker
   jQuery.ajax(
             {
                 type:"post",
                 url:"GetServerTime.aspx",
                 data:"abc=abc",
                 success: function(msg){
                                       document.getElementById('ticker-area').innerHTML = msg;
                                       createTicker();                                 
                             }
     })

	

}); 

function createTicker(){
	// put all list elements within #ticker-area into array
	var tickerLIs = $("#ticker-area ul").children();
	tickerItems = new Array();
	tickerLIs.each(function(el) {
		tickerItems.push( jQuery(this).html() );
	});
	i = 0
	rotateTicker();
}

function rotateTicker(){
	if( i == tickerItems.length ){
	  i = 0;
	}
  tickerText = tickerItems[i];
	c = 0;
	typetext();
	setTimeout( "rotateTicker()", 10000 );
	i++;
}

var isInTag = false;
function typetext() {	
	var thisChar = tickerText.substr(c, 1);
	if( thisChar == '<' ){ isInTag = true; }
	if( thisChar == '>' ){ isInTag = false; }
	$('#ticker-area').html("&nbsp;" + tickerText.substr(0, c++));
	if(c < tickerText.length+1)
		if( isInTag ){
			typetext();
		}else{
			setTimeout("typetext()", 150);
		}
	else {
		c = 1;
		tickerText = "";
	}	
}

$(function () {
  
// load the ticker
   jQuery.ajax(
             {
                 type:"post",
                 url:"GetServerTime.aspx",
                 data:"title=title",
                 success: function(msg){
                                       document.getElementById('title-area').innerHTML = msg;
                                       createTitle();                                 
                             }
     })

	

}); 

function createTitle(){
	// put all list elements within #title-area into array
	var titleLIs = $("#title-area ul").children();
	titleItems = new Array();
	titleLIs.each(function(e2) {
		titleItems.push( jQuery(this).html() );
	});
	j = 0
	rotateTitle();
}

function rotateTitle(){
	if( j == titleItems.length ){
	  j = 0;
	}
  titleText = titleItems[j];
	d = 0;
	typetitletext();
	setTimeout( "rotateTitle()", 10000 );
	j++;
}

var isInTags = false;
function typetitletext() {	
	var thistitleChar = titleText.substr(d, 1);
	if( thistitleChar == '<' ){ isInTags = true; }
	if( thistitleChar == '>' ){ isInTags = false; }
	document.title=titleText.substr(0, d++);
	if(d < titleText.length+1)
		if( isInTags ){
			typetitletext();
		}else{
			setTimeout("typetitletext()", 150);
		}
	else {
		d = 1;
		titleText = "";
	}	
}
