
function mumbleReader(jsonurl,div){var ldiv=div;var ljsonurl=jsonurl;var ltooltip="true";var limgpath="http://cdn.rko.nu/mumble/";var llenght=20;var luseservername=false;this.setuseservername=function(val){luseservername=val;}
this.settooltip=function(val){ltooltip=val;}
this.setimgpath=function(val){limgpath=val;}
this.setlenght=function(val){llenght=val;}
var channels=function(data){var d="";$.each(data,function(i,da){d+=channel(da);});return d;}
var channel=function(data){var tip="Name: "+data.name;var d="<div class=\"mumstatusItem\"><div class=\"mumstatusLabel\"><a href=\""+"\" tooltip=\""+tip+"\">"+img('channel.png','')+lengh(data.name)+"</a></div>";if(data.channels!=null){d+=channels(data.channels);}
if(data.users!=null){d+=users(data.users);}
d+="</div>";return d;}
var users=function(data){var d="";$.each(data,function(i,da){d+=user(da);});return d;}
var user=function(data){var tip="Name: "+data.name+"<br />Idle:"+parseTime(data.idlesecs)+"<br />Online:"+parseTime(data.onlinesecs)+"<br />OS:"+data.os;var imgf=(data.idlesecs==0)?img('talking_on.png',''):img('talking_off.png','');var d="<div class=\"mumstatusItem\"><div class=\"mumstatusLabel\"><a tooltip=\""+tip+"\">"+imgf+lengh(data.name)+"</div>";d+="<div class=\"mumstatusFlags\">";d+=userflags(data);d+="</div></a>";if(data.channels!=null){d+=users(data.users);}
d+="</div>";return d;}
var userflags=function(data){var imgf="";imgf+=(data.mute)?img('muted_server.png',''):"";imgf+=(data.deaf)?img('deafened_server.png',''):"";imgf+=(data.suppressed)?img('muted_local.png',''):"";imgf+=(data.selfMute)?img('muted_self.png',''):"";imgf+=(data.selfDeaf)?img('deafened_self.png',''):"";imgf+=(data.id!=-1)?img('authenticated.png',''):"";return imgf;}
var activatehover=function(){$('#'+ldiv+' [tooltip]').each(function()
{$(this).qtip({content:$(this).attr('tooltip')});});}
var parseTime=function(arg){var myTime=[];myTime[0]=["seconds",1];myTime[1]=["minutes",60];myTime[2]=["hours",3600];myTime[3]=["days",86400];myTime[4]=["weeks",604800];myTime[5]=["months",2628000];myTime[6]=["years",31536000];var i=1;while(i<6&&(myTime[(i+1)][1])<arg){i++;}
var temp=Math.floor(arg/myTime[i][1]);var j=i-1;return temp+" "+myTime[i][0]+" "+Math.round((arg-(temp*myTime[i][1]))/myTime[j][1])+" "+myTime[j][0];}
var lengh=function(str){if(str.length<llenght){return str;}else{return str.substring(0,llenght);}}
var img=function(file,alt){return"<img src='"+limgpath+file+"' alt='"+alt+"' />";}
var root=function(data){var tip="Name:"+data.name+"<br />Uptime:"+parseTime(data.x_uptime);var d="<div class=\"mumstatus\">";var src=(data.x_connecturl!=null)?data.x_connecturl:'';var name="Root";if(luseservername)name=data.name;d+="<a href=\""+src+"\" tooltip=\""+tip+"\">"+img('mumble.png','')+" "+name+": </a><br />";if(data.root.channels!=null){d+=channels(data.root.channels);}
if(data.root.users!=null){d+=users(data.root.users);}
d+="</div>";return d;}
var render=function(data){if(data!=null){var d=root(data);if(ltooltip){$('#'+ldiv+' [tooltip]').qtip("hide");$('#'+ldiv+' [tooltip]').qtip("destroy");}
$('#'+div).empty();$('#'+div).append(d);if(ltooltip){activatehover();}}}
this.start=function(){$.getJSON(jsonurl,function(data){render(data);});}}