var t = '';

$.fn.cycle.defaults.speed   = 900;
$.fn.cycle.defaults.timeout = 6000;

$(function() {
    // run the code in the markup!
    $('div div pre code').each(function() {
        eval($(this).text());
    });
});



function ajaxInit() {
	var xmlHttpObj = null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttpObj = new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Selaimesi ei tue AJAX-tekniikkaa! Päivitä selaimesi uusimpaan versioon.");
			}
		}
	}
	
	return xmlHttpObj;
}

function vaihdaSivu(tyyppi, sivu, lajittelu, audio, video, puhujaid, sarjaid, katid, tagid, hakusana, srk)
{
	var xmlHttp = null;
	xmlHttp = ajaxInit();
	if(!xmlHttp) return false;
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{			
			
			document.getElementById("str_dynamic").innerHTML = xmlHttp.responseText;
			
			//if(sarjaid == 45) { 
								
			//}
			//else document.getElementById("fbchat").style.display = "none";
			
			// document.getElementById("str_srk").innerHTML = tuloste[1];
			$(function() {
				// run the code in the markup!
				$('div div pre code').each(function() {
					eval($(this).text());
				});
			});
		}
	}
	
	
	var data = "../../../streaming/str_functions.php";
	data = data + "?toiminto=vaihdasivu&tyyppi="+tyyppi+"&sivu="+sivu+"&lajittelu="+lajittelu+"&audio="+audio+"&video="+video+"&puhujaid="+puhujaid+"&sarjaid="+sarjaid+"&katid="+katid+"&tagid="+tagid+"&hakusana="+hakusana+"&srk="+srk;
	xmlHttp.open("GET",data,true);
	xmlHttp.send(null);  
}


function naytaHakusuositukset()
{
	var xmlHttp = null;
	xmlHttp = ajaxInit();
	if(!xmlHttp) return false;
	
	var hakusana = escape(document.getElementById('str_vapaahaku').value);
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{			
			//var ss = document.getElementById('str_hakusanat')
			var ss = document.getElementById('str_hakutulokset');
			ss.innerHTML = '';
			var tiedot = '';
			var str = xmlHttp.responseText.split("\n");
			var suggest = '<div id="str_ehdotusteksti">ehdotukset</div>';
			suggest += '<ul id="str_ehdotukset">';
			for(i=0; i < str.length - 1; i++) {			
				//Build our element string.  This is cleaner using the DOM, but			
				//IE doesn't support dynamically added attributes.			
				tiedot = str[i].split("|");
				suggest += '<li onmouseover="javascript:this.style.backgroundColor = \'#cccccc\'; this.style.cursor = \'pointer\';" ';			
				//suggest += 'onmouseout="javascript:this.style.backgroundColor = \'#FFFFFF\'; this.style.cursor = \'default\'; document.getElementById(\'str_hakutulokset\').style.visibility = \'hidden\'";';
				suggest += 'onmouseout="javascript:this.style.backgroundColor = \'#FFFFFF\'; this.style.cursor = \'default\';"';
				suggest += 'onclick="javascript:avaaFlowPlayer('+tiedot[1]+'); " ';			
				suggest += 'class="suggest_link">' + tiedot[0] + '</li>';
				
				//suggest += '<div style="padding:5px; font-family:Trebuchet MS, Verdana, Arial, Helvetica; font-size:11px; float:right; text-align:right; background-color:#FFFFFF; display:block; width:100%; padding-left:5px; padding-right:5px;" onmouseover="javascript:this.style.backgroundColor = \'#cccccc\';" ';			
				//suggest += 'onmouseout="javascript:this.style.backgroundColor = \'#FFFFFF\';" ';			
				//suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';			
				//suggest += 'class="suggest_link">' + str[i] + '</div>';			
				
				//ss.innerHTML += suggest;		
			}
			suggest += '</ul>';
			ss.innerHTML += suggest;
			if(str.length == 1 || hakusana.length == 0) ss.style.visibility = "hidden";
			else ss.style.visibility = "visible";
		}
	}
	var data = "../../../streaming/str_functions.php";
	data = data + "?toiminto=vapaahaku&hakusana="+encodeURI(hakusana);
	xmlHttp.open("GET",data,true);
	xmlHttp.send(null);  
}



