var VotitalyPlugin=new Class({options:{submiturl:'/plugins/content/ji_votitaly_ajax.php',loadingimg:'/plugins/content/ji_votitaly/images/loading.gif',show_stars:true,star_description:'undefined',language:{updating:'undefined',thanks:'undefined',already_vote:'undefined',votes:'undefined',vote:'undefined',average:'undefined',outof:'undefined',error1:'undefined',error2:'undefined',error3:'undefined'}},initialize:function(options){this.setOptions(options);this.elements=[];this.logmessages=[];this.build();},build:function(){var arrOfElements=$$('div.votitaly-inline-rating');if($type(arrOfElements)!='array'){this.log('Parametri di inizializzazione errati!');return false;}
if(!arrOfElements.length){this.log('Nessun elemento di inizializzazione configurato!');return false;}
var _class=this;var container_fx=box_fx=[];arrOfElements.each(function(el){var actual_el_id=el.getElement('div.votitaly-get-id').getText();var actual_id=el.id;var togglers=el.getElements('a.votitaly-toggler');container_fx[actual_el_id]=new Fx.Styles(actual_id,{duration:1000,wait:false});box_fx[actual_el_id]=new Fx.Styles($(actual_id).getElement('div.votitaly-box'),{duration:1000,wait:false});togglers.each(function(tog){tog.addEvent('click',function(e){var container_id=actual_id;var element_id=actual_el_id;container_fx[element_id].start({'opacity':0.3});$(container_id).getElement('div.votitaly-box').setHTML('<img src="'+_class.options.loadingimg+'" class="loading" /> '+_class.options.language.updating);new Ajax(_class.options.submiturl,{method:'post',data:'task=vote&cid='+element_id+'&rating='+tog.getText(),onComplete:function(response){var json=Json.evaluate(response);var cont_el=$(container_id);cont_el.getElement('li.current-rating').setStyle('width',json.width);container_fx[element_id].start({'opacity':1,'background-color':'#fff'});box_fx[element_id].start({'opacity':0}).chain(function(){cont_el.getElement('div.votitaly-box').setHTML((json.success?_class.options.language.thanks:_class._getErrorString(json.return_code)));box_fx[element_id].start({'opacity':1});}).chain(function(){var func=function(){box_fx[element_id].start({'opacity':0}).chain(function(){_class._update_voting_description(cont_el.getElement('div.votitaly-box'),json.num_votes,json.average,json.out_of);box_fx[element_id].start({'opacity':1});});}.delay((json.success?1000:4000));});}}).request();});});});},_update_voting_description:function(box_el,num_votes,average,out_of){var string=this.options.star_description;string=string.replace(/{num_votes}/ig,num_votes)
.replace(/{num_average}/ig,average)
.replace(/{num_outof}/ig,out_of)
.replace(/#LANG_VOTES/ig,num_votes==1?this.options.language.vote:this.options.language.votes)
.replace(/#LANG_AVERAGE/ig,this.options.language.average)
.replace(/#LANG_OUTOF/ig,this.options.language.outof);box_el.setHTML(string);},_getErrorString:function(errno){switch(errno){case 1:return this.options.language.error1;case 2:return this.options.language.error2;case 3:return this.options.language.error3;default:return'undefined';}},log:function(string){this.logmessages.include(string);},showLogs:function(){this.logmessages.each(function(message){console.log(message);});},hasLogs:function(){return this.logmessages.length>0;},emptyLogs:function(){this.logmessages=[];}});VotitalyPlugin.implement(new Options);
