/*!
 * Проект Charming RC1 build 13       
 * Набор плагинов и тема оформления для CMS Alto версии 1.0
 * @licence     Dual licensed under the MIT or GPL Version 2 licenses
 */

/*!
 * ch-rating-block.js
 * Файл скриптов плагина Charming
 *
 * @author      Андрей Г. Воронов <andreyv@gladcode.ru>
 * @copyrights  Copyright © 2013-2014, Андрей Г. Воронов
 *              Является частью плагина Charming
 * @version     0.0.1 от 23.01.14 23:30
 */
(function(b){var a=function(d,c){this.element=b(d);
this.options=b.extend({},b.fn.chRatingBlock.defaultOptions,c,this.element.data());this.ratingObjectId=this.element.data("object-id");this.ratingObjectType=this.element.data("object-type");
this.voteButtons=this.element.find(".js-rating-block-plus a, .js-rating-block-minus a");return this.init()};a.prototype={init:function(){var c=this;c.voteButtons.hover(function(){c.saveCurrentState().addClass(b(this).data("class"))
},function(){c.element.removeClass(b(this).data("class")).addClass(c.element.data("tmp-class"))}).click(function(){c.ajax.vote(c,b(this))});return c},saveCurrentState:function(){var c=this.element;
if(c.hasClass("vote-count-positive")){c.data("tmp-class","vote-count-positive")}if(c.hasClass("vote-count-zero")){c.data("tmp-class","vote-count-zero")
}if(c.hasClass("vote-count-negative")){c.data("tmp-class","vote-count-negative")}c.removeClass("vote-count-negative").removeClass("vote-count-positive").removeClass("vote-count-zero");
return c},initHelper:function(){charming.helper.add("#default-load-from-disk",ls.lang.get("plugin.userlogo.open_from_disk")).add("#default-load-from-camera",ls.lang.get("plugin.userlogo.open_from_camera"));
return this},loader:{show:function(d,c){d.element.data("ch.chRatingBlock.loader",true);b(c).addClass("loading");return d},hide:function(d,c){d.element.data("ch.chRatingBlock.loader",false);
b(c).removeClass("loading");return d}},ajax:{vote:function(d,c){if(d.element.data("ch.chRatingBlock.loader")){return false}if(!ls.vote.options.type[d.ratingObjectType]){return false
}d.loader.show(d,c);c=b(c);var e={};e.value=c.data("val");e[ls.vote.options.type[d.ratingObjectType].targetName]=d.ratingObjectId;ls.hook.marker("voteBefore");
ls.ajax(ls.vote.options.type[d.ratingObjectType].url,e,function(f){ls.vote.onVote.apply(this,[d.ratingObjectId,c,c.data("val"),d.ratingObjectType,f]);d.loader.hide(d,c)
}.bind(ls.vote));return false}}};b.fn.chRatingBlock=function(c){return this.each(function(){var f=b(this);var e=f.data("ch.chRatingBlock");var d=typeof c==="object"&&c;
if(!e){f.data("ch.chRatingBlock",(e=new a(this,d)))}if(typeof c==="string"){e[c]()}return f})};b.fn.chRatingBlock.Constructor=a;b.fn.chRatingBlock.defaultOptions={}
}(window.jQuery));$(function(){ls.vote.options.type.group={url:aRouter.ajax+"vote/blog/",targetName:"idBlog"};ls.vote.onVoteTopic=function(f,d,e,b,a){var c=$(".status-counter-"+f);
if(typeof c!="undefined"){c.text(parseInt(c.text())+e)}if(typeof b.vote=="undefined"){return}b.vote.addClass("js-tooltip-vote-topic").tooltip("enter")};
$(".charming-rating-block").chRatingBlock({})});