function avaaPlayer(id,tyyppi,email,ajankohta,aika,debug)
{
	clearTimeout(t);
	var xmlHttp = null;
	xmlHttp = ajaxInit();
	if(!xmlHttp) return false;
	
	var tiedot = '';
	var ohj = document.getElementById("str_ohjelmatiedot");
	var mp3 = '';
	
	document.getElementById("linkit").style.visibility = 'visible';
	document.getElementById("palauteForm").innerHTML += '<input name="srkemail" id="srkemail" type="hidden" value="'+email+'" />';
	document.getElementById("kaveriForm").innerHTML += '<input type="hidden" id="ohjelma" value="'+id+'">';
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{	
			tiedot = xmlHttp.responseText.split("|");
			tiedot.push(id);
			// jos osoiteriville syötetään testi-muuttuja, laskuria ei näytetä (live)
			// tai jos tyyppi on arkisto
			if(tyyppi != "live" || debug) naytaSoitin(tiedot);
			// tavallinen live, laskuri näytetään
			else startCountDown(ajankohta, aika, tiedot);
		}
	}
	var data = "../../../streaming/str_functions.php";
	data = data + "?toiminto=avaaplayer&id="+id+"&tyyppi="+tyyppi;
	xmlHttp.open("GET",data,true);
	xmlHttp.send(null);  
}







function avaaFlowPlayer(id,tyyppi,email,ajankohta,aika,debug)
{
	clearTimeout(t);
	var xmlHttp = null;
	xmlHttp = ajaxInit();
	if(!xmlHttp) return false;
	
	var tiedot = '';
	var ohj = document.getElementById("str_ohjelmatiedot");
	var mp3 = '';
	
	document.getElementById("linkit").style.visibility = 'visible';
	document.getElementById("srkemail").value = email;
	document.getElementById("ohjid").value = id;
	//document.getElementById("srkemail").value = email;
	document.getElementById("ohjelma").value = id;
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{	
			tiedot = xmlHttp.responseText.split("|");
			tiedot.push(id);
			
			
			//document.getElementById("fbchat").src = "http://www.facebook.com/plugins/live_stream_box.php?app_id=160939500602121&amp;width=790&amp;height=300&amp;xid="+tiedot[9]+"&amp;via_url&amp;always_post_to_friends=false";
			document.getElementById("fbchatdiv").innerHTML = "<iframe id='fbchat' src='http://www.facebook.com/plugins/live_stream_box.php?app_id=160939500602121&amp;width=790&amp;height=300&amp;xid="+tiedot[9]+"&amp;via_url&amp;always_post_to_friends=false' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:790px; height:300px; display:none;' allowTransparency='true'></iframe>";
			
			var script = 'http://s7.addthis.com/js/250/addthis_widget.js#domready=1';
			if (window.addthis){
				window.addthis = null;
			}
			$.getScript( script );
			
			// jos osoiteriville syötetään testi-muuttuja, laskuria ei näytetä (live)
			// tai jos tyyppi on arkisto
			//if(tyyppi != "live" || debug) naytaFlowSoitin(tiedot);
			// tavallinen live, laskuri näytetään
			startCountDown(ajankohta, aika, tiedot);
		}
	}
	var data = "../../../streaming/str_functions.php";
	data = data + "?toiminto=avaaflowplayer&id="+id+"&tyyppi="+tyyppi;
	xmlHttp.open("GET",data,true);
	xmlHttp.send(null);  
}







