var Notifications={lock:{status:false,set:function(){Notifications.lock.status=true;window.setTimeout("Notifications.lock.open()",3000)},open:function(){Notifications.lock.status=false}},init:function(){var a=4000;if(document.getElementById("noSystem")){a=10000}else{if(document.getElementById("noBanner")){a=7000}}window.setTimeout("Notifications.read(false)",a);Contacts.init()},status:0,jobs:{timeline:0,progress:null,list:[5,5,5,5,5,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,12,12,12,12,12,12,12,15,15,15,15,15,20,20,20,20,20,20,30,30,30,60],getNextJobTimestamp:function(){if(Notifications.jobs.timeline<42){return this.list[this.timeline]*1000}else{Notifications.enableReturn.offer()}}},addRequest:function(){if(this.status==0){if(this.jobs.progress==null){var a=this.jobs.getNextJobTimestamp();this.jobs.progress=window.setTimeout("Notifications.read(false)",a);this.jobs.timeline++}}else{if(this.status==1){this.enableReturn.offer()}else{return false}}},enableReturn:{offer:function(){window.setTimeout("Notifications.enableReturn.observe()","6000")},observe:function(){document.onmousemove=function(){Notifications.enableReturn.restart()}},restart:function(){document.onmousemove=null;var a=new AjaxHandler();var b={json:true,success:function(c){if(c==1){Notifications.status=0;Notifications.read(true)}}};a.request("GET","/backend/setToken.php?h="+User.hash+"&token="+Jpy.token,b)
}},read:function(a){Notifications.jobs.progress=null;if(Notifications.lock.status!=true||a==true){var c={success:function(h){if(typeof(h)=="undefined"||h<0){return}else{if(h==0){Notifications.status=1;Notifications.addRequest()}else{if(h==null){return}if(h.nm){if(h.nm!=Notifications.newMails){if(document.getElementById("nvMailboxCounter")){Jpy.id("nvMailboxCounter").innerHTML=h.nm}else{var j=DOM.span({id:"nvMailboxCounter",className:"newEntries rb5 ml5",text:h.nm});var i=Jpy.id("nvMailbox");if(i&&i.childNodes&&i.childNodes[0]){i.insertBefore(j,i.childNodes[0])}}if(!Jpy.isActiveTab){if(!Notifications.currentDocumentTitle){Notifications.currentDocumentTitle=document.title}var f="["+h.nm+"] "+Notifications.currentDocumentTitle;if(Notifications.documentTitleIntervalId){clearInterval(Notifications.documentTitleIntervalId);Notifications.documentTitleIntervalId=null;document.title=Notifications.currentDocumentTitle}Notifications.documentTitleIntervalId=setInterval(function(){document.title=(document.title==f?Notifications.currentDocumentTitle:f)},1000);var g=function(){if(Notifications.documentTitleIntervalId){clearInterval(Notifications.documentTitleIntervalId);Notifications.documentTitleIntervalId=null}if(Notifications.currentDocumentTitle){document.title=Notifications.currentDocumentTitle;Notifications.currentDocumentTitle=null
}Jpy.removeEvent(window,"mousemove",g)};Jpy.removeEvent(window,"mousemove",g);Jpy.addEvent(window,"mousemove",g);var d=function(){if(Notifications.jobs.timeline>=42){g()}window.setTimeout(function(){d()},3000)};window.setTimeout(function(){d()},3000)}if(!Notifications.MessageStreamPreview){Notifications.MessageStreamPreview=new MessageStreamPreview()}Notifications.MessageStreamPreview.get()}Notifications.newMails=h.nm}else{Jpy.remove("nvMailboxCounter");if(Notifications.newMails!=0){if(!Notifications.MessageStreamPreview){Notifications.MessageStreamPreview=new MessageStreamPreview()}Notifications.MessageStreamPreview.get()}Notifications.newMails=0}Notifications.addRequest();Notifications.lock.set();if(h.ngb>User.newGB){var e;if(document.getElementById("nvGuestbook")){e=Jpy.id("nvGuestbook").getElementsByTagName("span")[0]}else{e=Jpy.id("nvAddTab").getElementsByTagName("span")[0]}e.innerHTML=h.ngb;e.className="newEntries";User.newGB=h.ngb}if(h.ofh!=User.friendsHash){User.friendsHash=h.ofh;Contacts.getContactsOnline()}if(h.msc){if(Jpy.id("mainStreamBar")==undefined){Jpy.id("nvOverview").innerHTML="<span class='newEntries'>"+h.msc+"</span> Übersicht"}}if(Notifications.newMails>0){if(Notifications.jobs.timeline==6||Notifications.jobs.timeline==12||Notifications.jobs.timeline==30){window.setTimeout("Notifications.MessageStreamPreview.get()",2000)
}}if(h.ma&&h.ma>0){Notifications.showMessageAnonymousHint()}if(h.ta){if(document.getElementById("taAddEntryTextarea")){TickerStartPage.updateTickerEntriesAndComments()}}if(h.lastProfileVisitorId){User.lastProfileVisitorId=h.lastProfileVisitorId}if(typeof(MainStream)!="undefined"){if(h.ms){MainStream.update(h.ms)}else{if(h.msc){MainStream.updateGlobalCounter(h.msc)}}}}}}};var b=Jpy.backend+"/getNotification.php";b+="?token="+Jpy.token;if(window.location.pathname.search("^/(start)?$")!=-1){b+="&lastUpdateCounter="+MainStream.lastUpdateCounter}b+="&lastProfileVisitorId="+User.lastProfileVisitorId;new Jsonp().get(b,c)}},newMails:0};var DesktopNotifications=function(){};DesktopNotifications.prototype.cache={};DesktopNotifications.prototype.requestPermission=function(a){var b=this;if(window.webkitNotifications&&window.webkitNotifications.checkPermission()!=0){window.webkitNotifications.requestPermission(function(){if(window.webkitNotifications.checkPermission()==0){SystemMessage.success("Die Funktion wurde nun aktiviert. Zum Deaktivieren benutze bitte die Einstellungen deines Browsers.");try{Jpy.remove(a)}catch(c){}if(Jpy.id("desktopNotificationOptions")){b.prepareSettings()}}else{SystemMessage.inline.error("Die Erlaubnis wurde nicht erteilt!")}})}};DesktopNotifications.prototype.show=function(i,d,k,n,c,f,l){if(!window.webkitNotifications||window.webkitNotifications.checkPermission()!=0){return
}if(!this.settingEnabled(c)){return}var m=Jpy.picurl+"/i/ge/Kb.gif";if(i){if(d){m=Jpy.profilimageUrl+"/ub/xs/"+d+"/"+i}else{m=Jpy.profilimageUrl+"/ub/xs/"+i}}var j="localStorage" in window&&window.localStorage!==null;if(j){var b=localStorage.getItem("DesktopNotifications:"+User.id+":"+c);this.cache=ParseJSON(b);delete (b);if(!this.cache){this.cache={}}}if(!this.cache[c+":"+f]){if(!Jpy.isActiveTab){var h=window.webkitNotifications.createNotification(m,k,n);window.setTimeout(function(){try{h.cancel()}catch(o){}},90000);var e=function(){try{h.cancel()}catch(o){}Jpy.removeEvent(window,"focus",e)};Jpy.removeEvent(window,"focus",e);Jpy.addEvent(window,"focus",e);var a=function(){try{h.cancel()}catch(o){}};Jpy.removeEvent(window,"leave",a);Jpy.addEvent(window,"leave",a);var g=window;h.onclick=function(){if(g&&g.focus){if(c=="Mail"&&l){if(User.mailboxView==1){new MessageStream().showMail(l.userId,l.id)}else{new MessageStream().showMessages(l.userId)}}g.focus()}try{h.cancel()}catch(o){}};h.show()}this.cache[c+":"+f]=1;if(j){localStorage.setItem("DesktopNotifications:"+User.id+":"+c,EncodeJSON(this.cache))}}};DesktopNotifications.prototype.switchSettingsButton=function(a,b){if(b=="off"){a.className="swOff";a.innerHTML="Aus"}else{a.className="swOn";a.innerHTML="An"}};DesktopNotifications.prototype.settingEnabled=function(b){var a=localStorage.getItem("DesktopNotifications:"+b+":"+User.id);
if(b=="Mail"){if(!a||a!=1){return true}return false}if(a==1){return true}return false};DesktopNotifications.prototype.prepareSettings=function(){if(!Jpy.id("desktopNotificationOptions")){return}if(!Jpy.hasLocalStorage()){Jpy.hide("desktopNotificationOptions");return}var b=null;var c=this;var a=Jpy.id("desktopNotificationMail");if(a){b=localStorage.getItem("DesktopNotifications:Mail:"+User.id);if(!b||b!=1){this.switchSettingsButton(a,"on");(function(d){d.parentNode.onclick=function(){c.switchOff(d,"Mail")}})(a)}else{this.switchSettingsButton(a,"off");(function(d){d.parentNode.onclick=function(){c.switchOn(d,"Mail")}})(a)}}a=Jpy.id("desktopNotificationTicker");if(a){b=localStorage.getItem("DesktopNotifications:Ticker:"+User.id);if(b==1){this.switchSettingsButton(a,"on");(function(d){d.parentNode.onclick=function(){c.switchOff(d,"Ticker")}})(a)}else{this.switchSettingsButton(a,"off");(function(d){d.parentNode.onclick=function(){c.switchOn(d,"Ticker")}})(a)}}a=Jpy.id("desktopNotificationFlog");if(a){b=localStorage.getItem("DesktopNotifications:Flog:"+User.id);if(b==1){this.switchSettingsButton(a,"on");(function(d){d.parentNode.onclick=function(){c.switchOff(d,"Flog")}})(a)}else{this.switchSettingsButton(a,"off");(function(d){d.parentNode.onclick=function(){c.switchOn(d,"Flog")}})(a)}}Jpy.show("desktopNotificationOptions")
};DesktopNotifications.prototype.switchOff=function(a,c){if(c=="Mail"){localStorage.setItem("DesktopNotifications:"+c+":"+User.id,1)}else{localStorage.setItem("DesktopNotifications:"+c+":"+User.id,0)}this.switchSettingsButton(a,"off");var b=this;a.parentNode.onclick=function(){b.switchOn(a,c)}};DesktopNotifications.prototype.switchOn=function(a,c){if(c=="Mail"){localStorage.setItem("DesktopNotifications:"+c+":"+User.id,0)}else{localStorage.setItem("DesktopNotifications:"+c+":"+User.id,1)}this.switchSettingsButton(a,"on");var b=this;a.parentNode.onclick=function(){b.switchOff(a,c)}};if(!SystemMessage){var SystemMessage={}}SystemMessage.desktop=new DesktopNotifications();
