function pChatSend(tid){var msg = $("#chatInput_"+tid).val();if(msg && msg != "Enter a Message ...")$.getJSON("/private.html?act=chat.send&tid="+tid+"&msg="+msg,function(f){pChatAdd(tid,f.msg,pSelfIcon,pSelfName,1);});}
function pChatAdd(tid,msg,icon,name,self){var css = (self)?'Me':'You';if(self) $('#chatInput_'+tid).val('').focus();$("#chatDialog_"+tid).append($('<li></li>').html('<img src="'+icon+'"> <b class="chat'+css+'">'+name+':</b> <span>'+msg+'</span><br/>')).parent().animate({'scrollTop':$("#chatDialog_"+tid).parent().attr("scrollHeight")},'slow');}
function pChatWhosOnline(){
	$.getJSON("/private.html?act=chat.whos.online",function(f){
		$('#chatWhosOnline').html((f.whosOnline)?f.whosOnline:'<li><i>no one online</i></li>');
		$('#chatListCounter').html((f.whosOnlineCount != undefined)?"("+f.whosOnlineCount+")":"(0)");
		if(f.convos && f.convos.length > 0){
			for(i=0;i<f.convos.length;i++) if(!$('#chatDialog_'+f.convos[i]).html()) pChatStart(f.convos[i]);
		}
	});
}
function pChatListShow(){if(pChatListOpen) pChatListHide();else {pChatListOpen=1;$('#chatListData').slideDown();}}
function pChatListHide(){$('#chatListData').slideUp();pChatListOpen=0;}
function pChatClose(pid){$('#pChat_'+pid).remove();$.getJSON("/private.html?act=chat.close&pid="+pid);if(pChatShown == pid) pChatShown = 0;}
function pChatPing(pid){if(!pChatLasts[pid]) pChatLasts[pid] = 0;window.setInterval(function(){$.getJSON('/private.html?act=chat.ping&last='+pChatLasts[pid]+'&pid='+pid,function(f){pChatLasts[pid] = f.last;if(f.msg){pChatAdd(pid,f.msg,f.icon,f.name);if($("#chatLog_"+pid).is(':hidden')) $('#pChat_'+pid+' > span.chatPerson').attr({'class':'chatPerson new'});}});},10000);}
function pChatHide(pid){$('#chatLog_'+pid).slideUp('slow');$('#pChat_'+pid+' > span.chatPerson').attr({'style':'backgroundColor:transparent;'});if(pChatShown == pid) pChatShown = 0;}
function pChatShow(pid,silent,hl){$("#pChat_"+pid+">span.chatPerson").removeClass().addClass('chatPerson');if(pChatShown != pid){if(pChatShown) pChatHide(pChatShown);if(!silent){pChatShown = pid;$('#chatLog_'+pid).addClass('chatLog').slideDown();$('#pChat_'+pid+' > span.chatPerson').attr({'style':'background-color:#fff;'});}if(!$('#chatLog_'+pid).html()){$('#chatLog_'+pid).html($('#chatLog_Loading').html());$.getJSON("/private.html?act=chat.load.recent&tid="+pid,function(f){$('#chatLog_'+pid).html(f.html);pChatLasts[pid] = f.last;window.setTimeout(function(){$('#chatDialog_'+pid).parent().animate({'scrollTop':$("#chatDialog_"+pid).parent().attr("scrollHeight")},'slow');},350);$('#chatInput_'+pid).focus();pChatPing(pid);if(hl) $('#pChat_'+pid+' > span').removeClass().addClas('chatPerson new');});} else $('#chatDialog_'+pid).parent().animate({'scrollTop':$("#chatDialog_"+pid).parent().attr("scrollHeight")},'slow');} else {pChatShown = 0;pChatHide(pid);}}
function pChatStart(pid,silent){pChatListHide(); if(!silent) silent = 0; if($('#pChat_'+pid).html()) pChatShow(pid); else $.getJSON("/private.html?act=chat.start&pid="+pid,function(f){if(f.icon){$('#activeChats').append($('<li></li>').addClass('person').attr({'id':'pChat_'+pid}).html("<div id=\"chatLog_"+pid+"\" class=\"hide\"></div><span class=\"chatPerson\"><div onclick=\"pChatShow("+pid+");\" class=\"person\"><img src=\""+f.icon+"\"> "+f.name+"</div><div class=\"closer\" onclick=\"pChatClose("+pid+");\"></div></span><br/>"));pChatShow(pid,silent);}});}
function initMenuBar(){$("#menuBarButtons > li > a").each(function(index){coolTitle(this);});}
function coolTitle(obj,ec){$(obj).append($('<div></div>').addClass('hide').html($(obj).attr('title'))).hover(function(){$('div',this).removeClass().addClass('titleBlurb '+ec);},function(){$('div',this).removeClass().addClass('hide');});}

var pcp;
pcp = window.setInterval(pChatWhosOnline,25000);