
(function($){var $document=$(document),iframe,hash='',needHistoryAdd=/MSIE/.test(navigator.userAgent),afterHistoryRead=false,afterHistoryAdd=false;function check(){if(hash!=(hash=document.location.hash)){if(!afterHistoryRead&&needHistoryAdd)historyAdd(hash);afterHistoryRead=false;$document.trigger('hashChange',[hash]);}
setTimeout(check,42);}
function historyAdd(hash){if(!iframe)iframe=$('<iframe style="display:none" src="javascript:false;"></iframe>').appendTo('body')[0];var d=iframe.contentDocument||(iframe.contentWindow?iframe.contentWindow.document:iframe.document);d.open();d.write('<html><head><title>'+document.title+'</title></head><body>');d.write($('<div/>').append($('<div id="hashdiv"></div>').text(hash)).html());d.write('<script>'+'window._hash = document.getElementById("hashdiv").innerText;'+'window.onload = parent._historyRead;'+'</script>');afterHistoryAdd=true;d.close();}
if('onpropertychange'in document&&'attachEvent'in document){document.attachEvent('onpropertychange',function(){if(event.propertyName=='location'){check();}});}
if(needHistoryAdd){window._historyRead=function(){if(!afterHistoryAdd){var newHash=this._hash;if(document.location.hash!=newHash){afterHistoryRead=true;document.location.hash=newHash;}}
afterHistoryAdd=false;};}
$(check);})(jQuery);jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};function getSelectedText(){if(window.getSelection){return window.getSelection()+'';}
else if(document.selection){return document.selection.createRange().text+'';}
return'';}
﻿var PH={timeout:1000,timeoutId:null,lastFeedTimestamp:0,testBannerEl:null,skipTestBanner:false,testBannerTimeoutId:null,feedMod:null,feedJson:function(jd){if(jd['messages']){PH.addMessages(jd.messages);}
if(jd['dialog']){$(jd.dialog['content']).dialog(jd.dialog.options);}},json:function(url,data,options){$.ajax({url:url,data:data,dataType:'json',type:'post',success:function(jd){PH.feedJson(jd);if(options&&options.onsuccess){options.onsuccess.call(jd,jd);}},complete:function(){if(options&&options.oncomplete){options.oncomplete.call();}}});},iframesubmit:function(frm,options){PH.Busy.set(1,'iframesubmit');var iframeId='sFormIframe',iframe=$('<iframe id="'+iframeId+'" name="'+iframeId+'" src="about:blank" style="display:none"></iframe>');frm=$(frm);iframe.appendTo('body');frm.attr('target',iframeId);if('json'in options){var tmpJsonInput=$('#iframesubmitTmpJsonInput');if(!tmpJsonInput[0]){tmpJsonInput=$('<input type="hidden" id="iframesubmitTmpJsonInput" name="json" value="1" />');}
tmpJsonInput.appendTo(frm);}
iframe.load(function(){PH.Busy.set(-1,'iframesubmit');if('about:blank'==iframe[0].contentWindow.document.location.href)return;var html=$(iframe[0].contentWindow.document.body).html();try{if('json'in options){var str=$(iframe[0].contentWindow.document.body).text();var jd=$.parseJSON(str);PH.feedJson(jd);if(options['onsuccess']){options.onsuccess.call(frm,jd);}
$('#iframesubmitTmpJsonInput').remove();}
else{if(options['onsuccess']){var str=$(iframe[0].contentWindow.document.body).html();options.onsuccess.call(frm,str);}}
frm.removeAttr('target');iframe.remove();}
catch(e){}});return true;},jsonsubmit:function(frm,options){frm=$(frm);PH.Busy.set(1);$.ajax({url:frm.attr('action'),data:frm.serialize(),dataType:'json',type:'post',success:function(jd){PH.feedJson(jd);if(options&&options.onsuccess){options.onsuccess.call(frm,jd);}},complete:function(){if(options&&options.oncomplete){options.oncomplete.call();}
PH.Busy.set(-1);}});return true;},jsonlink:function(a,options){a=$(a);if(!options){options={};}
if(!options.success){options.success=function(jd){PH.feedJson(jd);if(options['remove'])a.remove();if(options['onsuccess']){options.onsuccess.call(jd,jd);}}}
$.ajax({url:a.attr('href'),dataType:'json',success:options.success});return true;},addMessage:function(msg,timeout){var li=$('<li>'+msg+'</li>');$('#messages').append(li);if('undefined'==typeof timeout){timeout=5000;}
if(timeout>0){setTimeout(function(){li.slideUp('slow',function(){li.remove()})},timeout);}},addMessages:function(msgs){$.each(msgs,function(k,v){PH.addMessage(v)});},showError:function(error){$('<div class="error">'+error+'</div>').dialog({buttons:{"Ok":function(){$(this).dialog("close");}}});},showErrors:function(errors){$.each(errors,function(k,v){PH.showError(v)});},setMessagesTimeout:function(){var lis=$('#messages').children();setTimeout(function(){lis.slideUp('slow')},5000);},update:function(){$.getJSON(BASE_URL+'feed/update/'+PH.lastFeedTimestamp+'/'+PH.feedMod,function(data){PH.feed(data);});PH.resetTimeout();},feed:function(data){if(data._feed){$.each(data._feed,function(k,v){if('string'==typeof v&&'string'==typeof k){$('#'+k).html(v);}
else if(v._runme){eval(v._runme);}})}
if(this.timeoutId){clearTimeout(this.timeoutId);}},resetTimeout:function(){if(this.timeoutId){clearTimeout(this.timeoutId);}
PH.timeoutId=setTimeout(PH.update,PH.timeout);},collapse:function(el,triggerEl,slide,force){el=$(el);triggerEl=$(triggerEl);var cb=function(){var hidden=el.is(':hidden');triggerEl.toggleClass('collapsed',hidden);$.cookie(el.attr('id')+'_hidden',hidden?1:0);}
if(false!==slide&&0!==slide){switch(force){case 2:el.slideUp(500,cb);break;case 1:el.slideDown(500,cb);break;default:el.slideToggle(500,cb);break;}}
else{switch(force){case 2:el.hide(500,cb);break;case 1:el.show(500,cb);break;default:el.toggle(500,cb);break;}}}}
PH.Busy={_state:0,_namedSet:{},set:function(set,name){if(name){if(!('_busy'+name in this._namedSet)){this._namedSet['_busy'+name]=0;}
this._namedSet['_busy'+name]+=set;}
else{this._state+=set;if(this._state<0){this._state=0;}}
this.refresh();},refresh:function(){var named=0;for(var i in this._namedSet){if('_busy'==i.substring(0,5)){if(this._namedSet[i]>0){named++;}}}
if(named||this._state){$('#busyIndicator').show();}
else{$('#busyIndicator').hide();}}}
PH.Dim={enable:function(options){clearTimeout(PH.Dim.timeout);if(!PH.Dim.dimDiv){PH.Dim.dimDiv=$('<div class="hidden dim"></div>');PH.Dim.dimDiv.message=$('<div class="message"></div>');PH.Dim.dimDiv.appendTo("body");PH.Dim.dimDiv.message.appendTo(PH.Dim.dimDiv);}
if(options.message){PH.Dim.dimDiv.message.text(options.message).show();}
else{PH.Dim.dimDiv.message.hide();}
if(options.cssClass){PH.Dim.dimDiv.attr('class',options.cssClass);}
else{PH.Dim.dimDiv.attr('class','dim');}
if(options.timeout){PH.Dim.timeout=setTimeout(PH.Dim.disable,options.timeout);}
PH.Dim.dimDiv.show();},disable:function(options){if(PH.Dim.dimDiv){PH.Dim.dimDiv.hide();}}}
PH.Comments={_busy:false,objectType:null,objectId:null,refreshUrl:'/comments/refresh/',logged_in:null,setBusy:function(busy){this._busy=busy;if(busy){$('#commentsLoadingIndicator').show();}
else{$('#commentsLoadingIndicator').hide();}},init:function(options){$.extend(this,options);var form=$('#commentForm');;this.commentsWrapper=$('#commentsWrapper');this.captchaValue=$('#captcha_response');if(!this.logged_in){this.captchaWrapper=$('#captchaWrapper');this.token=$('#commentToken');}
this.form=form;form._textarea=$('#commentMessage');form.submit(function(){return PH.Comments.submitCommentForm(form);});form._textarea.bind('keyup',function(e){if(13==e.keyCode&&e.ctrlKey){form.trigger('submit');}});form._textarea.markItUp(mySettings);},refresh:function(data,options){var _this=this;this.setBusy(true);this.refreshUrl='/comments/refresh/'+$('#commentObjectType').val()+'/'+$('#commentObjectId').val();PH.json(this.refreshUrl,data,{onsuccess:function(jd){if(('_replyForm'in _this)){_this._replyForm.detach();}
_this.commentsWrapper.html(jd.html);if(!_this.logged_in){_this.captchaWrapper.html(jd.captcha);_this.token.attr('value',jd.token);_this.captchaValue.attr('value','');}
if(options&&options.onsuccess){options.onsuccess.call(jd,jd);}},oncomplete:function(jd){if(options&&options.oncomplete){options.oncomplete.call(jd,jd);}
_this.setBusy(false);}})},getDeleteForm:function(){if(!('_removeForm'in this)){var _removeForm=$('#commentDeleteForm');_removeForm.submit(function(){return false});_removeForm._commentId=_removeForm.find('#deleteCommentId');this._removeForm=_removeForm;}
return this._removeForm;},submitCommentForm:function(form){if(PH.Comments._busy){return false;}
PH.Comments.refresh(form.serialize(),{onsuccess:function(jd){if(jd.result&&jd.result==1){form._textarea.val('');}},oncomplete:function(){$('#commentsLoadingIndicator').hide();}});return false;},getReplyForm:function(commentId){if(!('_replyForm'in this)){var form=$('#commentReplyForm');form._commentId=form.find('#commentReplyTo');form._textarea=form.find('textarea');form._textarea.markItUp(mySettings);form._textarea.bind('keyup',function(e){if(13==e.keyCode&&e.ctrlKey){form.trigger('submit');}});form.submit(function(){return PH.Comments.submitCommentForm(form);});this._replyForm=form;}
this._replyForm._commentId.val(commentId);return this._replyForm;},remove:function(commentId){var _removeForm=this.getDeleteForm();_removeForm._commentId.val(commentId);_removeForm.dialog({title:'Подтверждение',buttons:{'Удалить':function(){PH.Comments.refresh(_removeForm.serialize(),{onsuccess:function(jd){if('result'in jd){_removeForm.dialog('close');}}});}}}).dialog('open');},reply:function(commentId){var frm=this.getReplyForm(commentId);frm.show().appendTo('#c'+commentId+' > .comment-controls');frm.find('textarea').focus();}}
PH.Report={showForm:function(reportFor,reportForId,container){$.get('/report/form/'+reportFor+'/'+reportForId,null,function(data){if(container){$(container).html(data);}
else{var frm=$(data);frm.dialog();}});}}
PH.invite=function(data){$('#fast_invite_form').hide();$('#fast_invite_wait').show();$.post(base_url+'friends/invite',data,function(data){$('#fast_invite_wait').hide();$('#fast_invite_form').show();$('#fast_invite_succ').html(data.msg).show();document.getElementById('fast_invite_form').reset();clearTimeout(fastInviteTimeout);},'json');fastInviteTimeout=setTimeout(PH.inviteTimeout,60000);}
PH.inviteTimeout=function(){$('#fast_invite_wait').hide();$('#fast_invite_form').show();$('#fast_invite_succ').html('<span style="color:red">При попытке отправить приглашение произошла ошибка.</span>').show();}
PH.clearOnFocus=function(inp){if(!inp._value||inp._value==inp.value){inp._value=inp.value;inp.value='';inp.onblur=function(){PH.resetOnBlur(inp)}
$(inp).removeClass('unchanged');}}
PH.resetOnBlur=function(inp){if(inp._value&&''==inp.value){inp.value=inp._value;inp._value=null;$(inp).addClass('unchanged');}}
PH.Inline={makeInput:function(name,replaceEl,options){replaceEl=$(replaceEl);if(replaceEl.data('_npInlineInput')){replaceEl.hide();replaceEl.data('_npInlineInput').show();return replaceEl.data('_npInlineInput');}
var val=('emptyValue'in options)?(options.emptyValue==replaceEl.text()?'':replaceEl.text()):replaceEl.text();var input=$('<input name="'+name+'" value="'+val+'" />');input.data('_replaceEl',replaceEl);replaceEl.data('_npInlineInput',input);if('submit'in options){input.bind('keyup',function(e){if(13==e.keyCode){options.submit.call(input,input);}});}
replaceEl.after(input).hide();input.show();return input;},autocompleteFriend:function(input){input.autocomplete({source:base_url+'search/suggest/?is_friend=1&self=1&',select:function(e,ui){$(this).val(ui.item.name).data('_np_choice',ui.item.name).data('_np_choice_id',ui.item.id);$('#'+$(this).attr('id')+'_id').val(ui.item.id);}});input.data("autocomplete")._renderItem=function(ul,item){return $('<li></li>').append('<a>'+item.name+'</a>').data("item.autocomplete",item).appendTo(ul);};}}
String.prototype.substitute=function(data){for(r in data){this.replace('{'+r+'}',data[r]);}}
unserialize=function(Data){var Data=Data.split("&");var Serialized=[];$.each(Data,function(){var Properties=this.split("=");Serialized[Properties[0]]=Properties[1];});return Serialized;};PH.unserialize=function(string){var params={},pairs=decodeURIComponent(string).split('&'),pair
for(i=0,len=pairs.length;i<len;++i){pair=pairs[i].split('=')
params[pair[0]]=pair[1]}
for(var key in params)
if(params.hasOwnProperty(key))
if(parts=key.split('['))
if(parts.length>1)
for(i=0,prop=params,len=parts.length;i<len;++i){if(i==len-1){var name=parts[i].replace(']','')
prop[name]=params[key]
prop=params,delete params[key]}
else{var name=parts[i].replace(']','')
prop=prop[name]=prop[name]||{}}}
return params}
$(window).load(function(){PH.setMessagesTimeout();var errors=[];$('#errors > li').each(function(k,e){errors[errors.length]=$(e).html()});PH.showErrors(errors);});PH.Backcall=function(frm){PH.jsonsubmit(frm,{onsuccess:function(jd){if(jd.result==1){$.fancybox.close();}}});};
