
function jt_AjaxVuPg() {
	this.showTitle=function(title) {
		var newBox = false;
		if (!this.box) {
			jt_DialogBox.imagePath = "/PC-NG-AA/images/";
			this.box = new jt_DialogBox(false);
			this.box.getContentNode().className = "pgView";
			this.newBox = true;
		}
		this.box.setTitle(title);
	}
	
				
	this.showContent=function(content) {
		var newBox = false;
		if (!this.box) {
			jt_DialogBox.imagePath = "/PC-NG-AA/images/";
			this.box = new jt_DialogBox(false);
			this.box.getContentNode().className = "pgView";
			this.newBox = true;
		}
		this.box.setContent(content);
		this.box.show();
		if (this.newBox) {
			this.box.moveTo(-1, -1);
			this.newBox = false;
		}
	}		
}

var newsFlashDlg=new jt_AjaxVuPg();
var newsFlashCache=new Object();
var thisNewsDisplayedAt=0;
function showNewsFlashInBanner(newsFlashId){
	if(!document.getElementById('nexi_news_banner_title'))
		return;
	if(newsFlashCache[newsFlashId]){
		showNewsFlashAndTxt(newsFlashId, newsFlashCache[newsFlashId]);
		return;
	}
		document.getElementById('nexi_news_banner_title').innerHTML="Loading nexi news";
		var ajaxHelper=new SimpleAjaxHelper('/PC-NG-AA/misc/index.do?action=getNewsTitle&newsFlashTrackingId='+newsFlashId);
		ajaxHelper.get("", true, new function(){
			this.onSuccess=function(req){
				showNewsFlashAndTxt(newsFlashId, req.responseText);
				newsFlashCache[newsFlashId]=req.responseText;
			}
			this.onFailure=function(){};
		});
}

function showNewsFlashAndTxt(newsFlashId, txt){
	if(txt!=''){
		document.getElementById("nexi_news_banner").style.display="block";
		document.getElementById('nexi_news_banner_title').current_news_id=newsFlashId;
		
		document.getElementById('nexi_news_banner_title').innerHTML=txt.trim();
		
		thisNewsDisplayedAt=(new Date()).getTime();
	}
	else{
		document.getElementById('nexi_news_banner_title').innerHTML="hmm, running out of stuff to tell you";
		setTimeout("document.getElementById('nexi_news_banner').style.display='none';", 2000);		
		thisNewsDisplayedAt=0;			
	}
}

function showNexiNews(){
	if(isDebugJS()){
		return;
	}
	var ajaxHelper=new SimpleAjaxHelper('/PC-NG-AA/misc/index.do?action=nexiNewsId&newsFlashTrackingId='+document.getElementById('nexi_news_banner_title').current_news_id);
	ajaxHelper.get("", true, new function(){
		this.onSuccess=function(req){
			if(req.responseText!=''){
				showNewsFlashInBanner(req.responseText);
			}
		};
		this.onFailure=function(){};
	});
}

function showPrevNews(){
	var ajaxHelper=new SimpleAjaxHelper('/PC-NG-AA/misc/index.do?action=prevNewsId&newsFlashTrackingId='+document.getElementById('nexi_news_banner_title').current_news_id);
	ajaxHelper.get("", true, new function(){
		this.onSuccess=function(req){
			if(req.responseText!='')
				showNewsFlashInBanner(req.responseText);
		};
		this.onFailure=function(){};
	});
}

function showNewsFlash(newsFlashId, uponFinishFunc){
		
		var ajaxHelper=new SimpleAjaxHelper('/PC-NG-AA/misc/index.do?action=getNewsTitle&newsFlashTrackingId='+newsFlashId);
		ajaxHelper.get("", true, new function(){
			this.onSuccess=function(req){
				newsFlashDlg.showTitle("Nexi New Flash: "+req.responseText);
			};
			this.onFailure=function(){};
		});
		
		var ajaxHelper=new SimpleAjaxHelper('/PC-NG-AA/misc/index.do?action=getNewsBody&newsFlashTrackingId='+newsFlashId);
		ajaxHelper.get("", true, new function(){
			this.onSuccess=function(req){
				newsFlashDlg.showContent(req.responseText);
				if(uponFinishFunc){
					uponFinishFunc();
				}
			};
			this.onFailure=function(){};
		});
}