function naytaSoitin(tiedot) {
	
	var sisalto = '';
	
	
	
	if(tiedot[0].substr(tiedot[0].length-3) == "mp3") mp3 = true;
	else mp3 = false;
	
	//document.getElementById("str_playerdiv").innerHTML = xmlHttp.responseText;
	if(mp3) {
		//document.getElementById("str_playerdiv").style.height = '120px';
		document.getElementById("str_player").style.height = '20px';
	} else {
		//document.getElementById("str_playerdiv").style.height = '600px';
		document.getElementById("str_player").style.height = '452px';
	}
	//document.getElementById("str_playerdiv").style.marginBottom = '0';
	
	if(tiedot[3] == "wmv") 
	{		
			// WMV-PLAYER
			/*
			var elm = document.getElementById("str_player");
			var src = '../../../streaming/player/wmvplayer/wmvplayer.xaml';
			var cfg = {
					file:tiedot[0],
					width:'768',
					height:'452',
					autostart:'true',
					shownavigation:'true'
					};
			var ply = new jeroenwijering.Player(elm,src,cfg);
			*/
			if(-1 != navigator.userAgent.indexOf("Firefox") || -1 != navigator.userAgent.indexOf("Opera"))
			{				
				sisalto += '<object id "mediaplayer" name="mediaplayer" width="768" height="452" type="application/x-mplayer2" stretchtofit="1" >';
				sisalto += '<param name="fileName" value="'+tiedot[0]+'">';
				sisalto += '<param name="autostart" value="1">';
				sisalto += '<param name="ShowStatusBar" value="0">';
				sisalto += '<param name="stretchToFit" value="1"/>';
				sisalto += '</object>';
				
				
			} else {
			
				
				sisalto += '<OBJECT id="mediaplayer2" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="768" height="452">';
		
				sisalto += '<PARAM NAME="URL" VALUE="'+tiedot[0]+'">';
		
				sisalto += '<PARAM NAME="enabled" VALUE="True">';
		
				sisalto += '<PARAM NAME="AutoStart" VALUE="true">';
		
				sisalto += '<PARAM name="PlayCount" value="3">';
		
				sisalto += '<PARAM name="Volume" value="100">';
		
				sisalto += '<PARAM NAME="balance" VALUE="0">';
		
				sisalto += '<PARAM NAME="Rate" VALUE="1.0">';
		
				sisalto += '<PARAM NAME="Mute" VALUE="False">';
		
				sisalto += '<PARAM NAME="fullScreen" VALUE="false">';
				
				sisalto += '<param name="stretchToFit" value="1"/>';
		
				sisalto += '<PARAM name="uiMode" value="full">';
				sisalto += '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer2" ShowStatusBar="true" EnableContextMenu="false" autostart="false" width="768" height="452" loop="false" src="'+tiedot[0]+'" />';
				sisalto += '</OBJECT>';
			}
			document.getElementById("str_player").innerHTML = sisalto;	
			
		
	}
	else if(tiedot[3] == "flv")
	{
			var elm = document.getElementById("str_player");					
			if(mp3) var s1 = new SWFObject('../../../streaming/player/flvplayer/player.swf','player','768','20','9');
			else var s1 = new SWFObject('../../../streaming/player/flvplayer/player.swf','player','768','452','9');
			s1.addParam('allowfullscreen','true');
			s1.addParam('allowscriptaccess','always');
			//s1.addParam('flashvars','file='+tiedot[0]+'&streamer=rtmp://81.22.246.204/vod2&autostart=true&type=rtmp');
			if(tiedot[7] == "live") {
				s1.addVariable('file', 'livestream');
				s1.addVariable('streamer',tiedot[0]);
				s1.addVariable('autostart','true');
				s1.addVariable('type','rtmp');
			} else {
				s1.addVariable('file', tiedot[0]);
				s1.addVariable('streamer','rtmp://81.22.246.204/vod2');
				s1.addVariable('autostart','true');
				s1.addVariable('type','rtmp');
			}
			s1.write(elm);			
	}


	// OHJELMAN LISÄTIEDOT JA FACEBOOK-JAKO
	
	teeLisatiedot(tiedot);
	
	document.location.href = "#player";
	document.title = Utf8.decode("Netmission, helluntaiherätyksen evankelioiva portaali");
	document.getElementById("str_player").focus();
	

	
}







