(function(a){a.comet=function(b,c){a.comet.callbacks[b]=c};a.comet.onReadyCBs=new Array();a.comet.callbacks={};a.comet.shouldBeAlive=true;a.comet.currentPoll=undefined;a.comet.onReady=function(b){if(a.comet.id){b()}a.comet.onReadyCBs.push(b)};a.comet.init=function(d,b,f,e,c){a.comet.baseURL=d;a.comet.listeners=c||[];if(!e){e=function(g,i,h){if(console&&console.debug){console.debug("Init failed: "+g.responseText);console.debug(h)}}}if(f){a.comet.onReady(f)}a.comet.call({method:"start",data:b,success:function(h){a.comet.currentPoll=undefined;if(h.success){a.comet.id=h.uuid;for(var g=0;g<a.comet.onReadyCBs.length;g++){a.comet.onReadyCBs[g](h)}a.comet.poll()}else{falCallback()}},error:function(g,i,h){a.comet.currentPoll=undefined;e(g,i,h)}})};a.comet.poll=function(c){if(c===undefined){c=-1}if(a.comet.currentPoll){try{a.comet.currentPoll.abort()}catch(b){}}a.comet.currentPoll=a.comet.call({method:"poll",data:{ack:c},success:a.comet.messages,error:function(){if(a.comet.shouldBeAlive){setTimeout(a.comet.poll,2000)}}})};a.comet.call=function(b){b.cache=false;b.dataType="json";b.type="post";if(!b.data){b.data={}}b.data["id"]=a.comet.id;if(!b.url&&b.method){b.url=a.comet.baseURL+"/"+b.method}if(!b.error){b.error=a.fn.glchat.output}return a.ajax(b)};a.comet.messages=function(b){var c=b.messages;a.each(c,function(e,g){for(var d=0;d<a.comet.listeners.length;d++){var f=a.comet.listeners[d];f(g)}var h=a.comet.callbacks[g.key];if(h){h(g)}});setTimeout(function(){a.comet.poll(b.seq)},10)};a.comet.shutdown=function(){a.comet.shouldBeAlive=false;if(a.comet.currentPoll){try{a.comet.currentPoll.abort()}catch(b){}a.comet.currentPoll=undefined}}})(jQuery);$(function(){$(window).bind("beforeunload",$.comet.shutdown);$(window).unload($.comet.shutdown)});
