//	JibberBook v2.0	(c) 2007 Chris Jaure, license: MIT License, website: http://www.chromasynthetic.com/
//  inc/jbscript_min.js
Element.extend({injectHTML:function(B,A){new Element("div").setHTML(B).getChildren().inject(this,A);return this}});var Guestbook={obj:{},fx:{},mouseDown:false,offset:2,submitForm:function(A){this.loading();this.obj.form.elements["_ajax"].value=true;this.ajaxReq.send(this.obj.form.getProperty("action"),this.obj.form.toQueryString());A.stop()},processAddResponse:function(){var B=Json.evaluate.attempt(this.ajaxReq.response.text);if(B){if(B.value!="1"){this.showMessage(B.message,"error");if(B.value=="2"){this.obj.form.reset()}}else{this.obj.commentWrapper.injectHTML(B.content,"top");var A=this.obj.commentWrapper.getFirst();if(this.obj.scroller==window){this.fx.scroll.toElement(this.obj.commentWrapper).chain(function(){this.showMessage(B.message,"confirm")}.bind(this))}else{this.fx.scroll.toTop();this.showMessage(B.message,"confirm")}this.obj.form.reset()}}else{this.showMessage("An error has occurred.","error")}this.loaded()},processLoadComments:function(){var A=Json.evaluate(this.loadComments.response.text);if(A.value=="0"){this.obj.scroller.removeEvents();this.obj.loadingMessage.setText("All comments have been loaded.")}this.obj.loadingMessage.injectHTML(A.content,"before")},loading:function(){this.obj.submitButton.setProperties({"disabled":true,"value":"Loading..."})},loaded:function(){this.obj.submitButton.setProperties({"disabled":false,"value":this.obj.submitButton.orgVal})},show:function(){if(!this.mouseDown){var A=this.obj.scroller.getSize();var B=(this.obj.scroller==window)?0:this.obj.scroller.getTop();if(this.obj.loadingMessage.getTop()-B<A.scroll.y+A.size.y){if(!this.loadComments.running){this.loadComments.send("actions/loadcomments.php","offset="+this.offset);this.offset++}}}},showMessage:function(B,A){this.obj.messageWrapper.setStyles({"left":(window.getWidth()/2-150),"top":window.getScrollTop()+30,"opacity":0});this.obj.messageWrapper.className=A;this.obj.messageWrapper.getFirst().setText(B);this.fx.message.start(0.9)},initialize:function(C,D,B,F){this.obj.form=$(C);this.obj.commentWrapper=$(D);this.obj.comments=this.obj.commentWrapper.getChildren();this.obj.messageWrapper=$(B);this.obj.submitButton=this.obj.form.getElement("input[type=submit]");this.obj.submitButton.orgVal=this.obj.submitButton.value;this.obj.loadingMessage=$(F);var A=this.obj.commentWrapper;while(A){if(A.getTag()=="body"){this.obj.scroller=window;A=null;break}var E=A.getStyle("overflow");if(E=="auto"||E=="scroll"){this.obj.scroller=A;A=null}else{A=A.getParent()}}this.fx.message=new Fx.Style(this.obj.messageWrapper,"opacity");this.fx.scroll=new Fx.Scroll(this.obj.scroller,{"duration":1000,"transition":Fx.Transitions.Circ.easeInOut});this.loadComments=new XHR({method:"get","onSuccess":this.processLoadComments.bind(this)});this.ajaxReq=new XHR({method:"post","onSuccess":this.processAddResponse.bind(this),"onFailure":function(){this.showMessage("Your comment could not be added. Please try again later.","error");this.loaded()}.bind(this)});this.obj.messageWrapper.addEvent("mouseover",function(){this.fx.message.start(0)}.bind(this));if(this.obj.loadingMessage){this.obj.loadingMessage.setText("More comments are loading. If you are using the scrollbar, please release your mouse.");this.obj.scroller.addEvents({"scroll":this.show.bind(this),"mousedown":function(){this.mouseDown=true}.bind(this),"mouseup":function(){this.mouseDown=false;this.show()}.bind(this)})}this.obj.form.addEvent("submit",this.submitForm.bindWithEvent(this));if(window.ie6){this.obj.messageWrapper.setStyle("zoom",1)}}}