function naytaFlowSoitin(tiedot) {
	
	var sisalto = '';
	
	
	
		
		
		// ARKISTO
		if(tiedot[3] != "mp3") {
			if(tiedot[3] == "wmv")
				// wmv
				{
				document.getElementById("str_player").style.height = "452px";
				//document.getElementById("str_flowplayer").style.height = "452px";	
							// WMV-PLAYER
				/*
				var elm = document.getElementById("str_player");
				var src = '../../../streaming/player/wmvplayer/wmvplayer.xaml';
				var cfg = {
						file:tiedot[0],
						width:'768',
						height:'452',
						autostart:'true',
						shownavigation:'true'
						};
				var ply = new jeroenwijering.Player(elm,src,cfg);
				*/
				if(-1 != navigator.userAgent.indexOf("Firefox") || -1 != navigator.userAgent.indexOf("Opera"))
				{				
					sisalto += '<object id "mediaplayer" name="mediaplayer" width="768" height="452" type="application/x-mplayer2" stretchtofit="1" >';
					sisalto += '<param name="fileName" value="'+tiedot[0]+'">';
					sisalto += '<param name="autostart" value="1">';
					sisalto += '<param name="ShowStatusBar" value="0">';
					sisalto += '<param name="stretchToFit" value="1"/>';
					sisalto += '</object>';
					
					
				} else {
					
					
					
					sisalto += '<OBJECT id="mediaplayer2" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" width="768" height="452">';
			
					sisalto += '<PARAM NAME="URL" VALUE="'+tiedot[0]+'">';
			
					sisalto += '<PARAM NAME="enabled" VALUE="True">';
			
					sisalto += '<PARAM NAME="AutoStart" VALUE="true">';
			
					sisalto += '<PARAM name="PlayCount" value="3">';
			
					sisalto += '<PARAM name="Volume" value="100">';
			
					sisalto += '<PARAM NAME="balance" VALUE="0">';
			
					sisalto += '<PARAM NAME="Rate" VALUE="1.0">';
			
					sisalto += '<PARAM NAME="Mute" VALUE="False">';
			
					sisalto += '<PARAM NAME="fullScreen" VALUE="false">';
					
					sisalto += '<param name="stretchToFit" value="1"/>';
			
					sisalto += '<PARAM name="uiMode" value="full">';
					sisalto += '<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer2" ShowStatusBar="true" EnableContextMenu="false" autostart="false" width="768" height="452" loop="false" src="'+tiedot[0]+'" />';
					sisalto += '</OBJECT>';
				}
				document.getElementById("str_player").innerHTML = sisalto;	
				
			
			}
			else
			{
				
				
				if(tiedot[7] == "live") {
					
					
					
					var livestream = "";
					
					if(tiedot[10] == "0") livestream = "livestream";
					else if(tiedot[10] == "1") livestream = "livestream1";
					else if(tiedot[10] == "2") livestream = "livestream2";
					else if(tiedot[10] == "4") livestream = "livestream3";
					
					if(tiedot[9] == "27") {
						// tampereen live
						tampere = tiedot[0].split(" ");
						
						sisalto += '<a style="display:block;width:768px;height:452px;" id="str_flowplayer">	</a>';
		
		
						document.getElementById("str_player").innerHTML = sisalto;	
						
						
						document.getElementById("str_player").style.height = "452px";
						document.getElementById("str_flowplayer").style.height = "452px";
						
						
						
						$f("str_flowplayer", "../../../streaming/flowplayer/flowplayer.commercial-3.2.5.swf", {
						   
						key: '#$201852a26207a03a389',
						logo: {
							url: '../../../streaming/nmlogo.png',
							fullscreenOnly: false,
							opacity: 0.3,
							displayTime: 0
						},
					
						clip: {
							url: tampere[1],
							scaling: 'fit',
							live: true,
							// configure clip to use influxis as our provider, it uses our rtmp plugin
							provider: 'rtmp'
							},
						
							// streaming plugins are configured under the plugins node
							plugins: {
						
								// here is our rtpm plugin configuration
								rtmp: {
									url: '/../../../streaming/flowplayer/flowplayer.rtmp-3.2.3.swf',
						
									// netConnectionUrl defines where the streams are found
									netConnectionUrl: tampere[0]				
								},
								gatracker: {
									url: "/../../../streaming/flowplayer/flowplayer.analytics-3.2.1.swf",
									labels: {
										start: "Start",	
										play: "Play",	
										pause: "Pause",	
										resume: "Resume",	
										seek: "Seek",	
										stop: "Stop",	
										finish: "Finish",	
										mute: "Mute",	
										unmute: "Unmute",	
										fullscreen: "Full Screen",	
										fullscreenexit: "Full Screen Exit"	
									},
									debug: false,
									trackingMode: "AS3",
									googleId: "UA-721773-5" // your Google Analytics id here
								}
							
							}
						}).ipad();	
					
					} else {
						// normaali rtmp-live
					
						sisalto += '<a style="display:block;width:768px;height:452px;" id="str_flowplayer">	</a>';
		
		
						document.getElementById("str_player").innerHTML = sisalto;	
						
						
						document.getElementById("str_player").style.height = "452px";
						document.getElementById("str_flowplayer").style.height = "452px";
									
						$f("str_flowplayer", "../../../streaming/flowplayer/flowplayer.commercial-3.2.5.swf", {
						key: '#$201852a26207a03a389',
						logo: {
							url: '../../../streaming/nmlogo.png',
							fullscreenOnly: false,
							opacity: 0.3,
							displayTime: 0
						},
						
						/*playlist: [
								   {
									    url: 'mp4:netmission/streamingmainos1',
										ipadUrl: 'http://81.22.246.204/vod2/netmission/streamingmainos1.mp4',
										scaling: 'fit',
										// configure clip to use influxis as our provider, it uses our rtmp plugin
										
										controls: { enabled: {scrubber: false} }, 
										provider: 'rtmpnm'
								   },
								   {
									    url: livestream,
										scaling: 'fit',
										live: true,
										provider: 'rtmp'
										// configure clip to use influxis as our provider, it uses our rtmp plugin
								   }
						   ],*/
						clip: {
								url: livestream,
								scaling: 'fit',
								live: true,
								provider: 'rtmp'
								// configure clip to use influxis as our provider, it uses our rtmp plugin
							
							},
						
							// streaming plugins are configured under the plugins node
							plugins: {
						
								// here is our rtpm plugin configuration
								rtmp: {
									url: '/../../../streaming/flowplayer/flowplayer.rtmp-3.2.3.swf',
						
									// netConnectionUrl defines where the streams are found
									netConnectionUrl: tiedot[0]				
								},
								rtmpnm: {
									url: '/../../../streaming/flowplayer/flowplayer.rtmp-3.2.3.swf',
						
									// netConnectionUrl defines where the streams are found
									netConnectionUrl: 'rtmp://81.22.246.204/vod2'				
								},
								gatracker: {
									url: "/../../../streaming/flowplayer/flowplayer.analytics-3.2.1.swf",
									labels: {
										start: "Start",	
										play: "Play",	
										pause: "Pause",	
										resume: "Resume",	
										seek: "Seek",	
										stop: "Stop",	
										finish: "Finish",	
										mute: "Mute",	
										unmute: "Unmute",	
										fullscreen: "Full Screen",	
										fullscreenexit: "Full Screen Exit"	
									},
									debug: false,
									trackingMode: "AS3",
									googleId: "UA-721773-5" // your Google Analytics id here
								}
							}
						}).ipad();	
					}
				
				}
				else
				{
					// normaali rtmp arkisto
					sisalto += '<a href="rtmp://81.22.246.204/vod2/'+tiedot[0]+'" style="display:block;width:768px;height:452px;" id="str_flowplayer">	</a>';
		
		
					document.getElementById("str_player").innerHTML = sisalto;	
					
					var numero = Math.floor(Math.random()*3+1)+'';
					
					document.getElementById("str_player").style.height = "452px";
					document.getElementById("str_flowplayer").style.height = "452px";	
					$f("str_flowplayer", "../../../streaming/flowplayer/flowplayer.commercial-3.2.5.swf", {
					key: '#$201852a26207a03a389',
					logo: {
							url: '../../../streaming/nmlogo.png',
							fullscreenOnly: false,
							opacity: 0.3,
							displayTime: 0
						},
					playlist: [
								   {
									    url: 'mp4:netmission/streamingmainos'+numero,
										ipadUrl: 'http://81.22.246.204/vod2/netmission/streamingmainos'+numero+'.mp4',
										scaling: 'fit',
										// configure clip to use influxis as our provider, it uses our rtmp plugin
										
										controls: { enabled: {scrubber: false} }
								   },
								   {
									    url: tiedot[0],
						
										ipadUrl: 'http://81.22.246.204/vod2/'+tiedot[0].substr(4),
										scaling: 'fit'
										// configure clip to use influxis as our provider, it uses our rtmp plugin
										
								   }
								   ],
					clip: {
							provider: 'rtmp'
						},
					
						// streaming plugins are configured under the plugins node
						plugins: {
					
							// here is our rtpm plugin configuration
							rtmp: {
								url: '/../../../streaming/flowplayer/flowplayer.rtmp-3.2.3.swf',
					
								// netConnectionUrl defines where the streams are found
								netConnectionUrl: 'rtmp://81.22.246.204/vod2'				
							},
							gatracker: {
									url: "/../../../streaming/flowplayer/flowplayer.analytics-3.2.1.swf",
									labels: {
										start: "Start",	
										play: "Play",	
										pause: "Pause",	
										resume: "Resume",	
										seek: "Seek",	
										stop: "Stop",	
										finish: "Finish",	
										mute: "Mute",	
										unmute: "Unmute",	
										fullscreen: "Full Screen",	
										fullscreenexit: "Full Screen Exit"	
									},
									debug: false,
									trackingMode: "AS3",
									googleId: "UA-721773-5" // your Google Analytics id here
								}
						}
					}).ipad();
					
				}
			}
		}
		else
		// mp3-player
		{
			sisalto += '<a href="rtmp://81.22.246.204/vod2/'+tiedot[0]+'" style="display:block;width:768px;height:452px;" id="str_flowplayer">	</a>';
		
		
			document.getElementById("str_player").innerHTML = sisalto;	
		
			document.getElementById("str_player").style.height = "30px";
			document.getElementById("str_flowplayer").style.height = "30px";
			$f("str_flowplayer", "../../../streaming/flowplayer/flowplayer.commercial-3.2.5.swf", {
			key: '#$201852a26207a03a389',
			logo: {
							url: '../../../streaming/nmlogo.png',
							fullscreenOnly: false,
							opacity: 0.3,
							displayTime: 0
						},
			clip: {
				url: tiedot[0],
				scaling: 'fit',
				ipadUrl: 'http://81.22.246.204/vod2/'+tiedot[0].substr(4)+'.mp3',
				// configure clip to use influxis as our provider, it uses our rtmp plugin
				provider: 'rtmp'
				},
			
				// streaming plugins are configured under the plugins node
				plugins: {
			
					// here is our rtpm plugin configuration
					rtmp: {
						url: '/../../../streaming/flowplayer/flowplayer.rtmp-3.2.3.swf',
			
						// netConnectionUrl defines where the streams are found
						netConnectionUrl: 'rtmp://81.22.246.204/vod2',
						durationFunc: 'getStreamLength'
					},
					controls: {
						fullscreen: false,
						height: 30,
						autoHide: false
					},
					gatracker: {
									url: "/../../../streaming/flowplayer/flowplayer.analytics-3.2.1.swf",
									labels: {
										start: "Start",	
										play: "Play",	
										pause: "Pause",	
										resume: "Resume",	
										seek: "Seek",	
										stop: "Stop",	
										finish: "Finish",	
										mute: "Mute",	
										unmute: "Unmute",	
										fullscreen: "Full Screen",	
										fullscreenexit: "Full Screen Exit"	
									},
									debug: false,
									trackingMode: "AS3",
									googleId: "UA-721773-5" // your Google Analytics id here
								}
				}
			}).ipad();
			
		}
	

	// OHJELMAN LISÄTIEDOT JA FACEBOOK-JAKO
	
	teeLisatiedot(tiedot);
	
	document.location.href = "#player";
	document.title = Utf8.decode("Netmission, helluntaiherätyksen evankelioiva portaali");
	document.getElementById("str_player").focus();
	

	
}








