var chat_room = 0;
var chat_show = 1;
var chat_type = 1;
var chat_timeout;


function show_death_video(server, imgver) {
	if (!imgver)  imgver = '';
	document.write('<div id="freevideospace"><a href="?videoplay=1" onclick="return !play_death_video(\''+ server +'\');" class="videoplay"><img src="img/videoplay'+ imgver +'.jpg" width="360" height="353"></a></div>');
}
function play_death_video(server) {
	obj = document.getElementById("freevideospace");
	ret = '<object width="360" height="353" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Player ..." type="application/x-oleobject">';
	ret += '  <param name="url" value="'+ server +'">';
	ret += '  <param name="stretchToFit" value="1">';
	ret += '  <param name="autoStart" value="1">';
	ret += '	<embed src="'+ server +'" ShowStatusBar="1" autostart="1" stretchToFit="1" width="360" height="353" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/downloads/contents/products/mediaplayer/"></embed>';
	ret += '</object>';
	obj.innerHTML = ret;
	return true;
}



function show_live_video(server) {
	document.write('<object width="360" height="353" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Player ..." type="application/x-oleobject">');
	document.write('  <param name="url" value="'+ server +'">');
	document.write('  <param name="stretchToFit" value="1">');
	document.write('  <param name="autoStart" value="1">');
	document.write('	<embed src="'+ server +'" ShowStatusBar="1" autostart="1" stretchToFit="1" width="360" height="353" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/downloads/contents/products/mediaplayer/"></embed>');
	document.write('</object>');
}






var fwobj;
function free_video_window(title, server) {
	if (typeof(fwobj) == "object") fwobj.close();
	w = 360;
	h = 353;
	x = Math.round((window.screen.width - w) / 2);
	y = Math.round((window.screen.height - h) / 2 / 2);
	fwobj = window.open('', '', 'scrollbars=no,noresizable,height='+h+',width='+w+',top='+y+',left='+x);
	fwobj.document.open();
	fwobj.document.write('<html><head><title>'+ title +'</title><style type="text/css">body {margin: 0} img {border: 0}</style></head><body>');
	fwobj.document.write('<object width="360" height="353" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" standby="Loading Player ..." type="application/x-oleobject">');
	fwobj.document.write('  <param name="url" value="'+ server +'">');
	fwobj.document.write('  <param name="stretchToFit" value="1">');
	fwobj.document.write('  <param name="autoStart" value="1">');
	fwobj.document.write('	<embed src="'+ server +'" autostart="1" ShowStatusBar="1" stretchToFit="1" width="360" height="353" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/downloads/contents/products/mediaplayer/"></embed>');
	fwobj.document.write('</object>');
	fwobj.document.write('</body></html>');
	fwobj.document.close();
	return true;
}


var prwobj;
function pressroom_image_window(title, file, w, h) {
	if (typeof(prwobj) == "object") prwobj.close();
	rw = w; rh = h;
	wsw = window.screen.width;
	wsh = window.screen.height;
	if (wsw < w-100) w = wsw-100; else w+= 15;
	if (wsh < h-200) h = wsh-200; else h+= 1;
	x = Math.round((wsw - w) / 2);
	y = Math.round((wsh - h) / 2 / 2);
	prwobj = window.open('', '', 'scrollbars=yes,resizable,height='+h+',width='+w+',top='+y+',left='+x);
	prwobj.document.open();
	prwobj.document.write('<html><head><title>'+ title +'</title><style type="text/css">body {margin: 0} img {border: 0}</style></head><body>');
	prwobj.document.write('<a href="#" onclick="window.close()"><img src="/img/press/'+ file +'" width="'+ rw +'" height="'+ rh +'" alt="'+ title +'" /></a>');
	prwobj.document.write('</body></html>');
	prwobj.document.close();
	return true;
}








function init_chat(room, show, type) {
	chat_room = room;
	chat_show = show;
	chat_type = type;
}

function show_chat() {
	show_chat_form(chat_show);
	show_chat_msgs(chat_show);
	show_chat_type(chat_show);
	if (chat_show) chat_fresh();
}

function show_chat_support() {
	show_chat_form(chat_show);
	show_chat_msgs(chat_show);
	show_chat_supporttype(chat_show);
	if (chat_show) chat_fresh();
}

function show_livechat() {
	show_chat_form(chat_show);
	show_chat_msgs(chat_show);
	show_chat_livetype(chat_show);
	if (chat_show) chat_fresh();
}


function show_chat_form(show) {
	document.write('<form action="#" onsubmit="chat_sendit(); return false" id="online-chat-form"'+ (!show ? ' style="display:none"' : '') +'>');
	document.write('		<label for="entrytext">msg: </label>');
	document.write('		<input type="text" name="entrytext" maxlength="200" id="entrytext" value="" class="entrytext" />');
	document.write('		<input type="submit" value="send" class="t-button" />');
	document.write('</form>');
	if (show) document.getElementById("entrytext").focus();
}

function show_chat_msgs(show) {
	document.write('<div id="online-chat-msgs" class="myscroll"'+ (!show ? ' style="display:none"' : '') +'>');
	document.write('</div>');
}

