
if(!window.console||!console.firebug)
{var names=['log','debug','info','warn','error','assert','dir','dirxml','group','groupEnd','time','timeEnd','count','trace','profile','profileEnd'];window.console={};for(var i=0;i<names.length;++i)
window.console[names[i]]=function(){}}
JabberPresence={defaults:{handler:'presence',host:null,id:null,idtype:'jid',parsexml:false,port:5280,refresh:30,ssl:false,theme:null,useAvatar:false},main:function(options){JabberPresence.opts=jQuery.extend({},JabberPresence.defaults,options);console.group('JabberPresence');console.log("Options parsed as: %o",JabberPresence.opts);var timer=typeof jQuery.fn.everyTime=='function';if(!JabberPresence.opts.host){console.log("%s","Host endpoint is undefined, not doing anything.");return;}
if(!JabberPresence.opts.id){console.log("%s",JabberPresence.opts.type+" is undefined, not doing anything.");return;}
JabberPresence.updatePage(this);if(JabberPresence.opts.refresh>0&&timer){this.everyTime(JabberPresence.opts.refresh*1000,function(){JabberPresence.updatePage(this);},0,true);}
console.groupEnd();return jQuery;},updatePage:function(obj){var uri=JabberPresence.buildURI('xml');var imgurl=JabberPresence.opts.useAvatar?JabberPresence.buildURI('avatar'):JabberPresence.buildURI('image')+'?nocache='+Math.random();if(JabberPresence.opts.parsexml===false){JabberPresence.formatter(obj,imgurl,'','');return;}
jQuery.ajax({type:'GET',url:uri,cache:false,dataType:'xml',processData:true,success:function(xml){var resources=jQuery(xml).find('resource');var state='';var message='';if(resources.length===0){state='offline';}
else{var resource=resources.eq(0);state=resource.attr('show');message=resource.text()||state;}
console.log('Current XMPP status: %s (%s)',state,message);JabberPresence.formatter(obj,imgurl,state,message);}});},buildURI:function(kind){var uri=JabberPresence.opts.ssl?'https://':'http://';uri=uri+JabberPresence.opts.host+':'+JabberPresence.opts.port+'/'+JabberPresence.opts.handler+'/';if(JabberPresence.opts.idtype=='rid'){uri=uri+'rid/'+JabberPresence.opts.id;}
else{var id=JabberPresence.opts.id.replace('@','/');uri=uri+'jid/'+id+'/';}
if(kind=='image'){if(!JabberPresence.opts.theme){uri=uri+'image';}
else{uri=uri+'image/theme/'+JabberPresence.opts.theme;}}
else{uri=uri+kind;}
return uri;},formatter:function(obj,imageurl,state,message){jQuery('<img />').attr('src',imageurl).attr('alt','XMPP status').attr('title',message).removeClass().addClass(state).load(function(){$(obj).html(this)});}};jQuery.fn.JabberPresence=JabberPresence.main;