function teeLisatiedot(tiedot) {
	var ohj = document.getElementById("str_ohjelmatiedot");
	ohj.innerHTML = "<div id=\"ohjelmatiedot\">";
	ohj.innerHTML += "<div class=\"str_ohjelmatiedot\"><h1>"+tiedot[1]+"</h1>"+tiedot[5]+" - "+tiedot[2].replace('srk','seurakunta')+"<br />"+tiedot[4]+"</div>";
	
	//ohj.innerHTML += "<div class=\"str_jaa\"><a href=\"http://www.facebook.com/share.php?u="+encodeURIComponent("http://www.netmission.fi/fi/etusivu/?id=267&vid=")+id+"\" class=\"fb_share_button\" onclick=\"return fbs_click()\" target=\"_blank\" style=\"text-decoration:none;\">Jaa</a></div>";
	
	
	//ohj.innerHTML += "<div class=\"str_jaa\"><a href=\"http://www.netmission.fi/streaming/fbshare.php?otsikko="+tiedot[1]+"&selitys="+tiedot[4]+"&id="+tiedot[7]+"&srk="+tiedot[6]+"\" class=\"fb_share_button\" target=\"fbshare\" style=\"text-decoration:none;\">Jaa</a></div>";
	
	var rand = Math.floor(new Date().getTime()/1000);
	ohj.innerHTML += "<div class=\"str_jaa\"> <div class=\"addthis_toolbox addthis_default_style\"> <a href=\"http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4d07188565eef1db\" class=\"addthis_button_compact\" addthis:url=\"http://www.netmission.fi/index.php?id=267&vid="+tiedot[8]+"&i="+rand+"\" addthis:title=\""+tiedot[1]+"\">Jaa</a> </div> </div>";




	ohj.innerHTML += "</div>";
}


