﻿ // JavaScript Document
var k_status = 99;
var k_status_novo = 99;
var k_a = 2; // variabla za aktualiziranje
var k_tmp = Math.round(100000000*Math.random());
var k_agt = navigator.userAgent;
var ZoomW;
var k_pa = 1; // aktualna PPT folija
var preloader = 0;
var k_log = 0;
var k_vst = ".";
var k_s = 1; // za archiv aktualni slidearray-zapis
var k_jez = 1;

	var url = String(window.location);
	var mp = 1;
	
	if(window.location.search != "") {
		var undef = url.split("?");
		var args = undef[1].split("&");
		
		for(i = 0; i < args.length; i++) {
			var a = args[i].split("=");
			if ( a[0] == 'mp' && a[1] == 2 ) mp = 2;
		}
	}

function aktualiziraj()
//Lobbypage, Live
{
	
	if (navigator.appName.indexOf("Netscape") == -1)
	{
		if (k_a == 1) k_a = 2;
		else k_a = 1;
		
		if (document.getElementById("aktual"+k_a).src != k_aurl) document.getElementById("aktual"+k_a).src = k_aurl;
		else document.getElementById("aktual"+k_a).contentWindow.location.reload(true);
	
	} else {
		k_a = 1
		document.getElementById("aktual"+k_a).src = "";
		document.getElementById("aktual"+k_a).src = k_aurl + "&x=" + Math.random();
	}

}

// *********************** L O B B Y   P A G E *******************************
function lobbystatus()
//Lobby
{
	aktualiziraj();
	
	if (parent.frames[0].document.getElementById("p_st")) {
		akt_st = parent.frames[0].document.getElementById("p_st").innerHTML;
		k_status_novo = akt_st * 1;
	}
	
	if (k_status != k_status_novo) {
		k_status = k_status_novo;
		minjaj();
	}
	
	if (!parent.frames[0].document.getElementById("p_st")) {
		akt_cas = 1500;
	} else {
		akt_cas = 22000;
	}
	akt_TO = setTimeout("lobbystatus()",akt_cas);
}

function mp_check()
//Lobby
{
	if (pluginlist.indexOf("Windows")!=-1) {
		document.getElementById("mp1").checked = true;
		ivtmpchange(1);
	} else if (pluginlist.indexOf("RealPlayer")!=-1) {
		document.getElementById("mp2").checked = true;
		ivtmpchange(2);
	} else {
		if (k_jez == 1) alert("Sie haben keinen gültigen Media Player installiert!\n(Um am Webcast teilzunehmen ist ein installierter Windows Media Player oder Real Player notwendig.)");
		else alert("Please install the Windows Media Player or the Real Player to view the webcast!");
	}
}

function ivtmpchange(bw)
//Lobby
{
	if (bw == 2) {
		if (pluginlist.indexOf("RealPlayer")!=-1) mp = 2;
		else alert("Sie haben keinen Real Player installiert!");
	} else {
		if (pluginlist.indexOf("Windows")!=-1) mp = 1;
		else alert("Sie haben keinen Windows Media Player installiert!");
	}
}

// ****************************** L I V E **********************************


function videoBW(x)
//Live
{
	if (!x) {
		var url = String(window.location);
		
		if(window.location.search != "") {
			var undef = url.split("?");
			var args = undef[1].split("&");
			
			for(i = 0; i < args.length; i++) {
				var a = args[i].split("=");
				if ( a[0] == 'bw' && a[1] <= 50 ) vurl = vurl1;
				if ( a[0] == 'bw' && a[1] > 50 ) vurl = vurl2;
				if (vurl3) if ( a[0] == 'bw' && a[1] == 300 ) vurl = vurl3;;
			}
		}
	}
	if (mp == 2) {
		document.video.SetSource(vurl);
		document.getElementById("video").src = vurl;
		document.video.DoPlay();
	} else {
		document.getElementById("video").src = vurl;
		document.getElementById("video").SRC = vurl;
		document.getElementById("video").URL = vurl;
		document.getElementById("video").FileName = vurl;
	}
}

