var CommonMood=Class.create({initialize:function(A,B){this.anchor=A;this.mood=B;this.productId;this.isCommentStructExists;this.comments=$H();this.currentElement;},initMoodCarousel:function(){var D=this.anchor.select("[carousel]").last();var B=this.anchor.select("[previous]").last();var A=this.anchor.select("[next]").last();var C=new SCarousel(D,{highLight:"carousel-highLight-h-special-image",direction:"horizontal",next:$(A),previous:$(B)});Object.extend(C,CarouselModuleSimple);D.select('[rel="scarousel"]').each(function(H,F){var E=$H();E.set("elm",H);var G=E.toObject();C.add(E.toObject());});C.calculateBlocks(175);C.checkButtons();Event.observe($(B),"click",function(){D.fire("previous:block");}.bind(this));Event.observe($(A),"click",function(){D.fire("next:block");}.bind(this));},initProductsEvent:function(A){this.anchor.select("[productid]").each(function(B){B.observe("mouseover",this.displayCommentEventHandler.bindAsEventListener(this));}.bind(this));},displayCommentEventHandler:function(A){var B=A.element().up(".widblock_prod");if(B){this.displayComment(B);}},displayComment:function(C){var B=C.readAttribute("productid");if(this.productId==B){return ;}this.productId=B;var A=this.anchor.select("[comment]").last();if(!this.isCommentStructExists){A.update(this.processTemplate(this.commentStruct,{}));A.select("[displaySendComment]").last().observe("click",this.clickSendContainer.bindAsEventListener(this));this.isCommentStructExists=true;}if(!this.currentElement){this.currentElement=C;this.currentElement.next(".wid_jaime_border").toggle();}else{this.currentElement.next(".wid_jaime_border").toggle();this.currentElement=C;this.currentElement.next(".wid_jaime_border").toggle();}this.showLoadingComment(A);var D=this.comments.get(this.productId);if(null!=D){A.select("[owner]").last().update(D.owner);A.select("[others]").last().update(D.other);}else{new Ajax.Request("/Widgets/Products/Products.ashx",{method:"GET",parameters:{action:"getproductscomment",pid:B,mood:this.mood},onSuccess:function(E){if(E.responseJSON.success){A.select("[owner]").last().update(E.responseJSON.owner);A.select("[others]").last().update(E.responseJSON.others);this.comments.set(E.responseJSON.productid,{owner:E.responseJSON.owner,others:E.responseJSON.others});}}.bind(this)});}},showLoadingComment:function(A){var B=this.processTemplate(this.commentLoading,{});A.select("[owner]").last().update(B);A.select("[others]").last().update(B);},sendComment:function(B,A){if(0==$F(A).length){return ;}Product.addComment(this.mood,B,null,$F(A),function(E){if(E.responseJSON.success){var D=this.commentItem.evaluate(E.responseJSON.comment);var C=this.comments.get(B);if(E.responseJSON.isOwner){C.owner=D+C.owner;this.comments.set(B,C);this.refreshOwnerComments(B);}else{C.other=D+C.other;this.comments.set(B,C);this.refreshOtherComments(B);}A.clear();}}.bind(this));},refreshOwnerComments:function(A){var B=this.comments.get(A);if(null!=B){this.anchor.select("[owner]").last().update(B.owner);}},refreshOtherComments:function(A){var B=this.comments.get(A);if(null!=B){this.anchor.select("[other]").last().update(B.other);}},clickSendContainer:function(A){var B=this.anchor.select(".comment-response-container").last();Effect.toggle(B,"slide",{duration:1,beforeStart:function(C){if(B.visible()){this.sendComment(this.productId,this.anchor.select(".comment-response").last());}}.bind(this),afterFinish:function(C){if(B.visible()){this.anchor.select("[displaySendComment]").last().update("+ Envoyer");}else{this.anchor.select("[displaySendComment]").last().update("+ Donner son avis");}}.bind(this)});},processTemplate:function(C,B){var D=C.evaluate(B);var A=new Element("div").update(D);return A.down(0);},commentStruct:new Template('<div><div class="wid_jaime_com"><div class="wid_jaime_moi">Ce que j \'aime</div><div owner></div><div class="wid_jaime_vous">Et vous ?</div><div others></div><div class="clear"></div></div><div class="wid_jaime_com comment-response-container collapsed" style="display:none;"><input class="comment-response" type="textarea" name="comment-response" comment-response=""/></div><div class="wid_com_ad"><a href="javascript:;" title="" displaySendComment >+ Donner son avis</a></div></div>'),commentLoading:new Template('<div><img src="/Images_beta2/loading.gif"/> chargement des commentaires ...<div>'),commentItem:new Template('<div class="wid_jaime_blockcom_repeater"><div class="wid_jaime_avatar"><img src="#{avatar}" alt=""/></div><div class="wid_jaime_blockcom"><p>#{text}</p></div><div class="wid_jaime_blockcom_bas"></div><div class="clear"></div></div>')});