function ajaxForm(form)
{
	var xmlHttp = null;
	xmlHttp = ajaxInit();
	if(!xmlHttp) return false;
	
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			naytaDiv(1);
			document.getElementById("tab1").innerHTML = xmlHttp.responseText;
			document.getElementById("palauteForm").reset();
			document.getElementById("kaveriForm").reset();
		}
	}
	if(form == 1) {		  
		var data = "tyyppi="+document.getElementById("tyyppi").options[document.getElementById("tyyppi").selectedIndex].value+"&nimi="+document.getElementById("nimi").value+"&email="+document.getElementById("email").value+"&viesti="+document.getElementById("viesti").value+"&srkemail="+document.getElementById("srkemail").value+"&id=1";
	} else if(form == 2) {
		var data = "nimi="+document.getElementById("nimi2").value+"&email="+document.getElementById("email2").value+"&viesti="+document.getElementById("viesti2").value+"&id=2&ohjelma="+document.getElementById("ohjelma").value;  
	}
	xmlHttp.open("POST","../../../streaming/palaute.php",true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
	xmlHttp.send(data);  
}

function piilotaHakutulokset() {	
	var t=setTimeout("document.getElementById('str_hakutulokset').style.visibility = 'hidden'; clearTimeout(this);",200);
	
}



/*
Author: Robert Hashemian
http://www.hashemian.com/

You can use this code in any manner so long as the author's
name, Web address and this disclaimer is kept intact.
********************************************************
*/