function livestatus(akt_cas)
//Live
{
	aktualiziraj();
	
	if (parent.frames[0].document.getElementById("p_st")) { 
		pst = parent.frames[0].document.getElementById("p_st").innerHTML;
		if (pst == 3) stat2();
	}
	
	if (parent.frames[0].document.getElementById("p_ppt")) {
		akt = parent.frames[0].document.getElementById("p_ppt").innerHTML;
		k_pn = akt * 1;

		if (k_pa != k_pn) {
			k_pa = k_pn;
			document.getElementById("ppt").src = ppt_url1 + k_pa + ".jpg";
			if (ZoomW != null)
				if (typeof(ZoomW) != 'undefined')
					if (typeof(ZoomW.setSlide) != 'undefined'  &&  typeof(ZoomW.setSlide) != 'unknown')
						ZoomW.setSlide(ppt_url2 + k_pa + ".jpg");
			preloader = 0;
		} else if (preloader == 0) {
			document.getElementById("prelkip").src = ppt_url1 + (k_pa + 1) + ".jpg";
			preloader = 1;
		}
	}	
	if(!akt_cas) akt_cas = 1400;
	akt_TO = setTimeout("livestatus(" + akt_cas + ")",akt_cas);
}

function caslive()
//Live
{
	if (mp == 1) {
		akt = document.video.CurrentPosition;
		aktkaz = pretvoricas(akt);
		if (document.video.PlayState == 2) {
			document.getElementById("aktcas").innerHTML = "&nbsp;Live / " + aktkaz + "&nbsp;";
			document.getElementById("aktload").style.visibility = "hidden";
		} else if ((document.video.PlayState == 3) && (k_jez == 1)) {
			document.getElementById("aktcas").innerHTML = 'Zwischenspeichern';
			document.getElementById("aktload").style.visibility = "visible";
		} else if ((document.video.PlayState == 3) && (k_jez == 2)) {
			document.getElementById("aktcas").innerHTML = 'Buffering';
			document.getElementById("aktload").style.visibility = "visible";
		} else { 
			document.getElementById("aktcas").innerHTML = "Stop";
			document.getElementById("aktload").style.visibility = "hidden";
		}
	} else {
		akt = document.video.getPosition();
		aktkaz = pretvoricas(akt/1000);
		document.getElementById("aktcas").innerHTML = "&nbsp;Live / " + aktkaz + "&nbsp;";
		document.getElementById("aktload").style.visibility = "hidden";
	}
	setTimeout("caslive()", 200);
}

// *********************** L I V E   i   A R C H I V *******************************

function stat1()
//Live, Archiv
{
	document.getElementById("stat").src = "http://www.ivs.tv/webcast/stat.php?s=1&tmp=" + k_tmp + "&wc=" + k_wc + "&jez=" + k_jez + "";
	k_log = 1;
}

function stat2()
//Live, Archiv
{
	if (k_log == 1) {	
		document.getElementById("stat").src = "http://www.ivs.tv/webcast/stat.php?s=2&tmp=" + k_tmp + "&wc=" + k_wc + "&jez=" + k_jez + "";
		
		k_log = 0;
		self.setTimeout("zaprisve()",800);
	}
}

function zaprisve()
//Live
{
	window.close();
	if (ZoomW) ZoomW.closeZoom();
}

