var Facebox=Class.create({initialize:function(a){this.settings={loading_image:"/images/loading.gif",close_image:"/images/closelabel.gif",image_types:new RegExp("."+["png","jpg","jpeg","gif"].join("|")+"$","i"),inited:true,facebox_html:'
'};if(a){Object.extend(this.settings,a)}$(document.body).insert({bottom:this.settings.facebox_html});this.preload=[new Image(),new Image()];this.preload[0].src=this.settings.close_image;this.preload[1].src=this.settings.loading_image;f=this;$$("#facebox .b:first, #facebox .bl, #facebox .br, #facebox .tl, #facebox .tr").each(function(b){f.preload.push(new Image());f.preload.slice(-1).src=b.getStyle("background-image").replace(/url\((.+)\)/,"$1")});this.facebox=$("facebox");this.keyPressListener=this.watchKeyPress.bindAsEventListener(this);this.watchClickEvents();fb=this;Event.observe($$("#facebox .close").first(),"click",function(b){Event.stop(b);fb.close()});Event.observe($$("#facebox .close_image").first(),"click",function(b){Event.stop(b);fb.close()})},watchKeyPress:function(a){if(a.keyCode==27||!Event.element(a).descendantOf(this.facebox)){this.close()}},watchClickEvents:function(b){var a=this;$$("a[rel=facebox]").each(function(d,c){Event.observe(d,"click",function(g){Event.stop(g);a.click_handler(d,g)})})},loading:function(){if($$("#facebox .loading").length==1){return true}contentWrapper=$$("#facebox .content").first();contentWrapper.childElements().each(function(c,b){c.remove()});contentWrapper.insert({bottom:''});var a=document.viewport.getScrollOffsets();this.facebox.setStyle({top:a.top+(document.viewport.getHeight()/10)+"px",left:document.viewport.getWidth()/2-(this.facebox.getWidth()/2)+"px"});Event.observe(document,"keypress",this.keyPressListener);Event.observe(document,"click",this.keyPressListener)},reveal:function(b,a){this.loading();load=$$("#facebox .loading").first();if(load){load.remove()}contentWrapper=$$("#facebox .content").first();if(a){contentWrapper.addClassName(a)}contentWrapper.update(b);$$("#facebox .body").first().childElements().each(function(d,c){d.show()});if(!this.facebox.visible()){new Effect.Appear(this.facebox,{duration:0.3})}this.facebox.setStyle({left:document.viewport.getWidth()/2-(this.facebox.getWidth()/2)+"px"});Event.observe(document,"keypress",this.keyPressListener);Event.observe(document,"click",this.keyPressListener)},close:function(){new Effect.Fade("facebox",{duration:0.3})},click_handler:function(c,i){this.loading();Event.stop(i);var k=c.rel.match(/facebox\[\.(\w+)\]/);if(k){k=k[1]}new Effect.Appear(this.facebox,{duration:0.3});if(c.href.match(/#/)){var a=window.location.href.split("#")[0];var j=c.href.replace(a+"#","");var l=$(j);var h=new Element(l.tagName);h.innerHTML=l.innerHTML;this.reveal(h,k)}else{if(c.href.match(this.settings.image_types)){var g=new Image();b=this;g.onload=function(){b.reveal('',k)};g.src=c.href}else{var b=this;var a=c.href;new Ajax.Request(a,{method:"get",onFailure:function(d){b.reveal(d.responseText,k)},onSuccess:function(d){b.reveal(d.responseText,k)}})}}}});var facebox;document.observe("dom:loaded",function(){facebox=new Facebox()});var WysiHat={};WysiHat.Editor={attach:function(a,c,e){c=$H(c);a=$(a);a.hide();var b=c.get("model")||WysiHat.iFrame;var d=e;return b.create(a,function(h){var g=h.getDocument();var i=h.getWindow();h.load();Event.observe(i,"focus",function(j){h.focus()});Event.observe(i,"blur",function(j){h.blur()});h._observeEvents();if(Prototype.Browser.Gecko){h.execCommand("undo",false,null)}if(d){d(h)}h.focus()})},include:function(a){this.includedModules=this.includedModules||$A([]);this.includedModules.push(a)},extend:function(b){var a=this.includedModules||$A([]);a.each(function(c){Object.extend(b,c)})}};WysiHat.Commands=(function(){function l(){this.execCommand("bold",false,null)}function w(){return this.queryCommandState("bold")}function H(){this.execCommand("underline",false,null)}function x(){return this.queryCommandState("underline")}function t(){this.execCommand("italic",false,null)}function F(){return this.queryCommandState("italic")}function v(){this.execCommand("strikethrough",false,null)}function g(){this.execCommand("blockquote",false,null)}function q(I){this.execCommand("fontname",false,I)}function m(){var I=this.selection.getNode();return Element.getStyle(I,"fontFamily")}function u(I){this.execCommand("fontsize",false,I)}function c(){var I=this.selection.getNode();return r(Element.getStyle(I,"fontSize"))}function G(I){this.execCommand("forecolor",false,I)}function k(){var I=this.selection.getNode();return y(Element.getStyle(I,"color"))}function p(I){if(Prototype.Browser.Gecko){this.execCommand("hilitecolor",false,I)}else{this.execCommand("backcolor",false,I)}}function a(){var I=this.selection.getNode();return y(Element.getStyle(I,"backgroundColor"))}function E(I){this.execCommand("justify"+I)}function d(){var I=this.selection.getNode();return Element.getStyle(I,"textAlign")}function j(I){this.execCommand("createLink",false,I)}function i(){var I=this.selection.getNode();if(this.linkSelected()){this.selection.selectNode(I)}this.execCommand("unlink",false,null)}function C(){var I=this.selection.getNode();return I?I.tagName.toUpperCase()=="A":false}function o(){this.execCommand("insertorderedlist",false,null)}function n(){this.execCommand("insertunorderedlist",false,null)}function e(I){this.execCommand("insertImage",false,I)}function b(J){if(Prototype.Browser.IE){var I=this._selection.getRange();I.pasteHTML(J);I.collapse(false);I.select()}else{this.execCommand("insertHTML",false,J)}}function A(M,L,K){var I=this.getDocument();if(Prototype.Browser.IE){this.selection.restore()}var J=this.commands.get(M);if(J){J.bind(this)(K)}else{I.execCommand(M,L,K)}}function h(K){var I=this.getDocument();var J=this.queryCommands.get(K);if(J){return J.bind(this)()}else{return I.queryCommandState(K)}}var B=$w("xxx-small xx-small x-small small medium large x-large xx-large");var D=$w("9px 10px 13px 16px 18px 24px 32px 48px");if(Prototype.Browser.WebKit){B.shift();B.push("-webkit-xxx-large")}function r(J){var I=B.indexOf(J);if(I>=0){return I}I=D.indexOf(J);if(I>=0){return I}return parseInt(J)}function y(M){if(!M||M.match(/[0-9a-f]{6}/i)){return M}var J=M.toLowerCase().match(/^(rgba?|hsla?)\(([\s\.\-,%0-9]+)\)/);if(J){var P=J[2].split(/\s*,\s*/),K=P.length,V=J[1];if((V=="rgb"&&K==3)||(V=="rgba"&&K==4)){var I=P[0];if(I.charAt(I.length-1)=="%"){var Q=P.map(function(L){return parseFloat(L)*2.56});if(K==4){Q[3]=P[3]}return z(Q)}return z(P)}if((V=="hsl"&&K==3)||(V=="hsla"&&K==4)){var R=((parseFloat(P[0])%360)+360)%360/360,N=parseFloat(P[1])/100,O=parseFloat(P[2])/100,T=O<=0.5?O*(N+1):O+N-O*N,U=2*O-T,Q=[s(U,T,R+1/3)*256,s(U,T,R)*256,s(U,T,R-1/3)*256,1];if(K==4){Q[3]=P[3]}return z(Q)}}return null}function z(J){var I=J.slice(0,3).map(function(K){var L=parseInt(K).toString(16);return L.length<2?"0"+L:L});return"#"+I.join("")}function s(J,I,K){if(K<0){++K}if(K>1){--K}var L=6*K;if(L<1){return J+(I-J)*L}if(2*K<1){return I}if(3*K<2){return J+(I-J)*(2/3-K)*6}return J}return{boldSelection:l,boldSelected:w,underlineSelection:H,underlineSelected:x,italicSelection:t,italicSelected:F,strikethroughSelection:v,blockquoteSelection:g,fontSelection:q,fontSelected:m,fontSizeSelection:u,fontSizeSelected:c,colorSelection:G,colorSelected:k,backgroundColorSelection:p,backgroundColorSelected:a,alignSelection:E,alignSelected:d,linkSelection:j,unlinkSelection:i,linkSelected:C,insertOrderedList:o,insertUnorderedList:n,insertImage:e,insertHTML:b,execCommand:A,queryCommandState:h,commands:$H({}),queryCommands:$H({link:C})}})();WysiHat.Editor.include(WysiHat.Commands);WysiHat.Events=(function(){var a=["click","dblclick","mousedown","mouseup","mouseover","mousemove","mouseout","keypress","keydown","keyup"];function b(j,k){a.each(function(l){Event.observe(j,l,function(m){k.fire("wysihat:"+l)})})}function g(l,j,k){Event.observe(j,"keydown",function(m){if(m.keyCode==86){k.fire("wysihat:paste")}});Event.observe(l,"paste",function(m){k.fire("wysihat:paste")})}function c(k,j){Event.observe(k,"focus",function(l){j.fire("wysihat:focus")});Event.observe(k,"blur",function(l){j.fire("wysihat:blur")})}function i(j,k){Event.observe(j,"mouseup",function(m){var l=k.selection.getRange();if(!l.collapsed){k.fire("wysihat:select")}})}function e(j,k){var l=k.rawContent();Event.observe(j,"keyup",function(n){var m=k.rawContent();if(l!=m){k.fire("wysihat:change");l=m}})}function d(j,l){var m=l.selection.getRange();var k=function(o){var n=l.selection.getRange();if(m!=n){l.fire("wysihat:cursormove");m=n}};Event.observe(j,"keyup",k);Event.observe(j,"mouseup",k)}function h(){if(this._observers_setup){return}var j=this.getDocument();var k=this.getWindow();b(j,this);g(k,j,this);c(k,this);i(j,this);e(j,this);d(j,this);this._observers_setup=true}return{_observeEvents:h}})();WysiHat.Editor.include(WysiHat.Events);WysiHat.Persistence=(function(){function h(i){return i.formatHTMLOutput()}function a(i){return i.formatHTMLInput()}function e(){return this.outputFilter(this.rawContent())}function d(i){this.setRawContent(this.inputFilter(i))}function c(){this.textarea.value=this.content()}function g(){this.setContent(this.textarea.value)}function b(){this.selection.setBookmark();this.save();this.load();this.selection.moveToBookmark()}return{outputFilter:h,inputFilter:a,content:e,setContent:d,save:c,load:g,reload:b}})();WysiHat.Editor.include(WysiHat.Persistence);WysiHat.Window=(function(){function c(){return this.contentDocument||this.contentWindow.document}function b(){if(this.contentDocument){return this.contentDocument.defaultView}else{if(this.contentWindow.document){return this.contentWindow}else{return null}}}function a(){this.getWindow().focus();if(this.hasFocus){return}this.hasFocus=true}function d(){this.hasFocus=false}return{getDocument:c,getWindow:b,focus:a,blur:d}})();WysiHat.Editor.include(WysiHat.Window);WysiHat.iFrame={create:function(a,c){var b=new Element("iframe",{id:a.id+"_editor","class":"editor"});Object.extend(b,WysiHat.iFrame.Methods);WysiHat.Editor.extend(b);b.attach(a,c);a.insert({before:b});return b}};WysiHat.iFrame.Methods={attach:function(a,b){this.textarea=a;this.observe("load",function(){try{var c=this.getDocument()}catch(d){return}this.selection=new WysiHat.Selection(this);if(this.ready&&c.designMode=="on"){return}this.setStyle({});c.designMode="on";b(this);this.ready=true;this.fire("wysihat:ready")})},unattach:function(){this.remove()},whenReady:function(b){if(this.ready){b(this)}else{var a=this;a.observe("wysihat:ready",function(){b(a)})}return this},setStyle:function(e){var a=this.getDocument();var c=this;if(!this.ready){return setTimeout(function(){c.setStyle(e)},1)}if(Prototype.Browser.IE){var d=a.createStyleSheet();d.addRule("body","border: 0");d.addRule("p","margin: 0");$H(e).each(function(h){var g=h.first().underscore().dasherize()+": "+h.last();d.addRule("body",g)})}else{if(Prototype.Browser.Opera){var d=Element("style").update("p { margin: 0; }");var b=a.getElementsByTagName("head")[0];b.appendChild(d)}else{Element.setStyle(a.body,e)}}return this},linkStyleSheet:function(a){this.whenReady(function(d){var b=d.getDocument();if(b.createStyleSheet){b.createStyleSheet(css)}else{var c=b.documentElement.getElementsByTagName("head")[0];if(!c){c=b.createElement("head");b.documentElement.insertBefore(c,b.getElementsByTagName("body")[0])}var e='';c=$(c);if(c.insert){$(c).insert(e)}else{c.innerHTML=c.innerHTML+e}}})},getStyle:function(b){var a=this.getDocument();return Element.getStyle(a.body,b)},rawContent:function(){var a=this.getDocument();if(a.body){return a.body.innerHTML}else{return""}},setRawContent:function(b){var a=this.getDocument();if(a.body){a.body.innerHTML=b}}};WysiHat.Editable={create:function(a,c){var b=new Element("div",{id:a.id+"_editor","class":"editor",contenteditable:"true"});b.textarea=a;WysiHat.Editor.extend(b);Object.extend(b,WysiHat.Editable.Methods);c(b);a.insert({before:b});return b}};WysiHat.Editable.Methods={getDocument:function(){return document},getWindow:function(){return window},rawContent:function(){return this.innerHTML},setRawContent:function(a){this.innerHTML=a}};Object.extend(String.prototype,(function(){function a(){var k=String(this);k=k.tidyXHTML();if(Prototype.Browser.WebKit){k=k.replace(/(\s*<\/p>/g,"");k=k.replace(/
(\n)*/g,"\n")}else{if(Prototype.Browser.Gecko){k=k.replace(/
/g,"");k=k.replace(/<\/p>(\n)?/g,"\n");k=k.replace(/
(\n)*/g,"\n")}else{if(Prototype.Browser.IE||Prototype.Browser.Opera){k=k.replace(/
( | |\s)<\/p>/g,"
");k=k.replace(//g,"");k=k.replace(/ /g,"");k=k.replace(/<\/p>(\n)?/g,"\n");k=k.gsub(/^
/,"");k=k.gsub(/<\/p>$/,"")}}}k=k.gsub(//,"");k=k.gsub(/<\/b>/,"");k=k.gsub(//,"");k=k.gsub(/<\/i>/,"");k=k.replace(/\n\n+/g,"
\n\n");k=k.gsub(/(([^\n])(\n))(?=([^\n]))/,"#{2}
\n");k="
"+k+"
";k=k.replace(/\s*/g,"
");k=k.replace(/\s*<\/p>/g,"
");var e=Element("body");e.innerHTML=k;if(Prototype.Browser.WebKit||Prototype.Browser.Gecko){var j;do{j=false;e.select("span").each(function(i){if(i.hasClassName("Apple-style-span")){i.removeClassName("Apple-style-span");if(i.className==""){i.removeAttribute("class")}j=true}else{if(i.getStyle("fontWeight")=="bold"){i.setStyle({fontWeight:""});if(i.style.length==0){i.removeAttribute("style")}i.update(""+i.innerHTML+"");j=true}else{if(i.getStyle("fontStyle")=="italic"){i.setStyle({fontStyle:""});if(i.style.length==0){i.removeAttribute("style")}i.update(""+i.innerHTML+"");j=true}else{if(i.getStyle("textDecoration")=="underline"){i.setStyle({textDecoration:""});if(i.style.length==0){i.removeAttribute("style")}i.update(""+i.innerHTML+"");j=true}else{if(i.attributes.length==0){i.replace(i.innerHTML);j=true}}}}}})}while(j)}var h=$A(["BR","IMG"]);for(var d=0;d/g,"
\n\n");k=k.replace(/
\s*<\/p>/g,"");k=k.replace(/\s*$/g,"");return k}function b(){var e=String(this);var d=Element("body");d.innerHTML=e;if(Prototype.Browser.Gecko||Prototype.Browser.WebKit){d.select("strong").each(function(g){g.replace(''+g.innerHTML+"")});d.select("em").each(function(g){g.replace(''+g.innerHTML+"")});d.select("u").each(function(g){g.replace(''+g.innerHTML+"")})}if(Prototype.Browser.WebKit){d.select("span").each(function(g){if(g.getStyle("fontWeight")=="bold"){g.addClassName("Apple-style-span")}if(g.getStyle("fontStyle")=="italic"){g.addClassName("Apple-style-span")}if(g.getStyle("textDecoration")=="underline"){g.addClassName("Apple-style-span")}})}e=d.innerHTML;e=e.tidyXHTML();e=e.replace(/<\/p>(\n)*
/g,"\n\n");e=e.replace(/(\n)?
(\n)?/g,"\n");e=e.replace(/^
/g,"");e=e.replace(/<\/p>$/g,"");if(Prototype.Browser.Gecko){e=e.replace(/\n/g,"
");e=e+"
"}else{if(Prototype.Browser.WebKit){e=e.replace(/\n/g,"
");e="
"+e+"
";e=e.replace(/<\/p>/g,"
");e=e.replace(/(
<\/p>)+$/g,"")}}}return e}function c(){var d=String(this);d=d.gsub(/\r\n?/,"\n");d=d.gsub(/<([A-Z]+)([^>]*)>/,function(e){return"<"+e[1].toLowerCase()+e[2]+">"});d=d.gsub(/<\/([A-Z]+)>/,function(e){return""+e[1].toLowerCase()+">"});d=d.replace(/
/g,"
");return d}return{formatHTMLOutput:a,formatHTMLInput:b,tidyXHTML:c}})());Object.extend(String.prototype,{sanitize:function(a){return Element("div").update(this).sanitize(a).innerHTML.tidyXHTML()}});Element.addMethods({sanitize:function(c,b){c=$(c);b=$H(b);var a=$A(b.get("tags")||[]);var d=$A(b.get("attributes")||[]);var e=Element(c.nodeName);$A(c.childNodes).each(function(i){if(i.nodeType==1){var g=$(i).sanitize(b).childNodes;if(a.include(i.nodeName.toLowerCase())){var h=Element(i.nodeName);d.each(function(j){if((value=i.readAttribute(j))){h.writeAttribute(j,value)}});e.appendChild(h);$A(g).each(function(j){h.appendChild(j)})}else{$A(g).each(function(j){e.appendChild(j)})}}else{if(i.nodeType==3){e.appendChild(i)}}});return e}});if(typeof Range=="undefined"){Range=function(a){this.ownerDocument=a;this.startContainer=this.ownerDocument.documentElement;this.startOffset=0;this.endContainer=this.ownerDocument.documentElement;this.endOffset=0;this.collapsed=true;this.commonAncestorContainer=this._commonAncestorContainer(this.startContainer,this.endContainer);this.detached=false;this.START_TO_START=0;this.START_TO_END=1;this.END_TO_END=2;this.END_TO_START=3};Range.CLONE_CONTENTS=0;Range.DELETE_CONTENTS=1;Range.EXTRACT_CONTENTS=2;if(!document.createRange){document.createRange=function(){return new Range(this)}}Object.extend(Range.prototype,(function(){function r(){return e(this,Range.CLONE_CONTENTS)}function x(){try{var z=new Range(this.ownerDocument);z.startContainer=this.startContainer;z.startOffset=this.startOffset;z.endContainer=this.endContainer;z.endOffset=this.endOffset;z.collapsed=this.collapsed;z.commonAncestorContainer=this.commonAncestorContainer;z.detached=this.detached;return z}catch(y){return null}}function b(y){if(y){this.endContainer=this.startContainer;this.endOffset=this.startOffset;this.collapsed=true}else{this.startContainer=this.endContainer;this.startOffset=this.endOffset;this.collapsed=true}}function a(z,E){try{var A,D,C,y;A=this.commonAncestorContainer;D=E.commonAncestorContainer;C=A;while(C.parentNode){C=C.parentNode}y=D;while(y.parentNode){y=y.parentNode}switch(z){case this.START_TO_START:return p(this,this.startContainer,this.startOffset,E.startContainer,E.startOffset);break;case this.START_TO_END:return p(this,this.startContainer,this.startOffset,E.endContainer,E.endOffset);break;case this.END_TO_END:return p(this,this.endContainer,this.endOffset,E.endContainer,E.endOffset);break;case this.END_TO_START:return p(this,this.endContainer,this.endOffset,E.startContainer,E.startOffset);break}}catch(B){}return null}function w(){try{e(this,Range.DELETE_CONTENTS)}catch(y){}}function v(){this.detached=true}function o(){try{return e(this,Range.EXTRACT_CONTENTS)}catch(y){return null}}function k(y){try{var C,z,B;switch(this.startContainer.nodeType){case Node.CDATA_SECTION_NODE:case Node.TEXT_NODE:z=this.startContainer.splitText(this.startOffset);this.startContainer.parentNode.insertBefore(y,z);break;default:if(this.startContainer.childNodes.length==0){B=null}else{B=this.startContainer.childNodes(this.startOffset)}this.startContainer.insertBefore(y,B)}}catch(A){}}function d(y){this.setStartBefore(y);this.setEndAfter(y)}function u(y){this.setStart(y,0);this.setEnd(y,y.childNodes.length)}function q(y,C){try{var z,B;this.startContainer=y;this.startOffset=C;z=this.endContainer;while(z.parentNode){z=z.parentNode}B=this.startContainer;while(B.parentNode){B=B.parentNode}if(B!=z){this.collapse(true)}else{if(p(this,this.startContainer,this.startOffset,this.endContainer,this.endOffset)>0){this.collapse(true)}}this.collapsed=t(this);this.commonAncestorContainer=s(this.startContainer,this.endContainer)}catch(A){}}function n(y){this.setStart(y.parentNode,h(y)+1)}function j(y){this.setStart(y.parentNode,h(y))}function i(y,A){try{this.endContainer=y;this.endOffset=A;endRootContainer=this.endContainer;while(endRootContainer.parentNode){endRootContainer=endRootContainer.parentNode}startRootContainer=this.startContainer;while(startRootContainer.parentNode){startRootContainer=startRootContainer.parentNode}if(startRootContainer!=endRootContainer){this.collapse(false)}else{if(p(this,this.startContainer,this.startOffset,this.endContainer,this.endOffset)>0){this.collapse(false)}}this.collapsed=t(this);this.commonAncestorContainer=s(this.startContainer,this.endContainer)}catch(z){}}function g(y){this.setEnd(y.parentNode,h(y)+1)}function l(y){this.setEnd(y.parentNode,h(y))}function m(z){try{var B,y;while(z.firstChild){z.removeChild(z.firstChild)}y=this.extractContents();this.insertNode(z);z.appendChild(y);this.selectNode(z)}catch(A){}}function p(D,B,E,z,C){var G,A,y,F,H;if(B==z){if(E==C){return 0}else{if(E