function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  //s = ((Math.floor(secs/num1))%num2).toString();  
  if (s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(secs, bitrate) {
  if(Tiedot[7] != "live") {
	  naytaFlowSoitin(Tiedot);
	  return;
  }
  if(secs < 600) {
	if(Tiedot[12] == "true") document.getElementById("fbchat").style.display = "";
	if(bitrate == 1 || bitrate == 2) {
		Tiedot[10] = bitrate;
		naytaFlowSoitin(Tiedot);
		return;
	}
	if(Tiedot[10] != 3 ) naytaFlowSoitin(Tiedot);
	else {
		var player = document.getElementById("str_player");
		player.innerHTML = "<div id='str_laskuri'><br><br><br><br><br>Valitse laatu, mill&auml; haluat katsoa l&auml;hetyst&auml;:<br><br><div class='bitrate' onmouseover='this.style.cursor=\"pointer\"; this.style.backgroundColor=\"#ccc\";' onmouseout='this.style.cursor=\"default\"; this.style.backgroundColor=\"white\";' onclick='javascript:CountBack(0,1);'>Korkea laatu <span style=\"font-size:10px;\">596kbps</span></div><div class='bitrate' onmouseover='this.style.cursor=\"pointer\"; this.style.backgroundColor=\"#ccc\";' onmouseout='this.style.cursor=\"default\"; this.style.backgroundColor=\"white\";' onclick='javascript:CountBack(0,2);'>Normaali laatu <span style=\"font-size:10px;\">296kbps</span></div></div>";
	}
	
    return;
  }
  if(Tiedot[12] == "true") document.getElementById("fbchat").style.display = "";
  DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60));
  DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60));
  
  DisplayStr = "<div id='str_laskuri'><br><br><br><br><br>Ohjelman alkuun:<br><br>"+DisplayStr+"</div>";

  document.getElementById("str_player").innerHTML = DisplayStr;
  if (CountActive)
    t = setTimeout("CountBack(" + (secs-1) + ")", 990);
}

function countDown() {
	if (typeof(BackColor)=="undefined")
	  BackColor = "white";
	if (typeof(ForeColor)=="undefined")
	  ForeColor= "black";
	if (typeof(TargetDate)=="undefined")
	  TargetDate = "12/31/2020 5:00 AM";
	if (typeof(DisplayFormat)=="undefined")
	  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
	if (typeof(CountActive)=="undefined")
	  CountActive = true;
	if (typeof(FinishMessage)=="undefined")
	  FinishMessage = "";
	
	var dthen = new Date(TargetDate);
	var dnow = new Date(Aika);
	ddiff = new Date(dthen-dnow);
	gsecs = Math.floor(ddiff.valueOf()/1000);
	CountBack(gsecs);
}