function PPT_Zoom(elemID,param)
//Live, Archiv
{
	ZoomW = window.open('', '_blank', 'width=720px,height=540px,resizable=yes');
	var src = ppt_url2 + k_pa + ".jpg";
	var doc = ZoomW.document;
	doc.open();
	var str =
		'<HTML>\r\n' +
		'<BODY onload=\"body_onload();\" leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>\r\n' +
		'<IMG id=curSlide name=curSlide width=\"100%\" height=\"100%\" src=\"' + src + '\">' +
		'</BODY>\r\n' +
		'<HEAD><TITLE>Powerpoint Zoom</TITLE>\r\n'+
		'<SCRIPT>\r\n' +
		'var closeCount=0;\r\n' +
		'var IE4 = (document.all)? true:false;\r\n' +
		'var NS4 = (document.layers) ? true:false;\r\n' +
		'var theElement = null;\r\n' +
		'var open_dt = new Date();\r\n' +
		'function setSlide(src)   { document.images[0].src = src; }\r\n' +
		'function closeZoom()     { window.close(); }\r\n' +
		'function body_onload() { var close_dt  = new Date(); if (window.opener) { if ((typeof(window.opener.LogEvent) == \"function\") || (typeof(window.opener.LogEvent) == \"object\")) { window.opener.LogEvent(\"' + elemID + '\",\"PowerPointComponent\",\"OpenZoom\",null,Math.round((close_dt.getTime()-open_dt.getTime())/1000)); } } }\r\n' +
		'function toggleCursor(state)   { opener.SetStyleInDoc(document,\"pointer\",\"visibility\",state.toUpperCase()==\"ON\"?\"visible\":\"hidden\"); }\r\n' +
		'function moveCursor(xp,yp)   { opener.SetStyleInDoc(document,\"pointer\",\"left\",(NS4?innerWidth:document.body.clientWidth)*xp/10000);opener.SetStyleInDoc(document,\"pointer\",\"top\",(NS4?innerHeight:document.body.clientHeight)*yp/10000);  }\r\n' +
		'</SCR' + 'IPT>\r\n' +
		'</HEAD>\r\n' +
		'</HTML>\r\n';
	doc.write(str);
	doc.close();
	ZoomW.setSlide(ppt_url2 + k_pa + ".jpg");
	ZoomW.focus();
}

function velikina(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}

function videostatus(kst)
{
	if (mp == 2) {
		switch(kst) {
		case 1:
			document.video.DoPlay();
			break;
		case 2:
			document.video.DoPause();
			break;
		case 3:
			document.video.DoStop();
			break;
		}
	} else {
		switch(kst) {
		case 1:
			document.video.Play();
			break;
		case 2:
			document.video.Pause();
			break;
		case 3:
			document.video.Stop();
			break;
		}
	}
	v_ctrl(kst);
}

function si_broj(ksl)
{
	k_s = ksl;
	cas = parseInt(slide[k_s][0])*1;
	if (document.video.CurrentPosition > 0) document.video.CurrentPosition = cas;
	if (mp == 2) document.video.SetPosition(cas*1000);
	videostatus(1);
}

var dur = "00:00";

function pretvoricas(akt)
{
	aktm = Math.floor(akt/60);
	if (aktm < 10) aktm = "0" + aktm;
	akts = Math.floor(akt - aktm*60);
	if (akts < 10) akts = "0" + akts;
	return aktm + ":" + akts;
}

function duzina()
{
	if (mp == 1) {
		akt = document.video.Duration;
		dur = pretvoricas(akt);
	}
	if (mp == 2) {
		akt = document.video.GetLength();
		dur = pretvoricas(akt/1000);
	} 
}

function aktcas()
//Live
{
	if (dur == "00:00") duzina();
	if (mp == 2) {
		akt = document.video.GetPosition();
		akt = akt/1000;
		pst = document.video.GetPlayState();
		if (document.video.GetPlayState() == 2) pst = 3;
		if (document.video.GetPlayState() == 3) pst = 2;
		if (document.video.GetPlayState() == 4) pst = 1;
	} else {
		akt = document.video.CurrentPosition;
		pst = document.video.PlayState;
	}
	
	aktkaz = pretvoricas(akt);
	
	if (pst == 2) {
		document.getElementById("aktcas").innerHTML = "&nbsp;" + aktkaz + " / " + dur;
		document.getElementById("aktload").style.visibility = "hidden";
		v_ctrl(1);
	} else if ((pst == 3) && (k_jez == 1)) {
		document.getElementById("aktcas").innerHTML = 'Zwischenspeichern';
		document.getElementById("aktload").style.visibility = "visible";
	} else if ((pst == 3) && (k_jez == 2)) {
		document.getElementById("aktcas").innerHTML = 'Buffering';
		document.getElementById("aktload").style.visibility = "visible";
	} else { 
		document.getElementById("aktcas").innerHTML = "Stop";
		document.getElementById("aktload").style.visibility = "hidden";
		v_ctrl(3);
	}
	if (pst == 2) {
		x = 0;
		while ((Math.floor(akt) + 2) > slide[x][0]) { x += 1 }
		if ((k_s != x) && (x <= slide.length)) pptminjaj(x);
	}

	setTimeout("aktcas()", 200);
}

