var splitter = "5bd713552b1db9d703aa2e2963cc3733"
var jahl_timer = null
if (jahl_autoroll) jahl_timer = setTimeout(jahlAutoRoll, jahl_delaytime*1000);
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		} catch (E) {
			xmlhttp=false
		}
	}
@else
	xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false
	}
}

function myXMLHttpRequest() {
	var xmlhttplocal;
	try {
		xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
		} catch (E) {
			xmlhttplocal=false;
		}
	}

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
		try {
			var xmlhttplocal = new XMLHttpRequest();
		} catch (e) {
			var xmlhttplocal=false;
			alert('couldn\'t create xmlhttp object');
		}
	}

	return(xmlhttplocal);
}

function jahlShowNews(news, total) {
	if (xmlhttp.readyState != 0 && xmlhttp.readyState != 4) return;
	xmlhttp.open('get', jahl_livesite + '/modules/ja_news/headlineloader.php?news=' + news + '&total=' + total + '&anticache=' + Math.random());
	xmlhttp.onreadystatechange = handleHeadlineResponse;
	xmlhttp.send(null);
	document.getElementById("loading-indicator").style.display = "block";
	jahl_current = news;
	clearTimeout(jahl_timer);
}

function handleHeadlineResponse() {
	if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
			var response = xmlhttp.responseText;
			jahlChangeText(response);
		}
	}
}

var jahl_div2show = "jahl-newsitem"
var jahl_ani
var jahl_text
function jahlInit() {
	jahl_ani = new fx.Style(jahl_div2show, 'opacity', {duration: 300})
}
window.addEvent( 'load', jahlInit )

function jahlShowComingNews() {
	if (jahl_ani.timer) {
		setTimeout(jahlShowComingNews, 20)
		return
	}
	
	update = new Array();
	update = jahl_text.split(splitter);
	
	$(jahl_div2show).innerHTML = update[0];
	jahl_ani.custom(0,1);
	$("loading-indicator").style.display = "none";
	$("jahl-indicator").innerHTML = "" + jahl_current + "/" + jahl_total;
	$("jahl-next").title = "Next: " + update[1];
	$("jahl-prev").title = "Previous: " + update[2];
	if (jahl_autoroll) jahl_timer = setTimeout(jahlAutoRoll, jahl_delaytime*1000);
}

function jahlChangeText( text ) {
	// Detect Browser
	var IE = (document.all) ? 1 : 0;
	var DOM = 0;
	if (parseInt(navigator.appVersion) >=5) {DOM=1};
	// Grab the content from the requested "div" and show it in the "container"
	jahl_ani.custom(1,0);
	jahl_text = text;
	jahlShowComingNews();
}

function jahlSwitchRoll () {
	switcher = document.getElementById("jahl-switcher");
	if (jahl_autoroll) {
		switcher.src = jahl_livesite + "/modules/ja_news/play.png"
		switcher.alt = "Play"
		switcher.title = "Play"
		jahl_autoroll = false;
		clearTimeout(jahl_timer);
	} else {
		switcher.src = jahl_livesite + "/modules/ja_news/pause.png"
		switcher.alt = "Pause"
		switcher.title = "Pause"
		jahl_autoroll = true;
		jahl_timer = setTimeout(jahlAutoRoll, jahl_delaytime*1000);
	}
	
	createCookie("JAHL-AUTOROLL", jahl_autoroll ? 1 : 0, 0);
}

function jahlAutoRoll() {
	if (jahl_current == jahl_total) next = 1;
	else next = jahl_current+1;
	
	jahlShowNews(next, jahl_total);
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}