function startCountDown(target,aika,tiedot) {
	TargetDate = target;
	Aika = aika;
	Tiedot = tiedot;
	CountActive = true;
	CountStepper = -1;
	LeadingZero = true;
	DisplayFormat = "%%D%% p&auml;iv&auml;&auml; %%H%% h %%M%% m %%S%% s";
	FinishMessage = "";
	
	document.getElementById("str_player").style.visibility = "visible";
	//document.getElementById("str_playerdiv").style.height = '600px';
	
	teeLisatiedot(Tiedot);
	countDown();
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function naytaDiv(id) {
	
	for(i=1;i<6;i++) {
		var obj = document.getElementById("tab"+i);
		if(i == id && id == 5) {
			document.getElementById("valilehticontainer").style.height = "500px";
			obj.style.visibility = "visible";
			obj.style.height = "450px";
			obj.style.padding = "20px";
			obj.style.backgroundColor = "#e5ffca";
			obj.style.borderLeft = "solid #d1faa7 1px";
			obj.style.borderRight = "solid #d1faa7 1px";
			obj.style.borderBottom = "solid #d1faa7 1px";
			obj.style.backgroundImage = "url(../../../streaming/kuvat/valilehtitausta.gif)";
			obj.style.backgroundRepeat = "no-repeat";
			if(id == 4) obj.style.backgroundPosition = "-210px 0px";
			else if(id == 3) obj.style.backgroundPosition = "10px 0px";
			else if(id == 5) obj.style.backgroundPosition = "-380px 0px";
			else if(id == 2) obj.style.backgroundPosition = "-560px 0px";
			else if(id == 1) { obj.style.backgroundImage = ""; obj.style.borderTop = "solid #d1faa7 1px"; }
		}
		else if(i == id && id == 2) {
			document.getElementById("valilehticontainer").style.height = "400px";
			obj.style.visibility = "visible";
			obj.style.height = "350px";
			obj.style.padding = "20px";
			obj.style.backgroundColor = "#e5ffca";
			obj.style.borderLeft = "solid #d1faa7 1px";
			obj.style.borderRight = "solid #d1faa7 1px";
			obj.style.borderBottom = "solid #d1faa7 1px";
			obj.style.backgroundImage = "url(../../../streaming/kuvat/valilehtitausta.gif)";
			obj.style.backgroundRepeat = "no-repeat";
			if(id == 4) obj.style.backgroundPosition = "-210px 0px";
			else if(id == 3) obj.style.backgroundPosition = "10px 0px";
			else if(id == 5) obj.style.backgroundPosition = "-380px 0px";
			else if(id == 2) obj.style.backgroundPosition = "-560px 0px";
			else if(id == 1) { obj.style.backgroundImage = ""; obj.style.borderTop = "solid #d1faa7 1px"; }
		}
		else if(i == id && id == 4) {
			document.getElementById("valilehticontainer").style.height = "400px";
			obj.style.visibility = "visible";
			obj.style.height = "350px";
			obj.style.padding = "20px";
			obj.style.backgroundColor = "#e5ffca";
			obj.style.borderLeft = "solid #d1faa7 1px";
			obj.style.borderRight = "solid #d1faa7 1px";
			obj.style.borderBottom = "solid #d1faa7 1px";
			obj.style.backgroundImage = "url(../../../streaming/kuvat/valilehtitausta.gif)";
			obj.style.backgroundRepeat = "no-repeat";
			if(id == 4) obj.style.backgroundPosition = "-210px 0px";
			else if(id == 3) obj.style.backgroundPosition = "10px 0px";
			else if(id == 5) obj.style.backgroundPosition = "-380px 0px";
			else if(id == 2) obj.style.backgroundPosition = "-560px 0px";
			else if(id == 1) { obj.style.backgroundImage = ""; obj.style.borderTop = "solid #d1faa7 1px"; }
		}
		else if(i == id && id == 3) {
			document.getElementById("valilehticontainer").style.height = "400px";
			obj.style.visibility = "visible";
			obj.style.height = "350px";
			obj.style.padding = "20px";
			obj.style.backgroundColor = "#e5ffca";
			obj.style.borderLeft = "solid #d1faa7 1px";
			obj.style.borderRight = "solid #d1faa7 1px";
			obj.style.borderBottom = "solid #d1faa7 1px";
			obj.style.backgroundImage = "url(../../../streaming/kuvat/valilehtitausta.gif)";
			obj.style.backgroundRepeat = "no-repeat";
			if(id == 4) obj.style.backgroundPosition = "-210px 0px";
			else if(id == 3) obj.style.backgroundPosition = "10px 0px";
			else if(id == 5) obj.style.backgroundPosition = "-380px 0px";
			else if(id == 2) obj.style.backgroundPosition = "-560px 0px";
			else if(id == 1) { obj.style.backgroundImage = ""; obj.style.borderTop = "solid #d1faa7 1px"; }
		}
		else if(i == id && id == 1) {
			document.getElementById("valilehticontainer").style.height = "400px";
			obj.style.visibility = "visible";
			obj.style.height = "350px";
			obj.style.padding = "20px";
			obj.style.backgroundColor = "#e5ffca";
			obj.style.borderLeft = "solid #d1faa7 1px";
			obj.style.borderRight = "solid #d1faa7 1px";
			obj.style.borderBottom = "solid #d1faa7 1px";
			obj.style.backgroundImage = "url(../../../streaming/kuvat/valilehtitausta.gif)";
			obj.style.backgroundRepeat = "no-repeat";
			if(id == 4) obj.style.backgroundPosition = "-210px 0px";
			else if(id == 3) obj.style.backgroundPosition = "10px 0px";
			else if(id == 5) obj.style.backgroundPosition = "-380px 0px";
			else if(id == 2) obj.style.backgroundPosition = "-560px 0px";
			else if(id == 1) { obj.style.backgroundImage = ""; obj.style.borderTop = "solid #d1faa7 1px"; }
		}
		else {
			obj.style.visibility = "hidden";
			obj.style.height = "0px";
			obj.style.padding = "0px";
			obj.style.backgroundColor = "";
			obj.style.border = "";
		}
	}
}

function piilotaDivit() {
	document.getElementById("valilehticontainer").style.height = "0px";
	for(i=1;i<6;i++) {
		var obj = document.getElementById("tab"+i);
		
			obj.style.visibility = "hidden";
			obj.style.height = "0px";
			obj.style.padding = "0px";
			obj.style.backgroundColor = "";
			obj.style.border = "";
		
	}
}


/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
