<!--
//typing speed in ticket
var typingEffectTimeout = 100;
//wait after every news flash is typed
var newsFlashTimeout     = 5000;
//get new news flash timeout request timeout in milliseconds
var getNewNewsFlashTimeout = 150000;
//list of news flash to be shown in ticker
var NEWS_FLASH_ARRAY = new Array();
//total number of news flash for ticker
var totalNewsFlashToDisplay = 0;
//currently displayed news flash
var currentNewsFlash = -1;
//current news flash character length
var currentNewsFlashLength = 0;
//we want to call the ticker function just once from
//newNewsFlashCallback function, from that point onwards
//it will be automatically called with setTimeout function
var callDisplayNewsFlash = true;
//div object where ticker will be displayed
var newsFlashDisplayDivObject = $("newsFlashTickerAnchor");
//setTimeout variable for displayNewsFlash
var displayNewsFlashTimeout;
// pause the news flash ticker when user hover it.
var PAUSE_NF_TICKER = false;
// number of news flashes to be displayed
var MAX_NUMBER_OF_NEWS_FLASHES = 20;
//call displayNewsFlash after this much time
var newsFlashDisplayTimeout;
/**
 * display news flash function
 */
function displayNewsFlash(){
	// Call up the next cycle of the ticker
	if (PAUSE_NF_TICKER && newsFlashDisplayTimeout==newsFlashTimeout) {
		clearTimeout(displayNewsFlashTimeout);
		return;
	}
	//get the new news flash details
	try {
		if(currentNewsFlashLength == 0) {
			currentNewsFlash  = ((currentNewsFlash==totalNewsFlashToDisplay) ? 0 : ++currentNewsFlash);
			newsFlashTitle = NEWS_FLASH_ARRAY[currentNewsFlash]["news_flash_title"].replace(/&quot;/g, '"');
			storyLink = NEWS_FLASH_ARRAY[currentNewsFlash]["news_flash_link"];
			//show authors name
			$('newsFlashTickerAuthorAnchor').style.display = "none";
			newsFlashDisplayDivObject.href = storyLink;
		}
		//rewrite the news flash title, increasing one character a time.
		newsFlashDisplayDivObject.innerHTML = " " + newsFlashTitle.substring(0,currentNewsFlashLength) + ((currentNewsFlashLength == newsFlashTitle.length) ? "" : ((currentNewsFlashLength % 2) == 1 ? "_" : "-"));
		if (currentNewsFlashLength != newsFlashTitle.length) {
			//set the timeout for current news flash
			currentNewsFlashLength++;
			newsFlashDisplayTimeout = typingEffectTimeout;
		} else {
			//show authors name
			try {
				$('newsFlashTickerAuthorAnchor').href = "/" + NEWS_FLASH_ARRAY[currentNewsFlash]["news_flash_added_by"];
				$('newsFlashTickerAuthorAnchor').innerHTML = " - " + (newsFlashTitle.length > 69 ? NEWS_FLASH_ARRAY[currentNewsFlash]["news_flash_added_by"].truncate(15, '..') : NEWS_FLASH_ARRAY[currentNewsFlash]["news_flash_added_by"]);
				$('newsFlashTickerAuthorAnchor').style.display = "block";
			}catch(e){}
			//set the timeout for next news flash
			currentNewsFlashLength = 0;
			newsFlashDisplayTimeout = newsFlashTimeout;
		}
	} catch(e){}
	// Call up the next cycle of the ticker
	if (!PAUSE_NF_TICKER || newsFlashDisplayTimeout==typingEffectTimeout) {
		clearTimeout(displayNewsFlashTimeout);
		displayNewsFlashTimeout = setTimeout("displayNewsFlash()", newsFlashDisplayTimeout);
	}
}
/**
 * Fetch news flash
 */
function newNewsFlash(){
	var postParameters = "count="+MAX_NUMBER_OF_NEWS_FLASHES;
	//display the loading icon
	var ajaxRequestOptions = {
		// Use POST
		method: 'post',
		// Send this lovely data
		postBody: postParameters,
		// Handle successful response
		onSuccess: function (response) {newNewsFlashCallback(response);},
		// Handle 404
		on404: newNewsFlash404Callback,
		// Handle other errors
		onFailure: newNewsFlashFailureCallback
	}
	// Data store model
	new Ajax.Request('/latest-news-flash', ajaxRequestOptions);
}
/**
 * Fetch news flash callback
 */
var newNewsFlashCallback = function (response){
	//eval the json object
	response_data = eval('(' + response.responseText + ')');
	var error = response_data.error;
	var newsFlashInfo = response_data.news_flash_info;
	if (error == 1) {
		return false;
	} else {
		NEWS_FLASH_ARRAY = new Array();
		//populate the array of news flash
		for (i = 0; i < newsFlashInfo.length; i++) {
			NEWS_FLASH_ARRAY[i] = newsFlashInfo[i];
		}
		//total news flash to be displayed
		totalNewsFlashToDisplay = NEWS_FLASH_ARRAY.length;
		//call displayNewsFlash only one time
		if (callDisplayNewsFlash==true && totalNewsFlashToDisplay > 0) {
			displayNewsFlash();
			callDisplayNewsFlash = false;
		}
	}
}
/**
 * Fetch news flash 404 callback
 */
var newNewsFlash404Callback = function(){}
/**
 * Fetch news flash faliure callback
 */
var newNewsFlashFailureCallback = function(){}
//fetch news flash at a specific time period
//var TIME_INTERVAL_FOR_NES_FLASH_REQUEST = setInterval("newNewsFlash()", getNewNewsFlashTimeout);
//fetch news flash in real time for the first time
newNewsFlash();
// -->