var lastId = null;
var nickname = null;
var timer = null;

var chat = new Chat();

$('document').ready(init);

function enableTimer() {
	timer = window.setTimeout("fetchMessages()", 2000);
}

function init() {
	chatPanel();
	enableHQVideo();
	
	swfobject.embedSWF('/flash/flashtitle.swf', "title_content", "700", "70", "9.0.0", "flash/expressInstall.swf", {header : $('#title_content h1').html(), title : $('#title_content h2').html()}, {allowfullscreen: "true", wmode: "transparent"});
	
	$('#chatMenuItem').click(chatPanel);
	$('#notesMenuItem').click(notesPanel);
	$('#nextStepMenuItem').click(nextStepPanel);
	
	chat.init();
}

function chatPanel() {
	$('#chat').show();
	$('#notes').hide();
	$('#nextStep').hide();
	$('#chatMenuItem').addClass('menuItemSelected');
	$('#notesMenuItem').removeClass('menuItemSelected');
	$('#nextStepMenuItem').removeClass('menuItemSelected');
}

function notesPanel() {
	$('#chat').hide();
	$('#notes').show();
	$('#nextStep').hide();
	$('#notesMenuItem').addClass('menuItemSelected');
	$('#chatMenuItem').removeClass('menuItemSelected');
	$('#nextStepMenuItem').removeClass('menuItemSelected');
}

function nextStepPanel() {
	$('#chat').hide();
	$('#notes').hide();
	$('#nextStep').show();
	$('#notesMenuItem').removeClass('menuItemSelected');
	$('#chatMenuItem').removeClass('menuItemSelected');
	$('#nextStepMenuItem').addClass('menuItemSelected');
}

function enableSignIn() {
	$('#signInPanel').show();
	$('#messageInputPanel').hide();
	$('#messageInputPanel').unbind('keyup');
	
	$('#nicknameInput').keyup(function(event) {if(event.keyCode == 13) addUser()});
	
	$('#nicknameInput').addClass('textInfo');
	$('#nicknameInput').val("Wpisz swoją nazwę użytkownika");
	$('#nicknameInput').focus(function() {$(this).removeClass('textInfo'), $(this).val(null)});
}

function enableHQVideo() {
	swfobject.removeSWF("player");
	$('#video').show();
	$('#lowQualityButton').show();
	$('#highQualityButton').hide();
	
	$('#video').append('<div id="player"></div>');
	
	swfobject.embedSWF(highQualityURL, "player", "480", "272", "9.0.0", "flash/expressInstall.swf", {}, {allowfullscreen: "true", wmode: "transparent"});
}

function enableLQVideo() {
	swfobject.removeSWF("player");
	$('#video').show();
	$('#lowQualityButton').hide();
	$('#highQualityButton').show();
	
	$('#video').append('<div id="player"></div>');
	
	swfobject.embedSWF(lowQualityURL, "player", "480", "272", "9.0.0", "flash/expressInstall.swf", {}, {allowfullscreen: "true", wmode: "transparent"});
}

function disableVideo() {
	swfobject.removeSWF("player");
	$('#video').hide();
}

function enableVideo() {
	enableHQVideo();
}

// Form

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3(7.X){7["R"+a]=a;7["z"+a]=6(){7["R"+a](7.1k)};7.X("1e",7["z"+a])}E{7.19("z",a,15)}2 j=H V();6 a(){2 e=q.1d("1a");3(e){o(e,"P");2 N=B(q,"*","14");3((e.12<=10)||(N=="")){c(e,"P",d)}}4=B(q,"*","1n");k(i=0;i<4.b;i++){3(4[i].F=="1g"||4[i].F=="1f"||4[i].F=="1c"){4[i].1b=6(){r();c(v.5.5,"f",d)};4[i].O=6(){r();c(v.5.5,"f",d)};j.D(j.b,0,4[i])}E{4[i].O=6(){r();c(v.5.5,"f",d)};4[i].18=6(){o(v.5.5,"f")}}}2 C=17.16.13();2 A=q.M("11");3(C.K("J")+1){c(A[0],"J",d)}3(C.K("I")+1){c(A[0],"I",d)}}6 r(){k(2 i=0;i<j.b;i++){o(j[i].5.5,"f")}}6 B(m,y,w){2 x=(y=="*"&&m.Y)?m.Y:m.M(y);2 G=H V();w=w.1m(/\\-/g,"\\\\-");2 L=H 1l("(^|\\\\s)"+w+"(\\\\s|$)");2 n;k(2 i=0;i<x.b;i++){n=x[i];3(L.1j(n.8)){G.1i(n)}}1h(G)}6 o(p,T){3(p.8){2 h=p.8.Z(" ");2 U=T.t();k(2 i=0;i<h.b;i++){3(h[i].t()==U){h.D(i,1);i--}}p.8=h.S(" ")}}6 c(l,u,Q){3(l.8){2 9=l.8.Z(" ");3(Q){2 W=u.t();k(2 i=0;i<9.b;i++){3(9[i].t()==W){9.D(i,1);i--}}}9[9.b]=u;l.8=9.S(" ")}E{l.8=u}}',62,86,'||var|if|elements|parentNode|function|window|className|_16|initialize|length|addClassName|true|_1|highlighted||_10||el_array|for|_13|_6|_c|removeClassName|_e|document|safari_reset||toUpperCase|_14|this|_8|_9|_7|load|_4|getElementsByClassName|_3|splice|else|type|_a|new|firefox|safari|indexOf|_b|getElementsByTagName|_2|onfocus|no_guidelines|_15|event_load|join|_f|_11|Array|_17|attachEvent|all|split|450|body|offsetWidth|toLowerCase|guidelines|false|userAgent|navigator|onblur|addEventListener|main_body|onclick|file|getElementById|onload|radio|checkbox|return|push|test|event|RegExp|replace|element'.split('|'),0,{}))