function show_chat_type(show) {
	document.write('<div id="online-chat-type-shown"'+ (!show ? ' style="display:none"' : '') +'>');
	document.write('<a id="online-chat-type-all" href="#"'+ (chat_type == 0 ? ' class="act"' : '') +' onclick="return !chat_type_all()">all rooms</a>');
	document.write('<a id="online-chat-type-one" href="#"'+ (chat_type == 1 ? ' class="act"' : '') +' onclick="return !chat_type_one()">only this room</a>');
	document.write('<a href="#" class="right" onclick="return !chat_close()">hide chat</a>');
	document.write('</div>');
	document.write('<div id="online-chat-type-hidden"'+ (show ? ' style="display:none"' : '') +'>');
	document.write('<a href="#" class="open" onclick="return !chat_open()">show chat</a>');
	document.write('</div>');
}
function show_chat_supporttype(show) {
	document.write('<div id="online-chat-type-shown">');
	document.write('</div>');
}
function show_chat_livetype(show) {
	document.write('<div id="online-chat-type-shown"'+ (!show ? ' style="display:none"' : '') +'>');
	document.write('<a id="online-chat-type-all" href="#"'+ (chat_type == 0 ? ' class="act"' : '') +' onclick="return !chat_type_all()">verejne se vsemy</a>');
	document.write('<a id="online-chat-type-one" href="#"'+ (chat_type == 1 ? ' class="act"' : '') +' onclick="return !chat_type_one()">soukrome s divkou</a>');
	document.write('</div>');
}



function nothing() {}

function chat_close() {
	chat_show = 0;
	document.getElementById('online-chat-msgs').style.display = "none";
	document.getElementById('online-chat-form').style.display = "none";
	document.getElementById('online-chat-type-shown').style.display = "none";
	document.getElementById('online-chat-type-hidden').style.display = "block";
	window.clearTimeout(chat_timeout);
	send_xmlhttprequest(nothing, 'GET', 'chat.php?set_show=0');
	return true;
}

function chat_open() {
	chat_show = 1;
	document.getElementById('online-chat-msgs').style.display = "block";
	document.getElementById('online-chat-form').style.display = "block";
	document.getElementById('online-chat-type-shown').style.display = "block";
	document.getElementById('online-chat-type-hidden').style.display = "none";
	chat_fresh();
	send_xmlhttprequest(nothing, 'GET', 'chat.php?set_show=1');
	return true;
}

function chat_type_all() {
	chat_type = 0;
	document.getElementById('online-chat-type-all').className = "act";
	document.getElementById('online-chat-type-one').className = "";
	chat_fresh();
	send_xmlhttprequest(nothing, 'GET', 'chat.php?room='+ chat_room +'&set_type=0');
	return true;
}

function chat_type_one() {
	chat_type = 1;
	document.getElementById('online-chat-type-all').className = "";
	document.getElementById('online-chat-type-one').className = "act";
	chat_fresh();
	send_xmlhttprequest(nothing, 'GET', 'chat.php?room='+ chat_room +'&set_type=1');
	return true;
}






function send_xmlhttprequest(obsluha, method, url, content, headers) {
	var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
	if (!xmlhttp) return false;
	xmlhttp.open(method, url);
	xmlhttp.onreadystatechange = function() {
		obsluha(xmlhttp);
	};
	if (headers) {
		for (var key in headers) {
			xmlhttp.setRequestHeader(key, headers[key]);
		}
	}
	xmlhttp.send(content);
	return true;
}

function chat_showit(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		document.getElementById('online-chat-msgs').innerHTML = xmlhttp.responseText;
	}
}

function chat_fresh() {
	if (chat_show) {
		url = 'chat.php?fresh=1&room='+ chat_room +'&type='+ chat_type;
		if (!send_xmlhttprequest(chat_showit, 'GET', url)) return false;
		chat_warp(10000);
	}
	return true;
}




function chat_sendit() {
	str = document.getElementById("entrytext").value;
	if (str) {
		if (!send_xmlhttprequest(chat_sended, 'GET', 'chat.php?room='+ chat_room +'&send_text='+ escape(str))) return false;
	}
	return true;
}
function chat_sended() {
	document.getElementById("entrytext").value = '';
	document.getElementById("entrytext").focus();
	chat_warp(100);
	return true;
}

function chat_warp(time) {
	if (chat_timeout) window.clearTimeout(chat_timeout);
	chat_timeout = window.setTimeout("chat_fresh()", time);
}








function live_picture_fresh_start() {
	window.setTimeout("live_picture_fresh()", 9000); // 200000
}
function live_picture_fresh() {
	obj = document.getElementById("room-livescreen-"+ lpf[lpfcurr]);
	obj.src = '/img/livescreen/'+ lpf[lpfcurr] +'_s.jpg?nocache='+ Math.floor(Math.random()*99999);
	lpfcurr++;
	if (!lpf[lpfcurr]) lpfcurr = 0;
	window.setTimeout("live_picture_fresh()", 9000); // 200000
}



function liveroom_fresh_start() {
	liveroom_fresh_warp();
}

function liveroom_fresh_showit(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		data = xmlhttp.responseText.split('|', 2);
		document.getElementById('live-room-data').innerHTML = data[1];
		if (data[0] != liveroom_fresh_type) {
			vo = document.getElementById('videoobject');
			vohtml = vo.innerHTML;
			vo.innerHTML = vohtml;
			liveroom_fresh_type = data[0];
		}
	}
}

function liveroom_fresh() {
	url = 'liveroom.php?room='+ liveroom_fresh_room;
	if (!send_xmlhttprequest(liveroom_fresh_showit, 'GET', url)) return false;
	liveroom_fresh_warp();
	return true;
}


var liveroom_fresh_timeout;
function liveroom_fresh_warp() {
	if (liveroom_fresh_timeout) window.clearTimeout(liveroom_fresh_timeout);
	liveroom_fresh_timeout = window.setTimeout("liveroom_fresh()", 20000); // 53000
}
