var streamip = "services.lwbcast.com";
var stream;
var ol_width = "350";
var ol_textfont = "Times New Roman";
var ol_textsize = "2";
var ol_fgcolor = "#FFFFCC"; 
//var ol_fgbackground = "Pictures/lwbbk.jpg";
var lwbwebsite = "http://www.lwbcast.org";
var icecast_server = "http://services.lwbcast.org:9090/";
var baselink = lwbwebsite + "/churchservices/";
var popUpWin=1;
var serverdata = "";
var dataarr = new Array();
var maxloop = 30;
var loopnum = 0;
var currstreamnum = false;
var servertype = "shoutcast";
var clicktoplay = false;
var aimg,vimg;
if (typeof cClick == 'undefined') addjs(baselink + "overlib.js");
if (typeof streamnum == 'undefined') addjs (baselink + "streamdata.php?streamname="+ streamname);
if (!lwb) gdinterval = setInterval("getdata();", 30000);
function getdata() {
	loopnum = 0 ;
	addjs(baselink + "data.php?streamname=" + streamname,false);
	window.setTimeout(datawait,500);
	loop = setInterval(datawait, 1000);
}
function datawait() {
	if (loopnum > maxloop) {
		serverdata = "error"; 	clearInterval(loop) ;
		document.getElementById("nowplaying").innerHTML = "There was an error fetching the title. You must be connected to the internet";
		return;
	}
	if(serverdata == false && loopnum < maxloop) {
		loopnum++ ;
		return ;
	}
	clearInterval(loop) ;
	if (serverdata.match(/|/)) {
		dataarr = serverdata.split("|");
		aimg = document.getElementById("aimg");
		vimg = document.getElementById("vimg");
		if (dataarr[1] == "0") {
			vimg.className = "styledisable";
			vimg.src = baselink + "images/video_off.gif";
			vimg.onmouseover = function () { overlib("Live video streaming is not available at this time"); };
			vimg.onmouseout = function () { cClick(); };
			vimg.style.cursor = "";
			vimg.style.width = "32px";
			vimg.style.height = "32px";
			if (document.getElementById("vimg_play")) {
				document.getElementById("vimg_play").style.display = 'none';
			}
		} else {
			vimg.onmouseover = function () { mouseover("v"); };
			vimg.onmouseout = "";
			vimg.className = "";
			//vimg.src = baselink + "images/video_on.gif";
			vimg.src = baselink + "/church_images/" + streamname + ".png";
			vimg.style.width = "60px";
			vimg.style.height = "45px";
			if (!document.getElementById("vimg_play")) {
				var vimg_play = document.createElement("img");
				var vimg_pos = pageXY(vimg);
				vimg_play.id = "vimg_play";
				vimg_play.src = baselink + "/images/play_a.gif";
				vimg_play.width="20";
				vimg_play.height="20";
				document.body.appendChild(vimg_play);
				vimg_play.style.position = 'absolute';
				vimg_play.style.zIndex = 10;
				vimg_play.style.top = (vimg_pos.y + 12) + 'px';
				vimg_play.style.left = (vimg_pos.x + 23) + 'px';
				vimg_play.onmouseover = function () { mouseover("v"); };
				vimg_play.onclick = function () { vimg_play.onclick = vimg.onclick; };
			} else {
				document.getElementById("vimg_play").style.display='block';
			}
		}
		if (dataarr[2] == "0") {
			aimg.className = "styledisable";
			aimg.src = baselink + "images/audio_off.gif";
			aimg.onmouseover = function () { overlib("Live audio streaming is not available at this time"); };
			aimg.onmouseout = function () { cClick(); };
			aimg.style.cursor = "";
		} else {
			aimg.onmouseover = function () { mouseover("a"); };
			aimg.onmouseout = "";
			aimg.className = "";
			aimg.src = baselink + "images/audio_on.gif";
		}
		document.getElementById("nowplaying").innerHTML = dataarr[4];
			if (document.getElementById("titlediv")&&(typeof currstream != 'undefined')&&String(currstream).toLowerCase().indexOf('live'+streamname)!=-1) {
				document.getElementById('titlediv').innerHTML = "<div><div>" + dataarr[4] + "</div></div>"; doDMarquee();
			}
	} else {
		serverdata = "error";
		document.getElementById("nowplaying").innerHTML = "There was an error fetching the title. You must be connected to the internet";
	}
}
function mouseover(mode) {
	if (serverdata == "error") {
		overlib("There was an error while trying to fetch the status on the streams. Please make sure you are connected to the internet, and that you are using an updated browser.", STICKY, CSSSTYLE, CLOSESIZE, 9, CAPTIONSIZE, 9, TEXTSIZE, 13);
	} else if (dataarr.length != 5) {
		overlib("Fetching status...Please wait",STICKY, CSSSTYLE, CLOSESIZE, 9, CAPTIONSIZE, 9, TEXTSIZE, 13,CAPTION,"Status");
		window.setTimeout("mouseover('" + mode + "');", 2000);
	} else {
		if (mode == "a") {
			atunein(aimg);
		} else if (mode == "v") {
			vtunein(vimg);
		} else if (mode == "c_a") {
			cs_tunein_click('a');
		} else if (mode == "c_v") {
			cs_tunein_click('v');
		}
	}
}
function popUpWindow(URLStr, left, top, width, height) {
  popUpWin = open(URLStr, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no,scrollbar=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
function atunein (img) {
	if (dataarr[0] != 'icecast') {
		var streambase = ((streamnum-1) * 2);
		var streamport = "90" + (streambase < 10 ? "0" + streambase : streambase);
		if (dataarr[2] == "1") {
			var overlibstuff = "<font size=\"2\">Please select one of the players to tune in. (Winamp recommended)</font><br><a href=\"" + baselink + "tunein.lwb?type=pls&stream=" + escape(stream) + "\" onClick=\"return nd();\"><img src=\"" + baselink + "images/winamplogo.gif\" border=\"0\"></a><br>";
			if (window.ActiveXObject) {
				overlibstuff += "<a href=\"javascript:tunein('a','" + dataarr[3] + " - Live Audio Stream');\" onMouseOver=\"window.status='';\" onClick=\"nd();\"><img src=\"" + baselink + "images/nsvplugin.gif\" border=\"0\"></a><br>";
			}
		} else {
			var overlibstuff = "Live audio is not available at this time.";
		}
		overlibstuff += "<br><font size=\"2\">We strongly recommend that you use the latest FREE (full) version of <a href='http://www.winamp.com/player/free.php'>Winamp</a>, in order to obtain the best audio quality.</font>";
		overlibstuff += "<div align=\"center\"><font size=\"1\"><b>Courtesy of <a href=\"http://www.livingwordbroadcast.org\"><font color=\"006600\">Living Word Broadcast</font></a>.</b></font></div>";
		overlib(overlibstuff, STICKY, OFFSETX, -125,CSSSTYLE, CLOSESIZE, 9, CAPTIONSIZE, 9, TEXTSIZE, 13, CAPTION, 'Live Audio Stream<br><i>(Please select a player to continue)</i>');
	} else {
		if (dataarr[2] == "1") {
			clicktoplay = true;
			overlib("Click to begin streaming audio");
			img.onmouseout = function () { cClick(); };
			img.style.cursor = "pointer";
		}
	}
}
function vtunein (img) {
	if (dataarr[0] != 'icecast') {
		var streambase = ((streamnum-1) * 2);
		var streamport = "90" + (streambase < 10 ? "0" + streambase : streambase);
		stream = "http://" + streamip + ":" + streamport + "/;file.nsv";
		if (dataarr[1] == "1") {
			var overlibstuff = "<font size=\"2\">Please select one of the players to tune in. (Winamp recommended)</font><br><a href=\"" + baselink + "tunein.lwb?type=pls&stream=" + escape(stream) + "\" onClick=\"return nd();\"><img src=\"" + baselink + "images/winamplogo.gif\" border=\"0\"></a><br>";
			if (window.ActiveXObject) {
				overlibstuff += "<a href=\"javascript:tunein('v','" + dataarr[3] + " - Live Video Stream');\" onMouseOver=\"window.status='';\" onClick=\"nd();\"><img src=\"" + baselink + "images/nsvplugin.gif\" border=\"0\"></a><br>";
			}
		} else {
			var overlibstuff = "Live Video is not available at this time.";
		}
		overlibstuff += "<br><font size=\"2\">We strongly recommend that you use the latest FREE (full) version of <a href='http://www.winamp.com/player/free.php'>Winamp</a>, in order to obtain the best video and audio quality.</font>";
		overlibstuff += "<div align=\"center\"><font size=\"1\"><b>Courtesy of <a href=\"http://www.livingwordbroadcast.org\"><font color=\"006600\">Living Word Broadcast</font></a>.</b></font></div>";
		overlib(overlibstuff, STICKY, OFFSETX, -125, CSSSTYLE, CLOSESIZE, 9, CAPTIONSIZE, 9, TEXTSIZE, 13, CAPTION, 'Live Video Stream<br><i>(Please select a player to continue)</i>');
	// OFFSETX, -200, OFFSETY, -200, 
	} else {
		if (dataarr[1] == "1") {
			if (typeof navigator.userAgent != 'undefined' && (
			    (navigator.userAgent.match(/Firefox\//) && parseFloat(String(navigator.userAgent.match(/Firefox\/[\d.]+/)[0].substr(8).replace(".",""))) >= 35)/* || //Chrome doesn't support HTML5 OGG streaming yet
			     (navigator.userAgent.match(/Chrome\//) && parseFloat(String(navigator.userAgent.match(/Chrome\/[\d.]+/)[0].substr(7).replace(".",""))) >= 30) */ ) ) {
				if (parseFloat(String(navigator.userAgent.match(/Firefox\/[\d.]+/)[0].substr(8).replace(".",""))) >= 35) {
					clicktoplay = "HTML5";
					overlib("Click to begin streaming video");
					img.onmouseout = function () { cClick(); };
					img.style.cursor = "pointer";
				} else {
					overlib("<span style='font-size:12pt;'>Your browser version is outdated. Please upgrade to Firefox 3.5 (or newer) to watch this video stream.</span>",STICKY, OFFSETX, -125, CSSSTYLE, CLOSESIZE, 9, CAPTIONSIZE, 9, TEXTSIZE, 13, CAPTION, 'Live Video Stream');
				}
			} else {
				if (Plugin.isInstalled("Java")) {
					clicktoplay = "Java";
					overlib("Click to begin streaming video");
					img.onmouseout = function () { cClick(); };
					img.style.cursor = "pointer";
					if (document.getElementById("vimg_play")) document.getElementById("vimg_play").style.cursor = 'pointer';
				} else {
					overlib("<span style='font-size:12pt;'>You must have a Java plugin installed OR have Firefox 3.5 to view this video.<br><a href='http://www.getfirefox.com'>Download Firefox 3.5</a><br><br><a href='http://java.com/en/download/index.jsp'>Download Java</a></span>",STICKY, OFFSETX, -125, CSSSTYLE, CLOSESIZE, 9, CAPTIONSIZE, 9, TEXTSIZE, 13, CAPTION, 'Live Video Stream');
				}
			}
		}
	}
}
function cs_tunein_click(mode) {
	if (clicktoplay) {
		currstreamnum = streamnum;
		if (mode == 'v') {
			if (dataarr[1] == "1") {
				 lwbplay(icecast_server + "Live" + streamname.toUpperCase() + ".ogg",'ogg',(clicktoplay == "HTML5" ? 'html5' : 'cortado'));
			}
		} else if (mode == 'a') {
			if (dataarr[2] == "1") {
				lwbplay(icecast_server + "Live" + streamname.toUpperCase() + ".mp3",'mp3');
			}
		}
	}
}
function tunein (mode,name) {
	var playerlink = baselink + "browserplugin.php?stream=" + escape(stream) + "&browser=IE&mode=" + mode + "&type=pls&name=" + name;
	popUpWindow(playerlink, 20,10,(mode == "a") ? 350 : 400,(mode == "a") ? 40 : 350);
}
if (!lwb) addEvent(window,"load",getdata);
window.setTimeout("try { document.getElementById(\"nowplaying\").innerHTML = \"Fetching Title...\";} catch (e) {}", 300);
//if (!lwb)
addEvent(window,"load",function () { addjs(lwbwebsite + "/lwbplayer/animation.js"); addjs(lwbwebsite + "/lwbplayer/plugins.js");  });
