/* f858b0449806ebac41055a5801c15836 */
var a;
function WikispacesEditor(e,d,b,c,f){this.VISUAL="visual";this.PLAIN="plain";this.mode=e;this.stylesheetUrl=d;this.cancelUrl=b;this.uploadUrl=c;this.maxFileSize=f;this.plugins=[];this.currentArea=null;this.areaMap=Array();this.toolbar=new WikispacesToolbar(this);this.createArea=function(g){return new WikispacesEditorArea(this,g)};this.addArea=function(g,h){this.areaMap[g]=h};this.removeArea=function(g){delete this.areaMap[g]};this.getArea=function(g){return this.areaMap[g]};this.getMainArea=function(){return this.getArea("WikispacesEditorContent")};
this.getCurrentArea=function(){return this.getArea(this.currentArea)};this.setCurrentArea=function(g){log("switching editor",g);var h=this.getCurrentArea();h&&h.areaId!=g&&h.selectElement(jQuery(h.getEditorWindow().document).find("body").get(0));this.currentArea=g};this.setMode=function(g){this.mode=g;g=this.mode==this.VISUAL?new WikispacesVisualEditor:new WikispacesTextEditor;for(var h in g)WikispacesEditorArea.prototype[h]=g[h]};this.sessionReloadFailed=function(){this.getCurrentArea().autosaveEnabled=
false;jQuery("#saveDraftButton").attr("disabled",true).val("Autosave Disabled");this.toolbar.setAutosaveStatus("Autosave Disabled",true);jQuery("#preview_top").attr("disabled",true);jQuery(document.rte.preview).attr("disabled",true);jQuery(this.toolbar.toolbarPopup.getContent()).find("#rteImageBtn").css("opacity","0.3").unbind("click").click(function(){alert("The image tool has been disabled.")});this.toolbar.linkToolbar.linkPopupWindow&&this.toolbar.linkToolbar.disableSelect();alert("Your connection to Wikispaces has been distrupted.  We recommend you save your page now, and try editing the page again.")};
this.registerPlugin=function(g){this.plugins[this.plugins.length]=g};this.setMode(e);WikispacesEditor.editor=this}WikispacesEditor.getEditor=function(){return WikispacesEditor.editor};
function WikispacesEditorArea(e,d){this.editor=e;this.areaId=d;var b=this;this.editor.addArea(d,this);this.editor.getCurrentArea()||this.editor.setCurrentArea(d);this.zeroBorder="#c0c0c0";this.anotherEditDetected=false;this.reloadAttempt=0;this.editorConfirmDeparture=true;this.editorSaving=false;this.editorCleanup="";this.mainEditor=true;this.referenceEditor=false;this.currentResizing=true;this.highlightContent=false;this.version=0;this.registerCleanup=function(){window.onbeforeunload=function(){return b.editorUnsavedChangesWarning()}};
this.detectedChangeDelayed=function(){typeof this.detectedChangeHandle=="number"&&clearTimeout(this.detectedChangeHandle);this.detectedChangeHandle=setTimeout(function(){b.detectedChange()},50)};this.detectedChange=function(){typeof this.detectedChangeHandle=="number"&&clearTimeout(this.detectedChangeHandle);if(!document.rte.changeDetected.value){document.rte.changeDetected.value=true;this.mainEditor&&this.registerCleanup();setTimeout(function(){b.autosaveLoop()},this.AUTOSAVE_INTERVAL)}if(this.editor.mode==
this.editor.VISUAL){this.lookForHeightChange();var c=jQuery(this.editor.getMainArea().getEditorWindow().document.body)[0].childNodes;c=c[c.length-1];for(var f=false,g=false;!f&&!g;)if(c&&c.nodeType==3)if(jQuery.trim(jQuery(c).text())=="")c=c.previousSibling;else f=true;else if(jQuery(c).is("br"))f=true;else g=true;g&&jQuery(this.editor.getMainArea().getEditorWindow().document.body).append("<br/>")}};this.lookForHeightChange=function(){var c=this.getContentHeight(),f=this.getMaxWidth();if(!this.editorMinWidth)this.editorMinWidth=
jQuery("#toolbarPopup").width()-32;if(c<290)c=290;if(f<this.editorMinWidth)f=this.editorMinWidth;if(!this.editorHeight)this.editorHeight=jQuery("#editor").height();if(!this.editorWidth)this.editorWidth=jQuery("#editor").width();if(c>this.editorHeight){this.editorHeight=c+10;if(this.editorHeight>32767&&jQuery.browser.mozilla){this.editorHeight=32767;jQuery("#"+this.areaId).css("overflow-y","scroll")}jQuery("#"+this.areaId).height(this.editorHeight)}if(f>this.editorWidth){this.editorWidth=f+10;jQuery("#"+
this.areaId).width(this.editorWidth)}if(!this.editorMaxWidth)this.editorMaxWidth=jQuery("#editor").width();if(this.editorWidth>this.editorMaxWidth){this.editorWidth=this.editorMaxWidth;jQuery("#"+this.areaId).width(this.editorWidth)}};this.getContentHeight=function(){var c=this.getEditorWindow().document.getElementById("editor_body");if(c)return c.scrollHeight*1};this.getMaxWidth=function(){var c=this.getEditorWindow().document.body;if(c){var f=c.scrollWidth;jQuery(c).find("img").each(function(){if(jQuery(this).width()>
f)f=jQuery(this).width()});jQuery(c).find("table").each(function(){if(jQuery(this).width()>f)f=jQuery(this).width()});return f*1}};this.enableDesignMode=function(c,f){log("enableDesignMode: ",arguments);var g='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html id="'+this.areaId+'"><head>\n<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n';g+=f.length>0?'<link media="all" type="text/css" href="'+f+'" rel="stylesheet">\n':
'<style>@charset "utf-8"; body {background:#FFFFFF;margin:8px;padding:0px;}</style>\n';g+='</head><body id="editor_body" class="wiki" style="margin: 0 1px;">';g+=c;g+="</body></html>";var h=this.getEditorWindow().document;if(jQuery.browser.msie){h.open();h.write(g);h.close();h.designMode="On"}else try{h.designMode="on";h.open();h.write(g);h.close()}catch(k){log("enableDesignMode exception",k);setTimeout(function(){b.enableDesignMode(c,f)},200)}};this.enableSpellCheck=function(){try{document.getElementById(this.areaId).contentWindow.document.getElementsByTagName("body")[0].spellcheck=
true}catch(c){setTimeout(function(){b.enableSpellCheck()},5E3)}};this.rteCleanup=function(){this.stripGuidelines();this.rteSync()};this.rteSync=function(){log("rteSync",this.areaId);var c=jQuery("#hdn"+this.areaId);c.val()==null&&c.val("");var f=this.getContent();f=this.referenceTool.pushInReferences(f);c.val(f)};this.rteCommand=function(c,f,g){var h=this.getEditorWindow().document;if(jQuery.browser.msie){if((f=="insertorderedlist"||f=="insertunorderedlist")&&!h.queryCommandState("InsertOrderedList")&&
!h.queryCommandState("InsertUnorderedList")){c=h.selection.createRange();if(c.htmlText==""){g=(new Date).getTime();f=="insertunorderedlist"?c.pasteHTML('<ul><li><p id="'+g+'"> &nbsp; </p></li></ul>'):c.pasteHTML('<ol><li><p id="'+g+'"> &nbsp; </p></li></ol>');h=h.getElementById(g);c.moveToElementText(h);c.select();c.collapse(true);jQuery(h).replaceWith(jQuery(h).html())}else{var k=c.htmlText;k=k.replace(/<br[\s*\/]?>/gmi,"</li> <li>");k="<li>"+k+"</li>";g=(new Date).getTime();f=="insertunorderedlist"?
c.pasteHTML('<ul id="'+g+'">'+k+"</ul>"):c.pasteHTML('<ol id="'+g+'">'+k+"</ol>");h=h.getElementById(g);c.moveToElementText(h);c.select()}this.updateHierarchy();this.detectedChangeDelayed();return true}if(f=="formatblock"){c=h.selection.createRange();k=c.htmlText;if(k!=""){f=this.ieGetParent();g=g.toUpperCase().replace(/[<>]/g,"");if(g.match(/^H\d$/))if(f.nodeName.match(/^H\d$/))if(f.nodeName!=g){k=f.innerHTML;var l=h.createElement(g);f.replaceNode(l);l.innerHTML=k;this.splitOnBr(g,h)}else return false;
else{k=k.replace(/<br[ \/]*>\s*$/i,"");k=k.replace(/^\s*<p>/i,"");k=k.replace(/<\/p>\s*$/i,"");c.pasteHTML("<"+g+">"+k+"</"+g+">");this.splitOnBr(g,h)}else if(f!=null&&f.nodeName.match(/^H\d$/)){k=f.innerHTML;l=h.createElement("SPAN");f.replaceNode(l);l.innerHTML=k}c.select();this.getEditorWindow().focus()}this.updateHierarchy();this.detectedChangeDelayed();return true}}try{this.getEditorWindow().focus();h.execCommand(f,false,g);this.getEditorWindow().focus();if(f!="useCSS"&&f!="enableInlineTableEditing"&&
f!="enableObjectResizing"){this.updateHierarchy();this.detectedChangeDelayed()}}catch(m){log("rteCommand exception "+m.name+" - "+m.message,m,f,g)}};this.selectFont=function(){var c=jQuery("#rteFormatBlock").val();WikispacesCommon.track("Editor","Select Font",c);this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"formatblock",c)};this.moveSelectionIntoEditor=function(c){if(!jQuery.browser.msie){var f=c.getSelection(),g=f.getRangeAt(0),h=g.startContainer,k=c.document.getElementById("editor_body");
if(h!=k&&!Element.childOf(h,k)){h=c.document.createRange();h.setStart(c.document.getElementById("editor_body"),0);h.setStart(c.document.getElementById("editor_body"),0);h.collapse(true);f.addRange(h);f.removeRange(g)}}};this.insertNodeAtSelection=function(c,f){this.moveSelectionIntoEditor(c);var g=new Selection(c),h=g.getRangeAt(0);g.removeAllRanges();h.deleteContents();h.insertNode(f);if(!jQuery.browser.msie){c.focus();g=new Selection(c);h=g.getRangeAt(0);h.selectNodeContents(f);h.collapse(false)}this.detectedChangeDelayed()};
this.setRange=function(){return(new Selection(this.getEditorWindow())).getRangeAt(0)};this.stripHTML=function(c){c=c.replace(/(<([^>]+)>)/ig,"");c=c.replace(/\r\n/g," ");c=c.replace(/\n/g," ");return c=c.replace(/\r/g," ")};this.showCursor=function(){try{var c=this.getEditorWindow();if(!jQuery.browser.msie){c.focus();var f=jQuery(c.document).find("body").children(":last").get(0);f||(f=jQuery(c.document).find("body").get(0));var g=c.document.createRange();g.setEndAfter(f);g.setStartAfter(f);c.getSelection().addRange(g)}c.focus()}catch(h){setTimeout(function(){b.showCursor()},
5E3)}};this.showGuidelines=function(){try{for(var c=this.getEditorWindow(this.areaId).document.getElementsByTagName("table"),f=0;f<c.length;f++)if(c[f].getAttribute("border")=="0")for(var g=c[f].getElementsByTagName("tr"),h=0;h<g.length;h++)for(var k=g[h].getElementsByTagName("td"),l=0;l<k.length;l++)if(h==0&&l==0)k[l].style.border="dashed 1px "+this.zeroBorder;else if(h==0&&l!=0){k[l].style.borderBottom="dashed 1px "+this.zeroBorder;k[l].style.borderTop="dashed 1px "+this.zeroBorder;k[l].style.borderRight=
"dashed 1px "+this.zeroBorder}else if(h!=0&&l==0){k[l].style.borderBottom="dashed 1px "+this.zeroBorder;k[l].style.borderLeft="dashed 1px "+this.zeroBorder;k[l].style.borderRight="dashed 1px "+this.zeroBorder}else if(h!=0&&l!=0){k[l].style.borderBottom="dashed 1px "+this.zeroBorder;k[l].style.borderRight="dashed 1px "+this.zeroBorder}}catch(m){setTimeout(function(){b.showGuidelines()},5E3)}};this.stripGuidelines=function(){for(var c=this.getEditorWindow().document.getElementsByTagName("table"),f=
0;f<c.length;f++)if(c[f].getAttribute("border")=="0")for(var g=c[f].getElementsByTagName("td"),h=0;h<g.length;h++)g[h].removeAttribute("style")};this.getRangeParent=function(c){var f=null;if(this.getEditorWindow().document.selection.type=="Control")for(i=0;i<c.length;i++){if(c(i).parentNode){f=c(i).parentNode;break}}else f=c.parentElement();return f};this.selectParent=function(c){if(this.imageTool.selectedImage&&this.imageTool.selectedImage.parentNode){for(var f=this.imageTool.selectedImage;f&&f.nodeName!=
c;)f=f.parentNode;return f}if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode){for(f=this.mediaTool.selectedMedia;f&&f.nodeName!=c;)f=f.parentNode;return f}var g=this.getEditorWindow();if(jQuery.browser.msie){g.focus();var h=g.document.selection.createRange();for(f=this.getRangeParent(h);f&&f.nodeName!=c;)f=f.parentNode;if(f&&f.nodeName==c){g.focus();g.document.selection.empty();h=g.document.selection.createRange();h.moveToElementText(f);h.select()}return f}g.focus();f=g.window.getSelection().getRangeAt(0);
if((f=f.startContainer.nodeType==1?f.startContainer.childNodes[f.startOffset]:f.startContainer)&&f.hasChildNodes()){h=f.childNodes;for(var k=0;k<h.length;k++)if(h[k].nodeName==c)f=h[k]}for(;f&&f.nodeName!=c;)f=f.parentNode;if(f&&f.nodeName==c){g.focus();h=g.document.createRange();h.selectNode(f);c=g.getSelection();c.removeAllRanges();c.addRange(h)}return f};this.geckoKeyPress=function(c){if(c.ctrlKey){var f="";switch(String.fromCharCode(c.charCode).toLowerCase()){case "b":f="bold";break;case "i":f=
"italic";break;case "u":f="underline";break}if(f){this.rteCommand(this.areaId,f,null);c.preventDefault();c.stopPropagation()}}};this.safariKeyPress=function(c){var f=this.getEditorWindow(),g=f.document;switch(c.keyCode){case 13:var h=new Selection(this.getEditorWindow());h=h.getRangeAt(0).startContainer.parentNode;if(!c.shiftKey&&(f.document.queryCommandState("InsertOrderedList")||f.document.queryCommandState("InsertUnorderedList"))||"H1"==h.nodeName||"H2"==h.nodeName||"H3"==h.nodeName||"H4"==h.nodeName||
"H5"==h.nodeName||"H6"==h.nodeName)return true;if(!(c.ctrlKey||c.altKey)){this.insertInEditor('<br id="wikispacesNewline" />&nbsp;');var k=jQuery(g.body).find("#wikispacesNewline").attr("id",null).get(0).nextSibling;h=f.getSelection();f=g.createRange();f.setStart(k,0);f.setEnd(k,0);h.removeAllRanges();h.addRange(f);c.preventDefault();c.stopPropagation();return false}break;case 9:if(!(c.ctrlKey||c.altKey)){if(g.queryCommandState("InsertOrderedList")||g.queryCommandState("InsertUnorderedList")){if(c.shiftKey){this.rteCommand(this.areaId,
"useCSS",true);this.rteCommand(this.areaId,"outdent","")}else{this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"indent","")}c.preventDefault();c.stopPropagation();return false}c.preventDefault();c.stopPropagation();return false}break;case 21:if(c.ctrlKey){this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"underline",null);c.preventDefault();c.stopPropagation();return false}break}};this.ieKeyPress=function(c){var f=this.getEditorWindow();switch(c.keyCode){case 13:if(!(c.ctrlKey||
c.altKey||c.shiftKey)){var g=this.ieGetParent();if(f.document.queryCommandState("InsertOrderedList")||f.document.queryCommandState("InsertUnorderedList")||"H1"==g.nodeName||"H2"==g.nodeName||"H3"==g.nodeName||"H4"==g.nodeName||"H5"==g.nodeName||"H6"==g.nodeName)return true;this.insertInEditor("<br />&nbsp;");g=f.document.selection.createRange();g.moveStart("character",-1);g.select();f.document.selection.clear();c.preventDefault();c.stopPropagation();return false}break;case 9:if(!(c.ctrlKey||c.altKey))if(f.document.queryCommandState("InsertOrderedList")||
f.document.queryCommandState("InsertUnorderedList")){if(c.shiftKey){this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"outdent","")}else{this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"indent","")}c.preventDefault();c.stopPropagation();return false}break}return true};this.ieGetParent=function(){var c=null;c=this.getEditorWindow();c.focus();for(c=this.getRangeParent(c.document.selection.createRange());c;){if(c.nodeType==1&&c.nodeName!="P"&&c.nodeName!="SPAN"&&
c.nodeName!="A")return c;if(c.parentNode)c=c.parentNode;else return null}};this.splitOnBr=function(c,f){jQuery(f).find(c).each(function(){var g=jQuery(this).children();if(g.length>0&&g.get(0).tagName.toLowerCase()=="p")g=g.get(0).children();jQuery(this);for(var h=f.createElement(c),k=false,l=0;g.length>l;)if(g.get(l).nodeType==1&&g.get(l).tagName.toLowerCase()=="br"){if(h.childNodes.length){lastLi=lastLi.insertAdjacentElement("afterEnd",h);log("added a new li")}h=f.createElement(c);g.remove(l);k=
true;log("BR FOUND IN LIST")}else if(k){h.appendChild(g.item(l).cloneNode(true));g.item(l).removeNode();log("appended a cloned node")}else l++;if(h.childNodes.length)lastLi=lastLi.insertAdjacentElement("afterEnd",h)})};this.customEditorStart=function(c,f){this.timeTracker=new TimeTracker;this.timeTracker._setHistogramBuckets([6E4,12E4,3E5,6E5,12E5,18E5,36E5]);this.timeTracker._recordStartTime();if(this.mainEditor){this.fadeEditor();this.registerCleanup()}if(f){log("autosaveDetected");if(typeof Dialog!=
"undefined"){log("showAutosavePopup");this.editor.toolbar.showAutosavePopup(c);return true}else{log("ERROR: undefined Dialog");return false}}else return this.customEditorStartSecondary(c)};this.initialRteCommands=function(){log("initialRteCommands");if(this.highlightContent){this.rteCommand(this.areaId,"selectall","");this.highlightContent=false}this.rteCommand(this.areaId,"enableInlineTableEditing",false);this.rteCommand(this.areaId,"useCSS",true)};this.attachDoubleClickEventHandlers=function(c){jQuery(c.body).find("a").unbind("dblclick");
jQuery(c.body).find("img.WikiAnchor").unbind("dblclick");jQuery(c.body).find(".WikiMedia").not(".WikiMediaFile").unbind("dblclick");jQuery(c.body).find("img.WikiAnchor").dblclick(function(){b.editor.toolbar.linkToolbar.openAnchor(this)});jQuery(c.body).find(".WikiMedia").not(".WikiMediaFile").dblclick(function(){b.editorEmbedMedia()});jQuery(c.body).find(".WikiReference").dblclick(function(){b.referenceTool.openReferencePopup(this.id+"-Area")})};this.handleTabs=function(c){if(!(c.ctrlKey||c.altKey))if(c.keyCode==
"9"){var f=this.getSelectionContainer();if(jQuery(f).is("li")||jQuery(f).parents("li").length>0){if(jQuery.browser.mozilla&&jQuery.browser.version.substring(0,3)>=1.9){if(c.shiftKey){this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"outdent","")}else{this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"indent","")}c.preventDefault();c.stopPropagation()}}else if(jQuery(f).is("td,th")||jQuery(f).parents("td,th").length>0){var g;g=jQuery(f).is("td,th")?jQuery(f):
jQuery(f).parents("td,th").eq(0);if(c.shiftKey){f=g.prev("td,th");if(f.length==0&&g.parents("tr").eq(0).prev("tr").length>0)f=g.parents("tr").eq(0).prev("tr").find("td,th").eq(g.parents("tr").eq(0).prev("tr").find("td,th").length-1);if(!f.length){this.tableTool.addNewRow(false,true);f=g.parents("tr").eq(0).prev("tr").find("td,th").eq(g.parents("tr").eq(0).prev("tr").find("td,th").length-1)}}else{f=g.next("td,th");if(f.length==0&&g.parents("tr").eq(0).next("tr").length>0)f=g.parents("tr").eq(0).next("tr").find("td,th").eq(0);
if(!f.length){this.tableTool.addNewRow(false,false);f=g.parents("tr").eq(0).next("tr").find("td,th").eq(0)}}if(f.length){f=f.get(0);var h=this.getEditorWindow().document;if(jQuery.browser.msie){this.getEditorWindow().focus();h.selection.empty();g=h.selection.createRange();g.moveToElementText(f);g.select()}else if(jQuery.browser.safari){g=this.getEditorWindow().getSelection();h=h.createRange();h.setStart(this.findTextNode(f),0);h.setEnd(this.findTextNode(f),0);g.removeAllRanges();g.addRange(h)}else{g=
new Selection(this.getEditorWindow());h=g.getRangeAt(0);h.setStart(f,0);h.collapse(true)}this.selectElement(f);c.preventDefault();c.stopPropagation()}else this.detectedChange()}}};this.findTextNode=function(c){for(var f,g=0;g<c.childNodes.length;g++){f=c.childNodes[g];if(f.nodeType==3)return f;else if(f.nodeType==1){f=this.findTextNode(f);if(f.nodeType==3)return f}}return null};this.keyEventHandler=function(c){typeof this.updateHierarchyHandle=="number"&&clearTimeout(this.updateHierarchyHandle);this.updateHierarchyHandle=
setTimeout(function(){b.updateHierarchy()},100);switch(c.keyCode){case 16:case 17:case 18:case 20:case 91:case 93:case 45:case 255:case 9:break;case Event.KEY_ESC:case Event.KEY_LEFT:case Event.KEY_UP:case Event.KEY_RIGHT:case Event.KEY_DOWN:case Event.KEY_PAGEUP:case Event.KEY_PAGEDOWN:case Event.KEY_END:case Event.KEY_HOME:this.selectElement(c.target);break;case Event.KEY_BACKSPACE:case Event.KEY_RETURN:case Event.KEY_DELETE:this.selectElement(c.target);this.detectedChange();break;default:this.detectedChange()}};
this.mouseEventHandler=function(c){typeof this.updateHierarchyHandle=="number"&&clearTimeout(this.updateHierarchyHandle);this.updateHierarchyHandle=setTimeout(function(){b.updateHierarchy()},100);this.selectElement(c.target)};this.selectElement=function(c){log("selectElement",c);var f=false;if(this!=this.editor.getCurrentArea()){log("selectElement called on non active editor, switch",this);this.editor.setCurrentArea(this.areaId)}if(jQuery(c).is("html"))c=this.getSelectionContainer();if(c.parentNode&&
jQuery(c).is("img")&&(jQuery(c).is(".WikiMediaFile")||!jQuery(c).is(".WikiAnchor, .WikiMedia, .WikiReference"))){log("selectElement: image on");this.imageTool.selectImage(c);jQuery(c).is(".WikiFile")||(f=true)}else if(this.imageTool.selectedImage){log("selectElement: image off");this.imageTool.unSelectImage()}if(c.parentNode&&jQuery(c).is("img.WikiMedia, img.WikiAnchor, img.WikiReference")&&!jQuery(c).is(".WikiMediaFile")){log("selectElement: media on");this.mediaTool.selectMedia(c);var g=c.id.match(/wikitext@@(.*)@@/);
if(g&&g.length>0)if(g[1]=="media")if(c.id.match(/type="(.*)"\s/)[1]!="custom")f=true}else if(this.mediaTool.selectedMedia){log("selectElement: media off");this.mediaTool.unSelectMedia()}if(jQuery(c).is("td,th")){log("selectElement: table on");this.tableTool.selectTableCell(c)}else if(jQuery(c).parents("td,th").length>0){log("selectElement: table on");this.tableTool.selectTableCell(jQuery(c).parents("td,th").get(0))}else if(this.tableTool.selectedTableCell){log("selectElement: table off");this.tableTool.unselectTableCell()}if(f!=
this.currentResizing){this.rteCommand(this.areaId,"enableObjectResizing",f);this.currentResizing=f}};this.getSelectionContainer=function(){if(this.imageTool.selectedImage&&this.imageTool.selectedImage.parentNode){var c=this.imageTool.selectedImage;return c}if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode)return c=this.mediaTool.selectedMedia;this.getEditorWindow();c=this.getEditorWindow().document;if(jQuery.browser.msie){this.getEditorWindow().focus();return this.getRangeParent(c.selection.createRange())}else{this.getEditorWindow().focus();
return c=this.getEditorWindow().getSelection().getRangeAt(0).commonAncestorContainer}};this.isSelectionUnderTag=function(c,f){for(c=this.getSelectionContainer();c!=null;){if(c.tagName==f)return c;c=c.parentNode}return false};this.updateHierarchy=function(){log("updateHierarchy top");typeof this.updateHierarchyHandle=="number"&&clearTimeout(this.updateHierarchyHandle);var c=this.getSelectionContainer(),f="";if(!(null!=this.updateHierarchyElement&&c==this.updateHierarchyElement)){this.updateHierarchyElement=
c;for(this.unsetAllButtons();c&&c.tagName!="BODY"&&c.tagName!="HTML";){if(c.tagName){this.setChildStatus(c);f=c.tagName+" &gt; "+f}else f="text &gt; "+f;c=c.parentNode}if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode){jQuery(this.mediaTool.selectedMedia).is(".WikiAnchor")?this.setButton("rteLinkBtn"):this.setButton("rteMediaBtn");this.unsetButton("rteImageBtn")}jQuery("#hierarchy").html(f)}};this.unsetAllButtons=function(){jQuery("#wikispacesEditorToolbar .rteButtonActive").removeClass("rteButtonActive");
this.setFormat("p")};this.setFormat=function(c){jQuery("#rteFormatBlock").val("<"+c+">");c=="pre"||c=="code"?jQuery("#rteFormatBlock").attr("disabled",true):jQuery("#rteFormatBlock").attr("disabled",false)};this.setChildStatus=function(c){switch(c.tagName){case "STRONG":case "B":this.setButton("rteBoldBtn");break;case "EM":case "I":this.setButton("rteItalicBtn");break;case "U":this.setButton("rteUnderlineBtn");break;case "OL":this.setButton("rteOrderedListBtn");break;case "UL":this.setButton("rteUnorderedListBtn");
break;case "A":this.setButton("rteLinkBtn");break;case "IMG":this.setButton("rteImageBtn");break;case "TABLE":this.setButton("rteTableBtn");break;case "H1":this.setFormat("h1");break;case "H2":this.setFormat("h2");break;case "H3":this.setFormat("h3");break;case "H4":this.setFormat("h4");break;case "H5":this.setFormat("h5");break;case "H6":this.setFormat("h6");break;case "PRE":this.setCodeFormat(c.className);this.setButton("rteCodeBtn");break;case "SPAN":if(jQuery(c).attr("style")||jQuery(c).attr("class"))this.setButton("rteTextColorBtn");
break}c.style.fontStyle=="italic"&&this.setButton("rteItalicBtn");c.style.fontWeight=="bold"&&this.setButton("rteBoldBtn");c.style.textDecoration=="underline"&&this.setButton("rteUnderlineBtn")};this.setCodeFormat=function(c){this.setFormat("code");var f="Code";if(c)f+=" ("+c+")";document.getElementById("rteFormatBlock").options[document.getElementById("rteFormatBlock").selectedIndex].innerHTML=f};this.setButton=function(c){jQuery("#"+c).addClass("rteButtonActive")};this.unsetButton=function(c){jQuery("#"+
c).removeClass("rteButtonActive")};this.getContent=function(){if(this.editor.mode==this.editor.VISUAL){var c=this.getEditorWindow().document;bodyTags=c.getElementsByTagName("HTML")[0].getElementsByTagName("BODY");for(i=1;i<bodyTags.length;i++){bodyTags[0].innerHTML+=bodyTags[i].innerHTML;bodyTags[i].parentNode.removeChild(bodyTags[i])}return c.body.innerHTML}else return jQuery("#textEditor").val()};this.saveCursor=function(){if(jQuery.browser.msie)if(document.selection)if(this.editor.mode==this.editor.VISUAL){if(!(this.mediaTool.selectedMedia||
this.imageTool.selectedImage)){var c=this.getEditorWindow().document.selection.createRange(),f=document.selection.createRange();if(jQuery.browser.version.substring(0,1)>=8&&c.text==""){jQuery(this.getEditorWindow().document.body).find("#__IERANGE__").remove();this.insertInEditorActual('<span id="__IERANGE__"></span>',false)}else if(c.duplicate)this.cursorPos=c.duplicate();else if(f.duplicate)this.cursorPos=f.duplicate()}}else this.cursorPos=document.selection.createRange().duplicate()};this.restoreCursor=
function(){if(this.editor.mode==this.editor.VISUAL&&jQuery.browser.msie&&jQuery.browser.version.substring(0,1)>=8){var c=jQuery(this.getEditorWindow().document).find("#__IERANGE__").get(0);if(c&&jQuery(c).parents("body").length>0){try{var f=this.getEditorWindow().document.selection.createRange();f.moveToElementText(c);f.select();jQuery(this.getEditorWindow().document).find("#__IERANGE__").remove()}catch(g){}return}}if(this.cursorPos)try{this.cursorPos.select();delete this.cursorPos}catch(h){}};this.prepareSelection=
function(c){c.sel_text="";c.sel_text_pre="";c.sel_text_post="";c.sel_start=0;c.sel_end=0;c.cur_start=0;c.cur_end=0;c.focus();if(typeof c.selectionStart=="number"){c.sel_start=c.selectionStart;c.cur_start=c.selectionStart;c.sel_end=c.selectionEnd;c.cur_end=c.selectionEnd;c.sel_text=c.value.substring(c.sel_start,c.sel_end);c.sel_text_pre=c.value.substring(0,c.sel_start);c.sel_text_post=c.value.substring(c.sel_end,c.value.length)}else if(document.selection){var f=document.selection.createRange(),g=document.body.createTextRange();
g.moveToElementText(c);for(var h=0;g.compareEndPoints("StartToStart",f)<0;h++)g.moveStart("character",1);c.cur_start=h;for(g=0;g<=h;g++)c.value.charAt(g)=="\n"&&h++;c.sel_start=h;g=document.body.createTextRange();g.moveToElementText(c);for(h=0;g.compareEndPoints("StartToEnd",f)<0;h++)g.moveStart("character",1);c.cur_end=h;for(g=0;g<=h;g++)c.value.charAt(g)=="\n"&&h++;c.sel_end=h;c.sel_text=f.text;c.sel_text_pre=c.value.substring(0,c.sel_start);c.sel_text_post=c.value.substring(c.sel_end,c.value.length)}};
this.expandSelectionToLine=function(){var c=document.getElementById("textEditor");this.prepareSelection(c);for(var f,g=c.sel_start;g>=0;g--)if(c.value.substring(g,g+1)=="\n"){f=g+1;break}for(g=c.sel_end;g<c.value.length-1;g++)if(c.value.substring(g,g+1)=="\n"){this.setSelectionRange(c,f,g);return true}return false};this.expandSelectionToTag=function(c,f,g){var h=this.getSelectedText().replace(/^\s+/,"").replace(/\s+$/,"");if(h)return h.substring(0,f.length+c.length)==c+f&&h.substring(h.length-g.length,
h.length)==g?true:false;else{h=document.getElementById("textEditor");this.prepareSelection(h);var k=0,l=0,m=h.sel_start-1;if(m<0)m=0;var n=null;for(m=m;m>=0;m--)if(h.value.substring(m,m+f.length+c.length)==c+f)if(l==0){n=m;break}else l--;else if(h.value.substring(m,m+c.length)==c)return false;else h.value.substring(m,m+g.length)==g&&h.sel_start-m>=g.length&&l++;if(n==null)return false;m=h.sel_end-(g.length-1);if(m<0)m=0;if(m<n+f.length+c.length)m=n+f.length+c.length;for(m=m;m<h.value.length-1;m++)if(h.value.substring(m,
m+g.length)==g)if(k==0){this.setSelectionRange(h,n,m+g.length);return true}else k--;else h.value.substring(m,m+c.length)==c&&k++}return false};this.setSelectionRange=function(c,f,g){if(c.setSelectionRange)c.setSelectionRange(f,g);else{var h=f;g=g;for(var k=0;k<f;k++)if(c.value.charAt(k)=="\n"){h--;g--}c=c.createTextRange();with(c){collapse(true);moveEnd("character",g);moveStart("character",h);select()}}};this.cancelEdit=function(){this.editorConfirmDeparture=false;WikispacesCommon.track("Editor",
"Stop","Cancel");this.timeTracker._recordEndTime();this.timeTracker._track(pageTracker,undefined,"Editor");window.location=this.editor.cancelUrl;return false};this.hidePreview=function(){jQuery("#previewBox").hide();jQuery("#editor_wrap").show();jQuery("#toolbarPopup_table_content").show();jQuery("#toolbarPopup_table_content_preview").remove();if(this.editor.mode==this.editor.VISUAL){this.rteCommand(this.areaId,"enableObjectResizing",false);this.currentResizing=false;this.rteCommand(this.areaId,"enableInlineTableEditing",
false);this.rteCommand(this.areaId,"useCSS",true)}};this.fadeEditor=function(){jQuery(".contentBox").parents().each(function(){jQuery(this).prevAll(":not(.rbT)").filter(":not(#WikispacesHelp)").filter(":not(#editorlibs)").filter(":not(script)").css("opacity",0.3);jQuery(this).nextAll(":not(.rbB)").filter(":not(#WikispacesHelp)").filter(":not(#editorlibs)").filter(":not(script)").css("opacity",0.3)})};this.showPreview=function(){var c;WikispacesCommon.track("Editor","Preview");this.imageTool.unSelectImage();
this.mediaTool.unSelectMedia();this.tableTool.unselectTableCell();this.referenceTool.closeReferences();jQuery("#toolbarPopup_table_content").hide();jQuery("#toolbarPopup_table_content_spinner").remove();jQuery("#toolbarPopup_table_content").after('<td id="toolbarPopup_table_content_spinner" class="wikispaces_content">Loading Preview <img src="/i/spinner.gif" alt="" width="18" height="18" /></td>');if(this.editor.mode==this.editor.VISUAL){c=this.getEditorWindow().document;try{var f="safari,mso,merge";
if(jQuery(c).find("span").length!=this.startingSpanCount)f+=",collapse";f+=",empty";this.styleTool.cleanup(c.body,f,true)}catch(g){}this.rteSync(this.areaId);c=document.getElementById("hdn"+this.areaId).value}else c=this.getContent();jQuery.ajax({async:false,cache:false,data:{content:c,mode:this.editor.mode},dataType:"xml",global:false,error:function(){reloadSession(function(){b.showPreview()},3E3,function(){jQuery("#toolbarPopup_table_content_spinner").remove();b.hidePreview();b.editor.sessionReloadFailed()})},
success:function(h){log("showPreviewResponse",h);reloadSessionSuccess();if(h.getElementsByTagName("preview").length>0){h=h.getElementsByTagName("preview")[0];var k="";if(h&&h.childNodes.length>0)for(var l=0;l<h.childNodes.length;l++)k+=h.childNodes[l].nodeValue;jQuery("#previewBox").html(k);jQuery("#previewBox").show();jQuery("#editor_wrap").hide();jQuery("#toolbarPopup_table_content_spinner").remove();jQuery("#toolbarPopup_table_content").after('<td id="toolbarPopup_table_content_preview" valign="top" align="right" class="wikispaces_content"><button type="submit" id="close" class="btn" value="1"><span><span>Continue Editing</span></span></button> <button type="submit" id="save" class="btn primary" name="update_preview" value="1"><span><span>Save</span></span></button></td>');
jQuery("#toolbarPopup_table_content_preview #close").click(function(m){b.hidePreview();m.preventDefault()});jQuery("#toolbarPopup_table_content_preview #save").click(function(m){document.rte.update.click();m.preventDefault()})}else if(h.getElementsByTagName("error").length>0){jQuery("#toolbarPopup_table_content_spinner").remove();b.hidePreview();h=h.getElementsByTagName("error")[0].getAttribute("message");alert(h)}else{jQuery("#toolbarPopup_table_content_spinner").remove();b.hidePreview();alert("An unexpected error occurred.")}},
type:"POST",url:"/page/preview/"+encodeURIComponent(wikispaces_page)})};this.getEditorWindow=function(c){if(!c)c=this.areaId;return document.getElementById(c).contentWindow};this.editorUnsavedChangesWarning=function(){if(this.editorConfirmDeparture&&document.rte.changeDetected.value){this.autosave();return"You have not yet saved your changes."}};this.getZIndex=function(){var c=jQuery("#"+this.areaId).parents(".dialog").css("z-index");c||(c=0);return c};this.autosaveDiscardDraft=function(c){WikispacesCommon.track("Editor",
"Autosave","Discard");var f="/page/discardautosave/"+encodeURIComponent(wikispaces_page);jQuery.ajax({url:f,type:"GET",global:false,cache:false});this.customEditorStartSecondary(c)};this.imageTool=new WikispacesImageTool(this);this.linkTool=new WikispacesLinkTool(this);this.styleTool=new WikispacesStyleTool(this);this.mediaTool=new WikispacesMediaTool(this);this.tableTool=new WikispacesTableTool(this);this.referenceTool=new WikispacesReferenceTool(this)}a=WikispacesEditorArea.prototype;
a.AUTOSAVE_INTERVAL=6E4;a.editorHeight=null;a.editorWidth=null;a.editorMinWidth=null;a.editorMaxWidth=null;a.concurrentEditors=[];a.concurrentEditorPopup=null;a.autosaveEnabled=true;a.autosaveLoop=function(){var e=this;try{this.autosave()}catch(d){}finally{setTimeout(function(){e.autosaveLoop()},this.AUTOSAVE_INTERVAL)}};
a.autosave=function(e){log("autosave",e);var d=this;if(typeof e=="undefined")e=true;this.editor.toolbar.setAutosaveStatus("Saving...");if(this.editor.mode==this.editor.VISUAL){var b=this.getEditorWindow().document;try{var c="safari,mso,merge";if(jQuery(b).find("span").length!=this.startingSpanCount)c+=",collapse";e||(c+=",empty");this.styleTool.cleanup(b.body,c)}catch(f){}}if(this.autosaveEnabled){b="/page/autosave/"+encodeURIComponent(wikispaces_page)+"/"+this.version+"?mode="+this.editor.mode;c=
this.getContent();if(this.editor.mode==this.editor.VISUAL)c=this.referenceTool.pushInReferences(c);c="content="+encodeURIComponent(c);jQuery.ajax({async:e,url:b,type:"POST",data:c,dataType:"xml",global:false,cache:false,error:function(){reloadSession(function(){d.autosave()},3E3,function(){d.editor.sessionReloadFailed()})},success:function(g){d.autosaveProcessResponse(g);reloadSessionSuccess()}});log("autosave finished")}};
a.autosaveProcessResponse=function(e){log("autosaveProcessResponse",e);if(e.getElementsByTagName("autosave")[0].getElementsByTagName("save").length>0)this.editor.toolbar.setAutosaveStatus("Draft Saved at "+e.getElementsByTagName("autosave")[0].getElementsByTagName("save")[0].firstChild.nodeValue,false);else e.getElementsByTagName("autosave")[0].getElementsByTagName("error").length>0&&this.editor.toolbar.setAutosaveStatus(e.getElementsByTagName("autosave")[0].getElementsByTagName("error")[0].getAttribute("message"),
true);if(e.getElementsByTagName("status").length>0&&e.getElementsByTagName("status")[0].getAttribute("type")=="changed"){var d=e.getElementsByTagName("status")[0].getElementsByTagName("revision");for(i=0;i<d.length;i++){var b=d[i].getElementsByTagName("user")[0].firstChild.nodeValue,c=d[i].getElementsByTagName("date")[0].firstChild.nodeValue;this.addSavedVersionDetected(d[i].getAttribute("id"),b,c)}}d=Array();var f=this.concurrentEditors.length>0;if(e.getElementsByTagName("concurrent").length>0){var g=
e.getElementsByTagName("concurrent")[0].getElementsByTagName("editor");for(i=0;i<g.length;i++){b=g[i].getElementsByTagName("user")[0].firstChild.nodeValue;c=g[i].getElementsByTagName("date")[0].firstChild.nodeValue;this.addConcurrentEditor(b,c);d[b]=1}f||WikispacesCommon.track("Editor","Concurrent Editing","Start")}for(b in this.concurrentEditors)d[b]!=1&&this.removeConcurrentEditor(b);f&&this.concurrentEditors.length==0&&WikispacesCommon.track("Editor","Concurrent Editing","End");this.concurrentEditors.length&&
WikispacesCommon.track("Editor","Concurrent Editing","Editor Count",this.concurrentEditors.length);if(e.getElementsByTagName("autosave")[0].getElementsByTagName("merge").length>0){e=e.getElementsByTagName("autosave")[0].getElementsByTagName("merge")[0];if(e.getElementsByTagName("mergeStatus").length>0&&e.getElementsByTagName("mergeStatus")[0].firstChild){b=e.getElementsByTagName("mergeStatus")[0].firstChild.nodeValue;document.getElementById("mergeStatus").innerHTML=b}if(e.getElementsByTagName("mergeResult").length>
0&&e.getElementsByTagName("mergeResult")[0].firstChild){b="";for(i=0;i<e.getElementsByTagName("mergeResult")[0].childNodes.length;i++)b+=e.getElementsByTagName("mergeResult")[0].childNodes[i].nodeValue;this.editor.mode==this.editor.PLAIN?jQuery("#mergeResult").val(b):jQuery("#mergeResult").html(b)}}jQuery("#saveDraftButton").attr("disabled",false).val("Save Draft")};
a.removeLock=function(){var e="/page/removepagelock/"+encodeURIComponent(wikispaces_page);jQuery.ajax({url:e,type:"GET",global:false,cache:false})};
a.addConcurrentEditor=function(e,d){this.showConcurrentEditorPopup();jQuery("#concurrentEditor_otherEditor_heading").show();this.concurrentEditors[e]=d;var b="concurrentEditor_otherEditor_"+e;if(!jQuery("#"+b).length){jQuery("#concurrentEditor_otherEditors").append('<li id="'+b+'"><img src="/user/pic/'+e+'-sm.jpg" height="16" width="16" style="vertical-align: text-top"/> '+e+" started editing this page at "+d+"</li>");jQuery("#concurrentEditor_noEditors").hide();jQuery("#"+b).effect("highlight",{color:WikispacesCommon.highlightColor},
2E3)}};a.removeConcurrentEditor=function(e){e=jQuery("#"+("concurrentEditor_otherEditor_"+e));if(e.length){e.slideUp();e.remove();jQuery("#concurrentEditor_otherEditors li").length==1&&jQuery("#concurrentEditor_noEditors").show().effect("highlight",{color:WikispacesCommon.highlightColor},2E3)}};
a.addSavedVersionDetected=function(e,d,b){this.anotherEditDetected=true;this.showConcurrentEditorPopup();jQuery("#concurrentEditor_savedVersion_heading").show();var c="concurrentEditor_savedVersion_"+e;if(!jQuery("#"+c).length){jQuery("#concurrentEditor_savedVersion_viewChanges").html('<a href="/page/diff/'+encodeURIComponent(wikispaces_page)+"?v1="+this.version+"&v2="+e+'" target="_new">View all changes since I started editing</a>');jQuery("#concurrentEditor_savedVersions").append('<li id="'+c+'"><img src="/user/pic/'+
d+'-sm.jpg" height="16" width="16" style="vertical-align: text-top;"/> '+d+" saved a new version at "+b+'.  <a href="/page/diff/'+encodeURIComponent(wikispaces_page)+"/"+e+'" target="_new">View the changes</a></li>');jQuery("#concurrentEditor_savedVersions li").length>1&&jQuery("#concurrentEditor_savedVersion_viewChanges").show();jQuery("#"+c).effect("highlight",{color:WikispacesCommon.highlightColor},2E3);this.removeConcurrentEditor(d)}};
a.showConcurrentEditorPopup=function(){var e=this;if(!this.concurrentEditorPopup){this.concurrentEditorPopup=new Window("concurrentEditorPopup",{minWidth:300,minHeight:100,title:"Page Activity",resizable:false,maximizable:false,minimizable:false,className:"wikispaces",showEffect:Element.show,hideEffect:Element.hide});this.concurrentEditorPopup.setHTMLContent(WikispacesToolbar.getContent("concurrentEditor"),true,true);document.getElementById("concurrentEditorPopup_content").style.overflowY="hidden";
if(jQuery.browser.msie==true&&jQuery.browser.version<7)WikispacesToolbar.registerOnScroll(function(){WikispacesToolbar.scrollWindow(e.concurrentEditorPopup,false)});else this.concurrentEditorPopup.element.style.position="fixed"}this.concurrentEditorPopup.element.style.left="0px";this.concurrentEditorPopup.show();this.concurrentEditorPopup.toFront();this.updateConcurrentEditorPopup()};
a.updateConcurrentEditorPopup=function(){this.concurrentEditorPopup.updateWidth();this.concurrentEditorPopup.updateHeight();if(jQuery.browser.msie){var e=document.documentElement.clientHeight+document.documentElement.scrollTop-jQuery(this.concurrentEditorPopup.element).height()+"px";if(e<this.concurrentEditorPopup.element.style.top)this.concurrentEditorPopup.element.style.top=e}else this.concurrentEditorPopup.element.style.top=document.documentElement.clientHeight-jQuery(this.concurrentEditorPopup.element).height()+
"px"};jQuery.fn.farbtastic=function(e){jQuery.farbtastic(this,e);return this};jQuery.farbtastic=function(e,d){e=jQuery(e).get(0);return e.farbtastic||(e.farbtastic=new jQuery._farbtastic(e,d))};
jQuery._farbtastic=function(e,d){var b=this;jQuery(e).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');var c=jQuery(".farbtastic",e);b.wheel=jQuery(".wheel",e).get(0);b.radius=84;b.square=100;b.width=194;b.firstClick=true;navigator.appVersion.match(/MSIE [0-6]\./)&&jQuery("*",c).each(function(){if(this.currentStyle.backgroundImage!="none"){var f=this.currentStyle.backgroundImage;
f=this.currentStyle.backgroundImage.substring(5,f.length-2);jQuery(this).css({backgroundImage:"none",filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+f+"')"})}});b.linkTo=function(f){typeof b.callback=="object"&&jQuery(b.callback).unbind("keyup",b.updateValue);b.color=null;if(typeof f=="function")b.callback=f;else if(typeof f=="object"||typeof f=="string"){b.callback=jQuery(f);b.callback.bind("keyup",b.updateValue);b.callback.get(0).value&&b.setColor(b.callback.get(0).value)}return this};
b.updateValue=function(){this.value&&this.value!=b.color&&b.setColor(this.value)};b.validColor=/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;b.setColor=function(f){if(!b.validColor.exec(f))return this;var g=b.unpack(f);if(g){b.color=f;b.rgb=g;b.hsl=b.RGBToHSL(b.rgb);b.updateDisplay()}return this};b.setHSL=function(f){b.hsl=f;b.rgb=b.HSLToRGB(f);b.color=b.pack(b.rgb);b.updateDisplay();return this};b.widgetCoords=function(f){var g,h,k=f.target||f.srcElement,l=b.wheel;if(typeof f.offsetX!="undefined"){var m=
{x:f.offsetX,y:f.offsetY};for(f=k;f;){f.mouseX=m.x;f.mouseY=m.y;m.x+=f.offsetLeft;m.y+=f.offsetTop;f=f.offsetParent}f=l;for(l={x:0,y:0};f;){if(typeof f.mouseX!="undefined"){g=f.mouseX-l.x;h=f.mouseY-l.y;break}l.x+=f.offsetLeft;l.y+=f.offsetTop;f=f.offsetParent}for(f=k;f;){f.mouseX=undefined;f.mouseY=undefined;f=f.offsetParent}}else{m=b.absolutePosition(l);g=(f.pageX||0*(f.clientX+jQuery("html").get(0).scrollLeft))-m.x;h=(f.pageY||0*(f.clientY+jQuery("html").get(0).scrollTop))-m.y}return{x:g-b.width/
2,y:h-b.width/2}};b.mousedown=function(f){if(!document.dragging){jQuery(document).bind("mousemove",b.mousemove).bind("mouseup",b.mouseup);document.dragging=true}var g=b.widgetCoords(f);b.circleDrag=Math.max(Math.abs(g.x),Math.abs(g.y))*2>b.square;b.mousemove(f);return false};b.mousemove=function(f){var g=b.widgetCoords(f);if(b.circleDrag){f=Math.atan2(g.x,-g.y)/6.28;if(f<0)f+=1;if(b.firstClick&&(b.hsl[2]==0||b.hsl[2]==1)){b.firstClick=false;b.setHSL([f,1,0.5])}else b.setHSL([f,b.hsl[1],b.hsl[2]])}else{f=
Math.max(0,Math.min(1,-(g.x/b.square)+0.5));g=Math.max(0,Math.min(1,-(g.y/b.square)+0.5));b.setHSL([b.hsl[0],f,g])}return false};b.mouseup=function(){jQuery(document).unbind("mousemove",b.mousemove);jQuery(document).unbind("mouseup",b.mouseup);document.dragging=false};b.updateDisplay=function(){var f=b.hsl[0]*6.28;jQuery(".h-marker",c).css({left:Math.round(Math.sin(f)*b.radius+b.width/2)+"px",top:Math.round(-Math.cos(f)*b.radius+b.width/2)+"px"});jQuery(".sl-marker",c).css({left:Math.round(b.square*
(0.5-b.hsl[1])+b.width/2)+"px",top:Math.round(b.square*(0.5-b.hsl[2])+b.width/2)+"px"});jQuery(".color",c).css("backgroundColor",b.pack(b.HSLToRGB([b.hsl[0],1,0.5])));if(typeof b.callback=="object"){jQuery(b.callback).css({backgroundColor:b.color,color:b.hsl[2]>0.5?"#000":"#fff"});jQuery(b.callback).each(function(){this.value=b.color})}else typeof b.callback=="function"&&b.callback.call(b,b.color)};b.absolutePosition=function(f){var g={x:f.offsetLeft,y:f.offsetTop};if(f.offsetParent){f=b.absolutePosition(f.offsetParent);
g.x+=f.x;g.y+=f.y}return g};b.pack=function(f){var g=Math.round(f[0]*255),h=Math.round(f[1]*255);f=Math.round(f[2]*255);return"#"+(g<16?"0":"")+g.toString(16)+(h<16?"0":"")+h.toString(16)+(f<16?"0":"")+f.toString(16)};b.unpack=function(f){if(f.length==7)return[parseInt("0x"+f.substring(1,3))/255,parseInt("0x"+f.substring(3,5))/255,parseInt("0x"+f.substring(5,7))/255];else if(f.length==4)return[parseInt("0x"+f.substring(1,2))/15,parseInt("0x"+f.substring(2,3))/15,parseInt("0x"+f.substring(3,4))/15]};
b.HSLToRGB=function(f){var g,h=f[0];g=f[1];f=f[2];g=f<=0.5?f*(g+1):f+g-f*g;f=f*2-g;return[this.hueToRGB(f,g,h+0.33333),this.hueToRGB(f,g,h),this.hueToRGB(f,g,h-0.33333)]};b.hueToRGB=function(f,g,h){h=h<0?h+1:h>1?h-1:h;if(h*6<1)return f+(g-f)*h*6;if(h*2<1)return g;if(h*3<2)return f+(g-f)*(0.66666-h)*6;return f};b.RGBToHSL=function(f){var g,h,k,l,m=f[0],n=f[1],o=f[2];g=Math.min(m,Math.min(n,o));f=Math.max(m,Math.max(n,o));h=f-g;l=(g+f)/2;k=0;if(l>0&&l<1)k=h/(l<0.5?2*l:2-2*l);g=0;if(h>0){if(f==m&&f!=
n)g+=(n-o)/h;if(f==n&&f!=o)g+=2+(o-m)/h;if(f==o&&f!=m)g+=4+(m-n)/h;g/=6}return[g,k,l]};jQuery("*",c).mousedown(b.mousedown);b.setColor("#000000");d&&b.linkTo(d)};
function WikispacesImageTool(e){this.area=e;var d=this;this.newImageIdCounter=0;this.pageCount=1;this.findCenteringElement=function(b){for(;b;){if(b.tagName&&(b.tagName.toUpperCase()=="CENTER"||b.tagName.toUpperCase()=="DIV"&&(b.style.textAlign=="center"||b.align=="center")))return b;if(b.parentNode)b=b.parentNode;else return null}return null};this.getImageAlignment=function(b){if(this.findCenteringElement(b))return"center";return b.align};this.updateImageCaption=function(b){if(this.selectedImage)this.selectedImage.alt=
b};this.unSelectImage=function(){if(this.selectedImage)this.selectedImage=null;this.area.editor.toolbar.imageToolbar.hideImagePropertiesPopup()};this.selectImage=function(b){this.unSelectImage();this.selectedImage=b;if(!jQuery(b).is(".WikiFile")){this.area.editor.toolbar.imageToolbar.showImagePropertiesPopup();this.area.editor.toolbar.imageToolbar.currentMode=="other"&&this.area.editor.toolbar.imageToolbar.setListMode("images");this.area.editor.toolbar.imageToolbar.setImageAlignment(this.getImageAlignment(b));
this.area.editor.toolbar.imageToolbar.setImageCaption(b.alt);b.parentNode.nodeName=="A"&&b.parentNode.href?this.area.editor.toolbar.imageToolbar.setImageLink(b.parentNode.href):this.area.editor.toolbar.imageToolbar.unsetImageLink();jQuery(b).is(".WikiMediaFile")?jQuery("#imageProperties .imageLink, #imageProperties .imageCaption").hide():jQuery("#imageProperties .imageLink, #imageProperties .imageCaption").show()}};this.setImageAlignment=function(b){if(this.selectedImage){if(b=="center")if(this.findCenteringElement(this.selectedImage))return;
else{this.selectedImage.align="";b=this.area.getEditorWindow().document.createElement("div");b.style.textAlign="center";var c=this.selectedImage;if(c.parentNode.nodeName=="A")c=this.selectedImage.parentNode;c.parentNode.appendChild(b);c.parentNode.replaceChild(b,c);b.appendChild(c)}else{if(c=this.findCenteringElement(this.selectedImage)){for(i=0;i<c.childNodes.length;i++)c.parentNode.insertBefore(c.childNodes.item(i),c);c.parentNode.removeChild(c)}this.selectedImage.align=b}this.area.editor.toolbar.imageToolbar.showImagePropertiesPopup();
this.area.detectedChange()}};this.insertImageInEditor=function(b,c){if(c=="image"){WikispacesCommon.track("Editor","Add Image",b);var f;f=b.substring(0,7)=="http://"||b.substring(0,8)=="https://"||b.substring(0,6)=="ftp://"?b:"/file/view/"+encodeURIComponent(b);var g=new Image;g.src=f;this.area.editor.mode==this.area.editor.VISUAL&&jQuery(g).load(function(){d.area.lookForHeightChange()});jQuery(g).ready(function(){d.area.insertImageInEditorCallback(b,c,g)})}else{WikispacesCommon.track("Editor","Add File",
b);this.area.insertImageInEditorCallback(b,c,null)}};this.adjustImageSize=function(b,c,f){if(this.selectedImage){var g=jQuery(this.selectedImage),h=new Image;if(h.height>0||h.width>0)this.adjustImageSizeCallback(g,h,b,c,f);else{jQuery(h).load(function(){d.adjustImageSizeCallback(g,h,b,c,f)});h.src=g.attr("src")}}return false};this.adjustImageSizeCallback=function(b,c,f,g,h){var k=b.height()/c.height,l=b.width()/c.width,m,n;if(g){m=c.height;n=c.width}else if(h)if(c.width>800){n=800;m=Math.round(800/
c.width*c.height)}else{n=c.width;m=c.height}else if(f!=0){m=Math.floor(c.height*(k+f));n=Math.floor(c.width*(l+f))}if(m>0&&n>0&&m>=Math.floor(c.height*0.05)&&n>=Math.floor(c.width*0.05)){b.height(m);b.width(n);this.area.editor.mode==this.area.editor.VISUAL&&this.area.lookForHeightChange()}if(g){jQuery(b).css("height","").css("width","");if(b.removeAttribute){b.removeAttribute("height");b.removeAttribute("width")}else{b.height=undefined;b.width=undefined}}};this.removeImage=function(){if(this.selectedImage){jQuery(this.selectedImage).remove();
this.selectedImage=null;this.area.editor.toolbar.imageToolbar.hideImagePropertiesPopup()}return false}}
function WikispacesImageToolbar(e){this.toolbar=e;this.MAX_ROWS=this.MAX_PER_ROW=8;this.PER_PAGE=6;this.IMAGE_SIZE=32;this.externalPosition=this.uploadPosition=0;this.currentMode="all";this.newUploads=[];this.swfu=null;var d=this;this.toggleImageEditTool=function(){WikispacesCommon.track("Editor","Open Image Tool");this.toolbar.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.imageListPopupWindow){this.imageListPopupWindow=new Window("imageListPopup",
{minWidth:602,minHeight:425,title:"Images & Files",resizable:false,minimizable:false,maximizable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal");d.toolbar.editor.getCurrentArea().restoreCursor()},showEffect:Element.show,hideEffect:Element.hide});this.imageListPopupWindow.setHTMLContent(WikispacesToolbar.getContent("imageTool"),true,false);this.imageListPopupWindow.getContent().style.overflow="hidden";this.setup();this.showPage(1);this.tagFilter.showPage(1)}WikispacesToolbar.setPopupSize(this.imageListPopupWindow,
true);this.imageListPopupWindow.toFront();this.imageListPopupWindow.showCenter()};this.addPage=function(b){var c=document.createElement("a");c.href="#";jQuery(c).click(function(){WikispacesCommon.track("Editor","Show File Page",b);d.showPage(b);return false});jQuery(c).html(b);jQuery(c).addClass("pageNumber");jQuery("#imagePages").append(c).append("&nbsp;")};this.showPage=function(b){this.showFileSpinner();var c=(b-1)*this.PER_PAGE,f=this.PER_PAGE,g="";if(document.imageToolForm.filename.value!=document.imageToolForm.filename.title)g=
document.imageToolForm.filename.value;var h=this.tagFilter.getTags();c="/file/listjson/"+encodeURIComponent(this.currentMode)+"?offset="+encodeURIComponent(c)+"&pageLimit="+encodeURIComponent(f)+"&filename="+encodeURIComponent(g)+"&tag="+encodeURIComponent(h);jQuery.ajaxq("imageList");jQuery.ajaxq("imageList",{url:c,type:"GET",dataType:"json",global:false,cache:false,error:function(){reloadSession(function(){d.showPage(b)},3E3,function(){d.toolbar.editor.sessionReloadFailed()})},success:function(k){reloadSessionSuccess();
d.loadFileData(k);WikispacesToolbar.setPopupSize(d.imageListPopupWindow,true);d.imageListPopupWindow.showCenter()}})};this.showFileSpinner=function(){jQuery("#filenameAutocomplete").css("background","white url('/i/spinner.gif') no-repeat center right")};this.hideFileSpinner=function(){jQuery("#filenameAutocomplete").css("background-image","none")};this.setListMode=function(b){jQuery(document.forms.imageToolForm.listMode).val(b);this.currentMode=b;this.tagFilter.setMode(b);this.showPage(1);this.tagFilter.showPage(1)};
this.getCell=function(b,c){return jQuery("#"+b+" tr").eq(Math.floor(c/this.MAX_PER_ROW)).find("td").get(c%this.MAX_PER_ROW)};this.addRow=function(b){var c=document.createElement("tr");for(j=0;j<this.MAX_PER_ROW;j++)c.appendChild(document.createElement("td"));jQuery("#"+b).append(c)};this.addFileRow=function(b,c,f,g,h){var k,l=c;if(f=="image"||this.isImage(f)){k="image";if(g)l=g}else k=this.isAudio(f)?"audio":this.isVideo(f)?"video":"file";li1=jQuery("<li>").attr("title",c).addClass("active");h||li1.click(function(){d.toolbar.editor.getCurrentArea().imageTool.insertImageInEditor(l,
k);d.imageListPopupWindow.close()});b=document.createElement("img");if(k=="image"&&g){b.src=g;if(b.height>b.width){b.width=b.width/b.height*d.IMAGE_SIZE;b.height=d.IMAGE_SIZE}else{b.height=b.height/b.width*d.IMAGE_SIZE;b.width=d.IMAGE_SIZE}}else{b.src="/file/thumbnail/"+encodeURIComponent(c)+"?size="+d.IMAGE_SIZE+(h?"&rnd="+Math.random():"");b.width=d.IMAGE_SIZE;b.height=d.IMAGE_SIZE}jQuery(li1).append(b).append(jQuery('<div class="fileName">').text(WikispacesCommon.truncify(c,40)));jQuery("#imageDiv .fileList ul").append(li1);
return li1};this.addFileCell=function(b,c,f,g,h,k){var l=b+"-file-"+g,m=this.getCell(b,g);if(!m){this.addRow(b);WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);m=this.getCell(b,g)}var n,o=c;if(f=="image"||this.isImage(f)){n="image";if(h)o=h}else n=this.isAudio(f)?"audio":this.isVideo(f)?"video":"file";b=document.createElement("td");b.style.textAlign="center";b.style.padding="5px;";b.title=c;jQuery(b).dblclick(function(){d.toolbar.editor.getCurrentArea().imageTool.insertImageInEditor(o,
n);d.imageListPopupWindow.close()});k||(k=document.createElement("img"));if(n=="image"&&h){k.src=h;if(k.height>k.width){k.width=k.width/k.height*d.IMAGE_SIZE;k.height=d.IMAGE_SIZE}else{k.height=k.height/k.width*d.IMAGE_SIZE;k.width=d.IMAGE_SIZE}}else{k.src="/file/thumbnail/"+encodeURIComponent(c)+"?size="+d.IMAGE_SIZE;k.width=d.IMAGE_SIZE;k.height=d.IMAGE_SIZE}k.onmousedown=function(){return false};h=document.createElement("div");h.className="WikiUploadFileEditor";h.appendChild(k);b.appendChild(h);
c=jQuery("<span>").attr("id",l).text(WikispacesCommon.truncate(c,13));jQuery(h).append("<br/>").append(c);m.parentNode.replaceChild(b,m)};this.resetPages=function(){jQuery("#imagePages").empty();var b=1,c=this.pageCount;if(this.pageCount>7){b=this.currentPage-1;if(b<1)b=1;c=b+1;if(c>this.pageCount)c=this.pageCount}for(var f=1+c-b+(c==this.pageCount?0:1)+(b==1?0:1),g=0;f<7&&(b!=1||c!=this.pageCount);){if(g%2){b--;if(b<1)b=1}else{c++;if(c>this.pageCount)c=this.pageCount}g++;f=1+c-b+(c==this.pageCount?
0:1)+(b==1?0:1)}if(this.pageCount>1){if(this.currentPage==1)jQuery("#imagePages").append('<span class="pageFirst inactive">&laquo; Previous</span>');else{f=jQuery('<a href="#" class="pageFirst">&laquo; Previous</a>').click(function(){d.showPage(d.currentPage-1)});jQuery("#imagePages").append(f)}if(b>1){this.addPage(1);b>2&&jQuery("#imagePages").append(" ... ")}for(g=b;g<=c;g++)this.addPage(g);if(this.pageCount>c){c+1<this.pageCount&&jQuery("#imagePages").append(" ... ");this.addPage(this.pageCount)}if(this.currentPage==
this.pageCount)jQuery("#imagePages").append('<span class="inactive">Next &raquo;</span>');else{b=jQuery('<a href="#">Next &raquo;</a>').click(function(){d.showPage(d.currentPage+1)});jQuery("#imagePages").append(b)}}};this.loadFileData=function(b){jQuery(document.imageToolForm).find(".fileList ul").empty();var c=0;if(this.currentMode=="myrecent"){var f=(d.currentPage-1)*d.PER_PAGE;jQuery.each(this.newUploads,function(k,l){if(!(k<f)){if(c>=d.PER_PAGE)return false;var m=d.addFileRow("imageTable",l.f_name,
l.r_mime_type,null,true);jQuery(m).attr("id","swfu_file_"+l.id).find("div.fileName").append("&nbsp;&nbsp;").append(jQuery("<a>").attr("href","#").addClass("uploadCancelButton").attr("id",l.id+"cancel").text("cancel").click(function(n){m.remove();d.swfu.swfu.cancelUpload(l.id,false);n.preventDefault()})).append('<div class="progressContainer"><div class="progressBar" id="'+l.id+'progress"></div></div>');c++}})}jQuery.each(b.files,function(k,l){if(c>=d.PER_PAGE)return false;d.addFileRow("imageTable",
l.f_name,l.r_mime_type);c++});if(!c){var g=jQuery("<li>").text("No files found").addClass("nodata");jQuery("#imageDiv .fileList ul").append(g);c++}for(;c<this.PER_PAGE;){g=document.createElement("li");var h=document.createElement("img");h.src="/i/c.gif";h.height=d.IMAGE_SIZE;h.width=d.IMAGE_SIZE;g.appendChild(h);g.appendChild(document.createTextNode(" "));jQuery("#imageDiv .fileList ul").append(g);c++}this.pageCount=b.pagedata.numpages;this.currentPage=b.pagedata.current;this.resetPages();this.highlightPage(this.currentPage);
this.hideFileSpinner()};this.highlightPage=function(b){jQuery("#imagePages a.pageNumber").each(function(){jQuery(this).html()==b?jQuery(this).addClass("pageCurrent"):jQuery(this).removeClass("pageCurrent")})};this.externalImageOnloadCallback=function(b){if(b.height==0)alert("The external image could not be found.");else{var c=b.src,f=c.match(/.*\/([^\/\?]+)/);f.length==2&&this.addFileCell("externalTable",f[1],"image",this.externalPosition++,c,b)}};this.showExternalImage=function(){var b=document.getElementById("externalImageUrl").value;
if(b){var c=new Image;jQuery(c).one("load",function(){d.externalImageOnloadCallback(c)});jQuery(c).one("error",function(){alert("The external image could not be found.")});c.src=b}else alert("Please enter the address of an external image.")};this.setup=function(){for(i=0;i<this.MAX_ROWS;i++)this.addRow("externalTable");reloadSessionAt(0);WikispacesCommon.setInputDefaults(jQuery("#imageDivTable .fileNameField"),"searchDefault");jQuery(document.imageToolForm.listMode).change(function(){d.setListMode(jQuery(this).val())});
wikispaces_isUserLoggedIn||jQuery("#uploadFileWrapper").hide();jQuery("#externalImageDiv form").submit(function(){d.showExternalImage();return false});jQuery("#imageDiv .tabs .tab").each(function(f){switch(f%2){case 0:jQuery(this).click(function(){d.switchToFile();return false});break;case 1:jQuery(this).click(function(){d.switchToExternal();return false});break}});jQuery(document.imageToolForm).submit(function(f){f.preventDefault()});jQuery(document.imageToolForm.filename).keyup(function(){d.showPage(1);
d.tagFilter.showPage(1)});wikispaces_username&&jQuery(document.imageToolForm.listMode).append('<option value="myrecent">My Recent Uploads</option>');jQuery("#imageDiv").find(".autocompleteSpace, .autocompleteTag, .autocompletePage").each(function(){WikispacesAutocomplete.initAutocomplete(this)});this.tagFilter=WikispacesCOB.initFilter(jQuery("#imageDiv .filterWrapper"),{tagChangeCallback:function(){d.showPage(1)},sessionFailCallback:function(){d.toolbar.editor.sessionReloadFailed()},tagPageChangeCallback:function(){WikispacesToolbar.setPopupSize(d.imageListPopupWindow,
true);d.imageListPopupWindow.showCenter()}});-1!=navigator.platform.indexOf("Mac")&&jQuery("#ctrlKeyName").html("&#8984;");try{this.swfu=new WikispacesCommon.swfUpload(this.toolbar.editor.uploadUrl,this.toolbar.editor.maxFileSize);this.swfu.swfu.queueSettings.user_upload_complete_handler=function(f){this.requireRefresh=true;jQuery("#swfu_file_"+f.id).attr("id","").find(".progressContainer").remove();jQuery("#"+f.id+"cancel").remove();return true};this.swfu.swfu.settings.file_queued_handler=function(f){var g=
"application/octet-stream",h=f.name;if(d.isImageFilename(f.name)){g="image";f.name=f.name.replace(/\s/g,"_")}d.newUploads.push({f_name:h,r_mime_type:g,id:f.id})};this.swfu.swfu.settings.queue_complete_handler=function(){d.newUploads=[];jQuery("#cancelQueueBtn").hide();jQuery("#uploadFileWrapper").width("auto").height("auto");var f=jQuery("<iframe>").hide().load(function(){d.setListMode("myrecent")});jQuery("body").append(f);f.attr("src",WikispacesCommon.addUriParams(this.customSettings.confirmUploadUrl,
[["remoteMode","true"]]))};var b=this.swfu.swfu.settings.file_dialog_complete_handler;this.swfu.swfu.settings.file_dialog_complete_handler=function(){if(d.newUploads.length>0){d.setListMode("myrecent");jQuery("#imageDivTable .filterTagShow").effect("highlight",{},3E3);jQuery("#uploadFileWrapper").width("1px").height("1px");jQuery("#cancelQueueBtn").removeClass("hidden").show()}b.call(this)};jQuery("#cancelQueueBtn").click(function(){d.swfu.swfu.cancelQueue();d.newUploads=[];jQuery(this).attr("disabled",
"disabled").hide();jQuery("#uploadFileWrapper").width("auto").height("auto");jQuery(".progressContainer").remove();jQuery(".uploadCancelButton").remove();var f=jQuery("<iframe>").hide().load(function(){d.setListMode("myrecent")});jQuery("body").append(f);f.attr("src",WikispacesCommon.addUriParams(d.swfu.swfu.customSettings.confirmUploadUrl,[["remoteMode","true"]]))})}catch(c){}};this.switchToFile=function(){WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);jQuery("#imageDiv .styleFile").show();
jQuery("#imageDiv .styleExternal").hide()};this.switchToExternal=function(){WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);jQuery("#imageDiv .styleFile").hide();jQuery("#imageDiv .styleExternal").show()};this.isImage=function(b){return b=="image/png"||b=="image/x-png"||b=="image/jpeg"||b=="image/gif"||b=="image/jpg"||b=="image/pjpeg"?true:false};this.isImageFilename=function(b){return b.match(/.*\.(?:gif|jpg|jpeg|png)$/i)};this.isMedia=function(b){return this.isAudio(b)||this.isVideo(b)};
this.isAudio=function(b){switch(b){case "audio/mpeg":case "audio/mpg":case "audio/mp3":case "audio/x-mp3":case "audio/x-mpeg":case "audio/x-mpg":case "application/asx":case "application/x-mplayer2":case "audio/x-ms-wma":case "audio/x-ms-wax":case "audio/3gpp":case "audio/3gpp2":case "audio/aac":case "audio/x-aac":case "audio/aiff":case "audio/x-aiff":case "audio/mid":case "audio/midi":case "audio/x-midi":case "audio/mp4":case "audio/m4a":case "audio/x-m4a":case "audio/wav":case "audio/x-wav":case "audio/x-pn-realaudio":case "audio/x-pn-realaudio-plugin":return true}return false};
this.isVideo=function(b){switch(b){case "video/x-ms-asf-plugin":case "video/x-ms-asf":case "video/x-ms-wm":case "video/x-ms-wmv":case "video/x-ms-wvx":case "video/avi":case "video/3gpp":case "video/3gpp2":case "video/m4v":case "video/x-m4v":case "video/mp4":case "video/mpeg":case "video/x-mpeg":case "video/quicktime":case "video/sd-video":case "video/flv":case "video/x-flv":case "application/x-shockwave-flash":case "application/futuresplash":return true}return false};this.showImagePropertiesPopup=
function(){if(!this.imagePropertiesPopupWindow){this.imagePropertiesPopupWindow=new Window("content_win",{minWidth:270,minHeight:95,title:"File Properties",resizable:false,className:"wikispaces",minimizable:false,maximizable:false,showEffect:Element.show,hideEffect:Element.hide});this.imagePropertiesPopupWindow.setHTMLContent(WikispacesToolbar.getContent("imageProperties"),true,false);this.imagePropertiesPopupWindow.getContent().style.overflow="hidden";this.setupProperties()}this.imagePropertiesPopupWindow.show();
this.imagePropertiesPopupWindow.toFront();var b=jQuery(this.toolbar.editor.getCurrentArea().imageTool.selectedImage),c=new Image;c.src=b.attr("src");if(c.height>0||c.width>0){this.toggleFitImage(b);this.adjustImagePropertiesPopup()}else jQuery(c).load(function(){d.toggleFitImage(b);d.adjustImagePropertiesPopup()})};this.adjustImagePropertiesPopup=function(){WikispacesToolbar.setPopupSize(this.imagePropertiesPopupWindow);var b=this.toolbar.getPositionWith(this.imagePropertiesPopupWindow.element,this.toolbar.editor.getCurrentArea().imageTool.selectedImage);
this.imagePropertiesPopupWindow.setLocation(b.top-10,b.left-10)};this.setupProperties=function(){jQuery("#imageAlign").click(function(){d.toolbar.editor.getCurrentArea().imageTool.setImageAlignment(jQuery(this).val())});jQuery("#changeLink").click(function(){d.toolbar.linkToolbar.openLinkPopup();return false});jQuery("#removeLink").click(function(){var b=d.toolbar.editor.getCurrentArea().imageTool.selectedImage;jQuery(b).parent("a").replaceWith(jQuery(b).parent("a").contents());d.toolbar.editor.getCurrentArea().imageTool.selectImage(b);
return false});jQuery("#addLink").click(function(){d.toolbar.linkToolbar.openLinkPopup();return false});jQuery("#imageSizeDown").click(function(){d.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(-0.1);return false});jQuery("#imageSizeUp").click(function(){d.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(0.1);return false});jQuery("#imageSizeOriginal").click(function(){d.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(0,true);return false});jQuery("#imageSizeFit").click(function(){d.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(0,
false,true);return false});jQuery("#imageCaptionInput").keyup(function(){d.toolbar.editor.getCurrentArea().imageTool.updateImageCaption(this.value)});jQuery("#imageCaptionInput").change(function(){d.toolbar.editor.getCurrentArea().imageTool.updateImageCaption(this.value)});jQuery("#imageRemoveLink").click(function(){d.toolbar.editor.getCurrentArea().imageTool.removeImage();return false})};this.toggleFitImage=function(b){b.width>800?jQuery("#imageSizeFit").show():jQuery("#imageSizeFit").hide()};this.hideImagePropertiesPopup=
function(){this.imagePropertiesPopupWindow&&this.imagePropertiesPopupWindow.hide()};this.setImageLink=function(b){jQuery("#imageLink").html(b).attr("title",b);jQuery("#imageLinkControlsActive").show();jQuery("#imageLinkControlsInactive").hide();this.adjustImagePropertiesPopup()};this.unsetImageLink=function(){jQuery("#imageLink").html("None").attr("title",null);jQuery("#imageLinkControlsActive").hide();jQuery("#imageLinkControlsInactive").show();this.adjustImagePropertiesPopup()};this.setImageCaption=
function(b){jQuery("#imageCaptionInput").val(b)};this.setImageAlignment=function(b){jQuery("#imageAlign").val(b)}}
function WikispacesInlineEditor(e,d,b,c){this.stylesheetUrl=e;this.cancelUrl=d;this.uploadUrl=b;this.maxFileSize=c;this.autosaveDetected=false;this.checkoutMessage=this.checkoutUser=this.checkoutStatus="";var f=this,g;this.disableEditButtons=function(h){jQuery(h).find(".editButton").css("cursor","default").attr("href","#").unbind("click",g).each(function(){var k=jQuery(this);if(!k.hasClass("WikiPageMenuEditButton"))return true;k.removeClass("WikiPageMenuEditButton").addClass("WikiPageMenuEditButtonDisabled")});
return true};this.enableEditButtons=function(h,k){log("enabledEditButtons",h,k);var l=jQuery(h).find(".editButton").attr("href","/page/edit/"+encodeURIComponent(wikispaces_page)).css("cursor","pointer").each(function(){var m=jQuery(this);if(!m.hasClass("WikiPageMenuEditButtonDisabled"))return true;m.removeClass("WikiPageMenuEditButtonDisabled").addClass("WikiPageMenuEditButton")});g=function(m){jQuery(".WikiNotice").remove();jQuery(".WikiBanner").remove();jQuery("#WikiPageInfo").hide();try{if(jQuery("#editor_wrap").parents("#content_view").length>
0)throw"Unclosed elements on page";if(jQuery("#editor_wrap").parents("#WikiAdMargin").length==0)throw"Excessive closing elements on page";f.disableEditButtons(h);var n=(new WikispacesEditor("visual",f.stylesheetUrl,f.cancelUrl,f.uploadUrl,f.maxFileSize)).createArea(k);n.autosaveEnabled=wikispaces_isUserLoggedIn;f.editorEnable(n);m.preventDefault()}catch(o){log(o);h.href="/page/edit/"+encodeURIComponent(wikispaces_page);f.redirectToEditPage(false);return true}};l.click(g)};this.editorEnable=function(h){log("editorEnable",
h);if(jQuery.browser.opera)this.redirectToEditPage(true);else try{var k="/page/dump/"+encodeURIComponent(wikispaces_page)+"?format=Wikispaces2",l=this;jQuery.ajax({url:k,type:"GET",timeout:2E3,global:false,error:function(n,o,p){l.redirectToEditPageCallback(n,o,p)},success:function(n){l.editorEnableCallback(h,n)}})}catch(m){this.redirectToEditPage(false)}};this.redirectToEditPageCallback=function(h,k,l){log("redirectToEditPageCallback",k,l);this.redirectToEditPage(false)};this.redirectToEditPage=function(h){log("redirectToEditPage");
document.location="/page/edit/"+encodeURIComponent(wikispaces_page)+(h?"?texteditor=1":"")};this.editorEnableCallback=function(h,k){log("editorEnableCallback");if(this.loadXMLData(h,k)){if(this.checkoutStatus=="locked"&&(!wikispaces_isUserLoggedIn||this.checkoutUser!=wikispaces_username)){alert(this.checkoutMessage);this.enableEditButtons(document);return false}jQuery("#editor_wrap").show();if(h.customEditorStart("WikispacesEditorContentHidden",this.autosaveDetected)){this.inlineEditorDisplay();WikispacesCommon.track("Editor",
"Start","Inline");return true}}this.redirectToEditPage(false)};this.inlineEditorDisplay=function(){log("inlineEditorDisplay");jQuery("#content_view").remove();jQuery(".WikiAds").hide();jQuery("#WikiAdMargin").css("marginRight",0)};this.loadXMLData=function(h,k){log("loadXMLData");try{var l=k.getElementsByTagName("dump")[0].getElementsByTagName("content")[0],m="";if(l)for(var n=0;n<l.childNodes.length;n++)m+=l.childNodes[n].nodeValue;else return false;var o=k.getElementsByTagName("dump")[0].getElementsByTagName("version")[0];
if(o&&o.firstChild)h.version=o.firstChild.nodeValue;var p=k.getElementsByTagName("dump")[0].getElementsByTagName("editorCleanup")[0];if(p&&p.firstChild)h.editorCleanup=p.firstChild.nodeValue;if(m)document.getElementById("WikispacesEditorContentHidden").innerHTML=m;this.checkoutStatus=k.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutStatus")[0].firstChild.nodeValue;if(this.checkoutStatus=="locked"){this.checkoutUser=k.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutUser")[0].firstChild.nodeValue;
var r=k.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutDate")[0].firstChild.nodeValue;k.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutRefreshDate");this.checkoutMessage="This page was locked for editing by "+this.checkoutUser+" on "+r+".  The page will be available for editing after the changes have been saved."}if(k.getElementsByTagName("dump")[0].getElementsByTagName("autosave").length>0){var q=k.getElementsByTagName("dump")[0].getElementsByTagName("autosave")[0],
s=q.getElementsByTagName("autosaveContent")[0];k="";if(s&&s.childNodes.length>0)for(n=0;n<s.childNodes.length;n++)k+=s.childNodes[n].nodeValue;var t=q.getElementsByTagName("autosaveDate")[0].firstChild.nodeValue;h.autosaveVersion=q.getElementsByTagName("autosaveVersion")[0].firstChild.nodeValue;h.autosaveCleanup=q.getElementsByTagName("autosaveCleanup")[0].firstChild.nodeValue;document.getElementById("autosavePrompt").innerHTML='<h1>Draft Recovered</h1><p class="wikispaces_p">We have recovered an unsaved draft of this page, created '+
t+".</p>"+(h.autosaveVersion!=h.version?'<p class="wikispaces_p">However, another person has edited this page since your last draft.  If you continue, their changes will be overwritten. To view these changes, <a href="/page/diff/'+encodeURIComponent(wikispaces_page)+"?v1="+h.autosaveVersion+"&v2="+h.version+'">click here</a>.</p>':"");jQuery("#autosaveContent").val(k);this.autosaveDetected=true}return true}catch(u){log(u);return false}}}WikispacesInlineEditor.libsLoaded=false;
function WikispacesLinkTool(e){this.area=e;var d=this;this.addLink=function(b){var c=document.linkForm["linkText"+b].value;if(b=="Anchor")if(c.match(/[a-z][a-zA-Z0-9]+/)){if(this.area.editor.mode==this.area.editor.VISUAL){this.area.insertInEditor('<img src="/i/anchor.gif" class="WikiAnchor" alt="Anchor" id="wikitext@@anchor@@'+c+'" title="Anchor: '+c+'"/>');jQuery(this.area.getEditorWindow().document.body).find("#wikitext@@anchor@@"+c).ready(function(){d.area.lookForHeightChange()})}else this.area.insertInEditor("[[#"+
c+"]]");WikispacesCommon.track("Editor","Add Anchor",f);return true}else{alert("Please correct the anchor name error before continuing");return false}var f=document.linkForm.url.value,g=document.linkForm.space.value,h=document.linkForm.anchor.value,k=document.linkForm.pageName.value,l=document.linkForm["newWindow"+b].checked;if(b=="Wiki"){var m="";m=k;if(g==""||m==""){alert("Please enter a wiki and page name");return false}if(h!="")h="#"+h;f=g==wikispaces_spaceName?"/"+encodeURIComponent(m)+h:"http://"+
g+"."+wikispaces_domain+"/"+encodeURIComponent(m)+h;if(this.pageNameFailure){alert("Please correct the page name error before continuing");return false}if(this.anchorFailure){alert("Please correct the anchor error before continuing");return false}}else if(f==""){alert("Please enter a URL");return false}else f.match(/^(?:[a-zA-Z0-9.+-]+:\/\/|mailto:)/)||(f=f.indexOf("@")>0?"mailto:"+f:"http://"+f);if(this.linkTextFailure){alert("Please correct the link text error before continuing");return false}if((k=
this.area.imageTool.selectedImage)&&k.parentNode&&k.src){b=this.area.getEditorWindow();if(k.parentNode.nodeName=="A"){k.parentNode.setAttribute("href",f);l?k.parentNode.setAttribute("target","_blank"):k.parentNode.removeAttribute("target")}else{newA=b.document.createElement("a");newA.setAttribute("href",f);l&&newA.setAttribute("target","_blank");k.parentNode.appendChild(newA);k.parentNode.replaceChild(newA,k);newA.appendChild(k)}this.area.imageTool.selectImage(k);WikispacesCommon.track("Editor","Add Link",
f)}else{k="";if(jQuery.trim(c)==""){alert("Please enter text for the link");return false}for(;c.charAt(c.length-1)==" ";){c=c.slice(0,c.length-1);k+=" "}if(this.area.editor.mode==this.area.editor.VISUAL){g="wiki_link";if(b=="External")g="wiki_link_ext";if(jQuery.browser.msie||jQuery.browser.safari){var n="";if(l)n=' target="_blank"';c='<a href="'+f+'" class="'+g+'"'+n+">"+c+"</a>"+k;if(jQuery.browser.safari)c+=" ";this.area.insertInEditor(c);WikispacesCommon.track("Editor","Add Link",f)}else{b=this.area.getEditorWindow();
a=b.document.createElement("a");a.setAttribute("href",f);a.setAttribute("class",g);l&&a.setAttribute("target","_blank");t1=b.document.createTextNode(c);a.appendChild(t1);this.area.insertNodeAtSelection(b,a);if(""!=k){t2=b.document.createTextNode(k);jQuery(a).after(t2)}WikispacesCommon.track("Editor","Add Link",f);b.focus()}this.area.attachDoubleClickEventHandlers(document.getElementById("WikispacesEditorContent").contentWindow.document)}else{n="";if(l)n="@";if(b=="Wiki"){f=(g==wikispaces_spaceName?
"":g+":")+m;this.area.insertInEditor("[["+n+f+(h?h:"")+(c==f?"":"|"+c)+"]] ");WikispacesCommon.track("Editor","Add Link",g+":"+f)}else{this.area.insertInEditor("[["+n+f+(f==c?"":"|"+c)+"]] ");WikispacesCommon.track("Editor","Add Link",f)}}}return true}}
function WikispacesLinkToolbar(e){this.toolbar=e;var d=this;this.linkTextFailure=this.pageNameFailure=this.anchorFailure=this.linkTextChanged=this.tabClicked=false;this.linkType="Wiki";this.tooManyPages=false;this.openLinkPopup=function(){WikispacesCommon.track("Editor","Open Link Tool");var b=false;this.toolbar.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.linkPopupWindow){b=true;this.linkPopupWindow=new Window("linkPopup",{minWidth:400,
title:"Insert Link",resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal");d.toolbar.editor.getCurrentArea().restoreCursor();d.tabClicked=false},showEffect:Element.show,hideEffect:Element.hide});this.linkPopupWindow.setHTMLContent(WikispacesToolbar.getContent("linkTool"),true,false);this.linkPopupWindow.getContent().style.overflow="hidden";this.setup()}var c="",f="",g="",h="",k="",l=false;this.linkTextFailure=this.pageNameFailure=
this.anchorFailure=this.linkTextChanged=false;this.linkType="Wiki";document.linkForm.linkTextWiki.value="";document.linkForm.linkTextExternal.value="";document.linkForm.space.value=wikispaces_spaceName;document.linkForm.pageName.value="";document.linkForm.anchor.value="";document.linkForm.newWindowWiki.checked=false;document.linkForm.newWindowExternal.checked=false;this.hideAnchor();this.tooManyPages||this.switchToSelect();jQuery("#linkDiv div.linkToolInputError").hide();var m=this.toolbar.editor.getCurrentArea();
m.saveCursor();jQuery("#linkDiv #removeExistingLink").hide();if(this.toolbar.editor.mode==this.toolbar.editor.VISUAL){var n=m.selectParent("A"),o=this.toolbar.editor.getCurrentArea().imageTool.selectedImage;o&&o.parentNode&&o.src||(c=m.getSelectedText());if(n){m=n.getAttribute("href",2)+"";m=m.replace(/^(..\/)+/,"/");var p=new RegExp("");p.compile("^http[s]?://([a-z0-9-]+).("+wikispaces_domain.replace(".",".")+")/([^#/]+)(#(.+)){0,1}$","gi");var r=new RegExp("");r.compile("^http[s]?://("+location.hostname.replace(".",
".")+")/([^#/]+)(#(.+)){0,1}$","gi");var q=new RegExp("");q.compile("^/([^#]+)(#(.+)){0,1}$","i");o=new RegExp("");o.compile("^(?:[a-zA-Z0-9.+-]+://|mailto:).*","i");p=p.exec(m);r=r.exec(m);q=q.exec(m);m=o.exec(m);if(p){f=p[1];g=p[3];h=p[5]?p[5]:""}else if(r){f="";g=r[2];h=r[4]?r[5]:""}else if(q){f="";g=q[1];h=q[3]?q[3]:""}else if(m)k=m[0];if(n.target)l=true;if(g){g=decodeURIComponent(g);g=g.replace(/\+/g," ")}if(h){h=decodeURIComponent(h);h=h.replace(/\+/g," ")}jQuery("#linkDiv #removeExistingLink").show()}}else if(m=
m.getSelectedText())if(n=m.match(/^\[\[(@)?((?:[a-zA-Z0-9.+-]+:\/\/|mailto:).*?)(?:\|(.*))?\]\]$/i)){if(n[1])l=n[1];if(n[2])k=n[2];if(n[3])c=n[3];jQuery("#linkDiv #removeExistingLink").show()}else if(n=m.match(/\[\[(@)?(?:([a-z0-9-]+):)?([^:|\/\[\]\{\}\$#@\\]+)(?:\#([A-Za-z][-A-Za-z0-9_ ]*))?(?:\|([^\[\]\xff]+))?\]\]/)){if(n[1])l=n[1];if(n[2])f=n[2];if(n[3])g=n[3];if(n[4])h=n[4];if(n[5])c=n[5];c||(c=f&&f!=wikispaces_spaceName?f+" : "+g:g);jQuery("#linkDiv #removeExistingLink").show()}else c=m;(o=
this.toolbar.editor.getCurrentArea().imageTool.selectedImage)&&o.parentNode&&o.src?jQuery("#linkDiv .trText").hide():jQuery("#linkDiv .trText").show();this.setupForms(c,k,f,g,h,l);b==true&&this.loadPages(c,k,f,g,h,l);WikispacesToolbar.setPopupSize(this.linkPopupWindow,true);this.linkPopupWindow.toFront();this.linkPopupWindow.showCenter()};this.openAnchor=function(b){this.openLinkPopup();if((b=b.id.match(/wikitext@@anchor@@(.*)/))&&b[1]){jQuery("#linkTextAnchor").val(b[1]);this.clickAnchorLink()}};
this.changeSpaceName=function(b){var c=jQuery("input#pageName").get(0).autocompleter;c.setExtraParams({space:b});c.flushCache()};this.switchToAutocomplete=function(){jQuery("#pageNameSelect").hide();jQuery("#pageName").parent().show();jQuery("#pageName").focus();jQuery("#pageName").change()};this.switchToSelect=function(){jQuery("#pageName").parent().hide();jQuery("#pageNameSelect").show();jQuery("#pageNameSelect").val(jQuery("#pageName").val())};this.loadPages=function(b,c,f,g,h,k){jQuery.ajax({async:true,
cache:true,dataType:"xml",global:false,error:function(l,m,n){log("load page list ajax error",l,m,n);reloadSession(function(){d.loadPages(b,c,f,g,h,k)},3E3,function(){d.disableSelect();d.setupForms(b,c,f,g,h,k);d.toolbar.editor.sessionReloadFailed()})},success:function(l){log("load page list ajax success",l);reloadSessionSuccess();if(l.getElementsByTagName("tooMany")[0])d.disableSelect();else{d.switchToSelect();l=l.getElementsByTagName("page");for(var m="",n=0;n<l.length;n++){var o=l[n].childNodes[0].nodeValue;
m+='<option value="'+o+'">'+WikispacesCommon.truncate(o,43)+"</option>"}jQuery("#pageNameSelect").append(m)}d.setupForms(b,c,f,g,h,k)},type:"GET",url:"/space/pagelistajax/"})};this.disableSelect=function(){this.tooManyPages=true;jQuery("#switchToPage").hide();this.switchToAutocomplete()};this.setupForms=function(b,c,f,g,h,k){document.linkForm.linkTextWiki.value="";document.linkForm.pageName.value="";document.linkForm.anchor.value="";document.linkForm.linkTextExternal.value="";document.linkForm.url.value=
"";document.linkForm.newWindowWiki.checked=false;document.linkForm.newWindowExternal.checked=false;this.clickWikiLink(true);if(b){document.linkForm.linkTextWiki.value=b;document.linkForm.linkTextExternal.value=b;this.linkTextChanged=true;jQuery(document.linkForm.linkTextWiki).change();if(b.indexOf("@")>0||b.match(/^(?:[a-zA-Z0-9.+-]+:\/\/|mailto:|www.)/)){this.clickExternalLink(true);document.linkForm.url.value=jQuery.trim(b)}else{document.linkForm.pageName.value=jQuery.trim(b);jQuery(document.linkForm.pageNameSelect).val(jQuery.trim(b));
jQuery(document.linkForm.pageNameSelect).val()==jQuery.trim(b)?this.switchToSelect():this.switchToAutocomplete()}}document.linkForm.newWindowWiki.checked=k;document.linkForm.newWindowExternal.checked=k;if(""!=g){document.linkForm.space.value=""==f?wikispaces_spaceName:f;document.linkForm.pageName.value=g;jQuery(document.linkForm.pageNameSelect).val(g);jQuery(document.linkForm.pageNameSelect).val()==g?this.switchToSelect():this.switchToAutocomplete();if(""!=h){document.linkForm.anchor.value=h;jQuery(document.linkForm.anchor).change();
this.showAnchor()}this.clickWikiLink(true)}else if(c!=""){document.linkForm.url.value=c;this.clickExternalLink(true)}document.linkForm.pageName.value&&setTimeout(function(){document.linkForm.pageName.autocompleter.findValue()},10)};this.checkPageName=function(b){var c=document.getElementById("pageNameError");b=b.value;if(this.pageNameFailure=/^\.\.?\s*$/.test(b)){c.innerHTML="Wiki page names cannot be . or ..";c.style.display="block";return this.pageNameFailure}if(this.pageNameFailure=/[\[\]:|\/{}$\"#@+]/.test(b)){c.innerHTML=
'Wiki page names cannot contain: [ ] : | / { } $ + " # @';c.style.display="block";return this.pageNameFailure}if(b.length>255){this.pageNameFailure=true;c.innerHTML="Wiki page name cannot be more than 255 characters";c.style.display="block";return this.pageNameFailure}c.innerHTML="";c.style.display="none";return this.pageNameFailure};this.checkLinkText=function(b){var c=jQuery("#linkDiv div.linkTextError"),f=new RegExp;f.compile("]]|]$");(this.linkTextFailure=f.test(b.value))?c.each(function(){this.innerHTML=
"Link text must not end with ] or contain ]]"}):c.each(function(){this.innerHTML=""});c.show()};this.checkAnchor=function(b){var c=jQuery(b).nextAll(".linkToolInputError:first");document.getElementById("anchorError");var f=new RegExp;f.compile("^[^a-zA-Z]");if(this.anchorFailure=f.test(b.value))c.html("Anchor text must start with a letter").show();else(this.anchorFailure=/[\[\]:|\/{}$\"#@+]/.test(b.value))?c.html('Anchors cannot contain: [ ] : | / { } $ + " # @').show():c.html("").hide()};this.clickWikiLink=
function(b){if(!(this.tabClicked&&b)){if(!b)this.tabClicked=true;this.linkType="Wiki";jQuery("#linkDiv .selected").removeClass("selected");jQuery("#switchToWiki").addClass("selected");jQuery("#linkDiv .styleAnchor").hide();jQuery("#linkDiv .styleExternal").hide();jQuery("#linkDiv .styleWiki").show();jQuery("#linkTextExternal").val()&&jQuery("#linkTextWiki").val(jQuery("#linkTextExternal").val());document.linkForm.newWindowWiki.checked=document.linkForm.newWindowExternal.checked;jQuery("#linkTextWiki").focus()}};
this.clickExternalLink=function(b){if(!(this.tabClicked&&b)){if(!b)this.tabClicked=true;this.linkType="External";jQuery("#linkDiv .selected").removeClass("selected");jQuery("#switchToExternal").addClass("selected");jQuery("#linkDiv .styleAnchor").hide();jQuery("#linkDiv .styleExternal").show();jQuery("#linkDiv .styleWiki").hide();jQuery("#linkTextWiki").val()&&jQuery("#linkTextExternal").val(jQuery("#linkTextWiki").val());document.linkForm.newWindowExternal.checked=document.linkForm.newWindowWiki.checked;
jQuery("#url").focus()}};this.clickAnchorLink=function(b){if(!(this.tabClicked&&b)){if(!b)this.tabClicked=true;this.linkType="Anchor";jQuery("#linkDiv .selected").removeClass("selected");jQuery("#switchToAnchor").addClass("selected");jQuery("#linkDiv .styleAnchor").show();jQuery("#linkDiv .styleExternal").hide();jQuery("#linkDiv .styleWiki").hide();jQuery("#linkTextAnchor").focus()}};this.hideAnchor=function(){jQuery("#anchorCellOff").show();jQuery("#anchorCellOn").hide()};this.showAnchor=function(){jQuery("#anchorCellOn").show();
jQuery("#anchorCellOff").hide();document.linkForm.anchor.disabled||document.linkForm.anchor.focus()};this.syncLinkText=function(b){if(!this.checkPageName(b)&&!this.linkTextChanged){jQuery(document.linkForm.linkTextWiki).val(jQuery(b).val());jQuery(document.linkForm.linkTextExternal).val(jQuery(b).val())}};this.setup=function(){jQuery("#linkDiv").find(".autocompleteSpace, .autocompleteTag, .autocompletePage").each(function(){WikispacesAutocomplete.initAutocomplete(this)});jQuery("#pageNameSelect").change(function(){jQuery(this).val()==
"@@"?d.switchToAutocomplete():jQuery(document.linkForm.pageName).val(jQuery(this).val()).change()});var b=function(){d.syncLinkText(this)};jQuery("#pageName").change(b).keyup(b);b=document.linkForm.pageName.autocompleter;var c=b.options.onItemSelect;b.options.onItemSelect=function(f,g){c(f,g);jQuery(document.linkForm.pageName).change()};jQuery("#url").change(function(){jQuery(this).val(jQuery(this).val().replace(/[\]\[{}|]/g,encodeURIComponent))});jQuery("#switchToWiki").click(function(){d.clickWikiLink();
return false});jQuery("#switchToExternal").click(function(){d.clickExternalLink();return false});jQuery("#switchToAnchor").click(function(){d.clickAnchorLink();return false});jQuery("#linkTextWiki").keydown(function(){d.linkTextChanged=true});jQuery("#linkTextExternal").keydown(function(){d.linkTextChanged=true});b=function(){d.checkLinkText(this)};jQuery("#linkTextWiki").change(b).keyup(b);jQuery("#linkTextExternal").change(b).keyup(b);jQuery("#switchToSpace").change(function(){d.changeSpaceName(this.value)});
jQuery("#switchToPage").click(function(){d.switchToSelect();return false});jQuery("#wikiAnchor").click(function(){d.showAnchor();return false});b=function(){d.checkAnchor(this)};jQuery("#anchor").change(b).keyup(b);jQuery("#linkTextAnchor").change(b).keyup(b);jQuery("#removeExistingLink").click(function(f){d.toolbar.editor.getCurrentArea().editorRemoveLink();d.linkPopupWindow.close();f.preventDefault()});jQuery("#submitLink").click(function(f){d.toolbar.editor.getCurrentArea().linkTool.addLink(d.linkType)&&
d.linkPopupWindow.close();f.preventDefault()});jQuery("#cancelLink").click(function(){d.linkPopupWindow.close();return false})}}
function WikispacesMediaTool(e){this.area=e;var d=this;this.unSelectMedia=function(){if(this.selectedMedia){jQuery(this.selectedMedia).css("opacity","1.0");this.selectedMedia=null}this.area.editor.toolbar.mediaToolbar.hideMediaPropertiesPopup()};this.selectMedia=function(b){this.unSelectMedia();this.selectedMedia=b;if(!jQuery(b).is(".WikiReference, .WikiAnchor")){jQuery(b).css("opacity","0.75");this.area.editor.toolbar.mediaToolbar.showMediaPropertiesPopup();if(jQuery(b).is(".WikiMediaRss, .WikiMediaInclude, .WikiMediaToc, .WikiMediaTocFlat"))this.area.editor.toolbar.mediaToolbar.hideAlignmentAndSize();
else{this.area.editor.toolbar.mediaToolbar.setMediaAlignment(this.getMediaAlignment(b));this.area.editor.toolbar.mediaToolbar.showAlignmentAndSize()}jQuery(b).is(".WikiMediaToc, .WikiMediaTocFlat")?jQuery("#mediaProperties #mediaEditLink").attr("disabled",true):jQuery("#mediaProperties #mediaEditLink").attr("disabled",false)}};this.insertMediaEmbedInEditor=function(b,c){WikispacesCommon.track("Editor","Add Media",c);this.area.insertInEditor(b);this.area.editor.mode==this.area.editor.VISUAL&&this.area.attachDoubleClickEventHandlers(this.area.getEditorWindow().document);
this.area.editor.toolbar.mediaToolbar.hideMediaTool()};this.insertToc=function(b){if(this.area.editor.mode==this.area.editor.VISUAL)if(b){this.area.insertInEditor('<img id="wikitext@@toc@@flat" class="WikiMedia WikiMediaTocFlat" title="Table of Contents" src="http://www.'+wikispaces_domain+'/site/embedthumbnail/toc/flat?w=100&h=16"/>');jQuery(this.area.getEditorWindow().document.body).find("#wikitext@@toc@@flat").ready(function(){d.area.lookForHeightChange()})}else{this.area.insertInEditor('<img id="wikitext@@toc@@normal" class="WikiMedia WikiMediaToc" title="Table of Contents" src="http://www.'+
wikispaces_domain+'/site/embedthumbnail/toc/normal?w=225&h=100"/>');jQuery(this.area.getEditorWindow().document.body).find("#wikitext@@toc@@normal").ready(function(){d.area.lookForHeightChange()})}else b?this.area.insertInEditor("\n[[toc|flat]]"):this.area.insertInEditor("\n[[toc]]");this.area.editor.toolbar.mediaToolbar.hideMediaTool()};this.insertReferences=function(){this.area.editor.mode==this.area.editor.VISUAL?this.area.insertInEditor("\n&lt;references/&gt;"):this.area.insertInEditor("\n<references/>");
this.area.editor.toolbar.mediaToolbar.hideMediaTool()};this.findCenteringElement=function(b){for(;b;){if(b.tagName&&(b.tagName.toUpperCase()=="CENTER"||b.tagName.toUpperCase()=="DIV"&&(b.style.textAlign=="center"||b.align=="center")))return b;if(b.parentNode)b=b.parentNode;else return null}return null};this.getMediaAlignment=function(b){if(this.findCenteringElement(b))return"center";return b.align};this.setMediaAlignment=function(b){if(this.selectedMedia){if(b=="center")if(this.findCenteringElement(this.selectedMedia))return;
else{this.selectedMedia.align="";b=this.area.getEditorWindow().document.createElement("div");b.style.textAlign="center";var c=this.selectedMedia;if(c.parentNode.nodeName=="A")c=this.selectedMedia.parentNode;c.parentNode.appendChild(b);c.parentNode.replaceChild(b,c);b.appendChild(c)}else{if(c=this.findCenteringElement(this.selectedMedia)){for(i=0;i<c.childNodes.length;i++)c.parentNode.insertBefore(c.childNodes.item(i),c);c.parentNode.removeChild(c)}this.selectedMedia.align=b}this.area.detectedChange()}};
this.adjustMediaSize=function(b,c,f){if(this.selectedMedia){var g=jQuery(this.selectedMedia),h=new Image;jQuery(h).load(function(){d.adjustMediaSizeCallback(g,h,b,c,f)});h.src=g.attr("src");if(h.height>0||h.width>0)this.adjustMediaSizeCallback(g,h,b,c,f)}return false};this.adjustMediaSizeCallback=function(b,c,f,g,h){var k=b.height()/c.height,l=b.width()/c.width,m,n;if(g){m=c.height;n=c.width}else if(h)if(c.width>800){n=800;m=Math.round(800/c.width*c.height)}else{n=c.width;m=c.height}else if(f!=0){m=
Math.floor(c.height*(k+f));n=Math.floor(c.width*(l+f))}if(m>0&&n>0&&m>=Math.floor(c.height*0.05)&&n>=Math.floor(c.width*0.05)){b.height(m);b.width(n);this.area.editor.mode==this.area.editor.VISUAL&&this.area.lookForHeightChange()}if(g){jQuery(b).css("height","").css("width","");if(b.removeAttribute){b.removeAttribute("height");b.removeAttribute("width")}else{b.height=undefined;b.width=undefined}}};this.removeMedia=function(){if(this.selectedMedia){jQuery(this.selectedMedia).remove();this.unSelectMedia()}return false}}
function WikispacesMediaToolbar(e){this.toolbar=e;this.currentSection=this.currentMenu=this.previousSection="wikispaces";var d=this;this.showMediaTool=function(){WikispacesCommon.track("Editor","Open Media Tool");this.toolbar.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.mediaPopupWindow){this.mediaPopupWindow=new Window("mediaPopup",{minWidth:620,minHeight:395,title:"Widgets",resizable:false,maximizable:false,minimizable:false,className:"wikispaces",
onClose:function(){WindowUtilities.enableScreen("overlay_modal");d.toolbar.editor.getCurrentArea().restoreCursor()},showEffect:Element.show,hideEffect:Element.hide});this.mediaPopupWindow.setHTMLContent(WikispacesToolbar.getContent("mediaTool"),true,false);this.mediaPopupWindow.getContent().style.overflow="hidden";this.setup()}this.resetMediaForms();this.setMediaMenu("wikispaces");WikispacesToolbar.setPopupSize(this.mediaPopupWindow,true);this.mediaPopupWindow.toFront();this.mediaPopupWindow.showCenter()};
this.hideMediaTool=function(){this.mediaPopupWindow.hide();WindowUtilities.enableScreen("overlay_modal");this.mediaPreviewPopupWindow&&this.mediaPreviewPopupWindow.hide()};this.showMediaPropertiesPopup=function(){if(!this.mediaPropertiesPopupWindow){this.mediaPropertiesPopupWindow=new Window("mediaPropertiesPopup",{minWidth:270,minHeight:40,title:"Widget Properties",resizable:false,className:"wikispaces",minimizable:false,maximizable:false,showEffect:Element.show,hideEffect:Element.hide});this.mediaPropertiesPopupWindow.setHTMLContent(WikispacesToolbar.getContent("mediaProperties"),
true,false);this.mediaPropertiesPopupWindow.getContent().style.overflow="hidden";this.setupProperties()}this.mediaPropertiesPopupWindow.show();this.mediaPropertiesPopupWindow.toFront();var b=jQuery(this.toolbar.editor.getCurrentArea().mediaTool.selectedMedia),c=new Image;c.src=b.attr("src");c.height>0||c.width>0?this.adjustMediaPropertiesPopup():jQuery(c).ready(function(){d.adjustMediaPropertiesPopup()})};this.hideMediaPropertiesPopup=function(){this.mediaPropertiesPopupWindow&&this.mediaPropertiesPopupWindow.hide()};
this.hideAlignmentAndSize=function(){jQuery("#mediaProperties .mediaAlignment, #mediaProperties .mediaSize").hide()};this.showAlignmentAndSize=function(){jQuery("#mediaProperties .mediaAlignment, #mediaProperties .mediaSize").show()};this.setupProperties=function(){jQuery("#mediaAlign").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.setMediaAlignment(jQuery(this).val())});jQuery("#mediaSizeDown").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(-0.1);return false});
jQuery("#mediaSizeUp").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(0.1);return false});jQuery("#mediaSizeOriginal").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(0,true);return false});jQuery("#mediaSizeFit").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(0,false,true);return false});jQuery("#mediaEditLink").click(function(){d.toolbar.editor.getCurrentArea().editorEmbedMedia();return false});jQuery("#mediaRemoveLink").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.removeMedia();
return false})};this.adjustMediaPropertiesPopup=function(){WikispacesToolbar.setPopupSize(this.mediaPropertiesPopupWindow);var b=this.toolbar.getPositionWith(this.mediaPropertiesPopupWindow.element,this.toolbar.editor.getCurrentArea().mediaTool.selectedMedia);this.mediaPropertiesPopupWindow.setLocation(b.top-10,b.left-10)};this.setMediaError=function(b){jQuery("#mediaError").show().html(b)};this.setMediaPreview=function(b){this.showMediaPreview();jQuery("#mediaPreviewArea").html(b)};this.resetMediaForms=
function(){jQuery("#mediaContent .mediaForm").each(function(){this.reset()});jQuery("#mediaContent .autocompletePage").val(wikispaces_page)};this.loadMedia=function(b){this.startMediaSpinner();document.genericMediaForm.media.value=b;document.genericMediaForm.submit()};this.showMediaPreview=function(){WindowUtilities.disableScreen("wikispaces","overlay_modal_preview",0);if(!this.mediaPreviewPopupWindow){this.mediaPreviewPopupWindow=new Window("mediaPreviewPopup",{minWidth:340,minHeight:340,title:"Media Preview",
resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal_preview");jQuery("#"+d.currentSection+"MediaMenu").show()},showEffect:Element.show,hideEffect:Element.hide});this.mediaPreviewPopupWindow.setHTMLContent(WikispacesToolbar.getContent("mediaPreview"),true,false);this.setupPreview()}jQuery("#"+this.currentSection+"MediaMenu").hide();WikispacesToolbar.setPopupSize(this.mediaPreviewPopupWindow,true);this.mediaPreviewPopupWindow.toFront();
this.mediaPreviewPopupWindow.show()};this.startMediaSpinner=function(){this.previousSection=this.currentSection;this.setMediaMenu("spinner");jQuery("#mediaContent").addClass("mediaContentSpinner");var b=document.getElementById("mediaError");b.style.display="none";b.innerHTML=""};this.stopMediaSpinner=function(){jQuery("#mediaContent").removeClass("mediaContentSpinner");this.setMediaMenu(this.previousSection)};this.setMediaAlignment=function(b){jQuery("#mediaAlign").val(b)};this.setMediaMenu=function(b){log("setMediaMenu",
b);var c=false;if(jQuery("#"+b+"MediaMenuEntry").parents("#mediaMenu").length==1){jQuery("#"+this.currentMenu+"MediaMenuEntry").removeClass("activeMediaMenuEntry");jQuery("#"+b+"MediaMenuEntry").addClass("activeMediaMenuEntry");this.currentMenu=b;c=true}if(b=="showcustom")b="custom";document.getElementById(b+"MediaMenu")||(b="wikispaces");jQuery("#"+b+"MediaMenu").find("input.autocompletePage").each(function(){var f=this.autocompleter;setTimeout(function(){f.findValue()},1)});jQuery("#"+b+"MediaMenu").find("input.autocompleteTag").each(function(){var f=
this.autocompleter;setTimeout(function(){f.findValue()},1)});jQuery("#"+this.currentSection+"MediaMenu").hide();jQuery("#"+b+"MediaMenu").show();this.currentSection=b;c&&b!="custom"||b=="wikispaces"||b=="spinner"||b=="flickr"||b=="gabbly"||b=="yackpack"||b=="bittybrowser"||b=="toc"||b=="reference"||b.substring(0,7)=="include"||jQuery("#"+b+"MediaMenu").is(".hideTextMediaInstructions")?jQuery(document.otherMediaForm).hide():jQuery(document.otherMediaForm).show();if(b!="spinner"){document.otherMediaForm.mediaType.value=
b;WikispacesToolbar.setPopupSize(this.mediaPopupWindow,true);WikispacesToolbar.snapPopupToScreen(this.mediaPopupWindow)}};this.submitYackpack=function(){var b="http://www.yackpack.com/walkietalkie/?"+encodeURIComponent(document.yackpackMediaForm.channel.value);document.otherMediaForm.embedText.value=b;document.otherMediaForm.save.click()};this.submitBittyBrowser=function(){document.otherMediaForm.embedText.value='bitty browser\nwebsite: "'+document.bittybrowserMediaForm.url.value+'"';document.otherMediaForm.save.click()};
this.embedGabbly=function(){document.otherMediaForm.embedText.value="<iframe src='http://cw.gabbly.com/gabbly/cw.jsp?e=1&t="+encodeURIComponent(location.protocol+"//"+location.host+"/"+wikispaces_page)+"' scrolling='no' style='width:300px; height:250px;' frameborder='0'></iframe>";document.otherMediaForm.save.click()};this.setupPreview=function(){jQuery("#closePreviewButton").click(function(){d.mediaPreviewPopupWindow.close()})};this.setup=function(){jQuery("#mediaDiv ul li").live("click",function(){var g=
this.id;g=g.substring(0,g.indexOf("MediaMenuEntry"));d.currentMenu!="spinner"&&d.setMediaMenu(g);return false});jQuery("#tocMediaForm #tocSubmitButton").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.insertToc();return false});jQuery("#tocMediaForm #flatSubmitButton").click(function(){d.toolbar.editor.getCurrentArea().mediaTool.insertToc(true);return false});jQuery("#referenceMediaForm").submit(function(g){d.toolbar.editor.getCurrentArea().referenceTool.insertReference();d.hideMediaTool();
g.preventDefault();g.stopPropagation();return false});jQuery("#referencesMediaForm").submit(function(g){d.toolbar.editor.getCurrentArea().mediaTool.insertReferences();g.preventDefault();g.stopPropagation();return false});jQuery("#mediaDiv .mediaForm").submit(function(){d.startMediaSpinner()});jQuery("#bittybrowserMediaForm").submit(function(){d.submitBittyBrowser()});jQuery("#gabblyMediaForm").submit(function(g){d.embedGabbly();g.preventDefault();g.stopPropagation();return false});jQuery("#yackpackMediaForm").submit(function(g){d.submitYackpack();
g.preventDefault();g.stopPropagation();return false});jQuery("#codeMediaForm").submit(function(g){if(d.toolbar.editor.mode==d.toolbar.editor.VISUAL&&document.getElementById("rteFormatBlock").options[document.getElementById("rteFormatBlock").selectedIndex].value=="<code>"){alert("You cannot insert a code block inside another code block");d.stopMediaSpinner()}else{d.toolbar.editor.getCurrentArea().insertCode();d.mediaPopupWindow.close()}g.preventDefault();g.stopPropagation();return false});jQuery("#includeCharMediaMenu td").hover(function(){jQuery(this).addClass("hl")},
function(){jQuery(this).removeClass("hl")});jQuery("#includeCharMediaMenu td").click(function(){WikispacesCommon.track("Editor","Add Character",jQuery(this).html());d.toolbar.editor.getCurrentArea().insertInEditor(jQuery(this).html());d.mediaPopupWindow.close()});jQuery("#mediaDiv form").each(function(){jQuery(this).attr("action","/page/embedmedia/"+encodeURIComponent(wikispaces_page)+"?mode="+encodeURIComponent(d.toolbar.editor.mode))});jQuery("#mediaDiv .cancelMediaLink").click(function(){d.mediaPopupWindow.close();
return false});jQuery("#mediaDiv").find(".autocompleteSpace, .autocompleteTag, .autocompletePage").each(function(){WikispacesAutocomplete.initAutocomplete(this)});jQuery("#rssDescInput").change(function(){if(this.checked){jQuery("#rssDescRow input").attr("disabled",false);jQuery("#rssDescRow th").removeClass("disabled")}else{jQuery("#rssDescRow input").attr("disabled",true);jQuery("#rssDescRow th").addClass("disabled")}});for(var b=0;b<this.toolbar.editor.plugins.length;b++){var c=this.toolbar.editor.plugins[b];
if(c.options.type=="media"){var f=jQuery("<img>").attr("title",c.options.name).attr("alt",c.options.name).attr("src",c.options.logo);f=jQuery("<a>").attr("href","#widget-"+c.options.id).append(f);f=jQuery("<li>").attr("id",c.options.id+"MediaMenuEntry").addClass("mediaMenuEntry").append(f);jQuery("#"+c.options.category+"MediaMenu ul li:last").before(f);f=WikispacesCommon.addUriParams(c.options.url,[[WikispacesEditorPlugin.COMMAND_URL_PARAM,document.location.protocol+"//"+document.location.host+"/site/editorplugin"]]);
c=jQuery("<div>").attr("id",c.options.id+"MediaMenu").addClass("hideTextMediaInstructions").addClass("mediaInstructions").hide().html('<iframe class="pluginIframe" frameborder="0" src="'+f+'" id="'+c.options.id+'-pluginIframe" name="'+c.options.id+'-pluginIframe"></iframe>');jQuery("#mediaContent").find(".mediaInstructions:last").after(c)}}}}function WikispacesEditorPlugin(e){this.options=e}WikispacesEditorPlugin.COMMAND_URL_PARAM="wikispacesCommandUrl";
WikispacesEditorPlugin.runCommand=function(e,d){var b=WikispacesEditor.getEditor();switch(e){case "cancel":b.toolbar.mediaToolbar.hideMediaTool();break;case "preview":jQuery("#otherMediaForm #embedText").val(d.content);jQuery("#otherMediaForm").get(0).preview.click();break;case "submit":jQuery("#otherMediaForm #embedText").val(d.content);jQuery("#otherMediaForm").get(0).save.click();break;default:alert("The plugin requested an invalid operation.");break}};
Function.prototype.extend=function(e,d){var b=this,c=function(){b.apply(this,arguments);e.apply(this,arguments)};c.prototype=new b;c.implement(d);return c};Function.prototype.implement=function(e){for(var d in e)this.prototype[d]=e[d]};function AbstractRange(){this.fatal=false;this.endOffset=this.endContainer=this.startOffset=this.startContainer=null;this.collapsed=true;this.commonAncestorContainer=null;this.START_TO_START=0;this.START_TO_END=1;this.END_TO_END=2;this.END_TO_START=3}
AbstractRange.prototype={setStart:function(){},setEnd:function(){},setStartBefore:function(){},setStartAfter:function(){},setEndBefore:function(){},setEndAfter:function(){},collapse:function(){},selectNode:function(){},selectNodeContents:function(){},insertNode:function(){},surroundContents:function(){},toString:function(){},compareBoundaryPoints:function(){},deleteContents:function(){},extractContents:function(){},cloneContents:function(){},cloneRange:function(){},detach:function(){}};
InternetExplorerRange=AbstractRange.extend(function(e){this.win=e;this.className="InternetExplorerRange"},{setStart:function(e,d){try{if(e.nodeType==3&&(d>e.data.length||d<0))throw'Exception... "Index or size is negative or greater than the allowed amount" 1 '+d;if(e.nodeType==1&&d>0&&(d>e.childNodes.length-1||e.childNodes.length==0)){log("START NODE IS AN ELEMENT"+e.tagName);throw'Exception... "Index or size is negative or greater than the allowed amount" 2 '+d;}this.startContainer=e;this.startOffset=
d;if(this.endContainer==null&&this.endOffset==null){this.endContainer=e;this.endOffset=d}this.collapsed=this._collapsed()}catch(b){this.fatal=true;log("setStart exception "+b.name+" - "+b.message,b)}},setEnd:function(e,d){try{if(e.nodeType==3&&(d>e.data.length||d<0))throw'Exception... "Index or size is negative or greater than the allowed amount" 3 '+d+" "+e.data;if(e.nodeType==1&&d>0&&(d>e.childNodes.length-1||e.childNodes.length==0)){log("END NODE IS AN ELEMENT"+e.tagName);throw'Exception... "Index or size is negative or greater than the allowed amount" 4 '+
d;}this.endContainer=e;this.endOffset=d;if(this.startContainer==null&&this.startOffset==null){this.startContainer=e;this.startOffset=d}this.collapsed=this._collapsed()}catch(b){this.fatal=true;log("setEnd exception "+b.name+" - "+b.message,b)}},collapse:function(){},_collapsed:function(){return this.startContainer==this.endContainer&&this.startOffset==this.endOffset},insertNode:function(e){var d=this.win.document.selection.createRange(),b=this.win.document.createElement("div");b.appendChild(e);d.collapse(false);
d.pasteHTML(b.innerHTML)},surroundContents:function(e){var d=this.win.document.selection.createRange(),b=this.win.document.createElement("div");b.appendChild(e);e.innerHTML+=d.htmlText;d.pasteHTML(b.innerHTML)},selectNode:function(e){var d=this.win.document.selection.createRange();d.moveToElementText(e);try{d.select()}catch(b){if(b.number!=-2146827682)throw b;}},selectNodeContents:function(e){var d=this.win.document.selection.createRange();d.moveToElementText(e);d.select()},deleteContents:function(){this.win.document.selection.createRange().pasteHTML("")}});
InternetExplorerRange.prototype.toString=function(){return this.win.document.selection.createRange().text};W3Range=AbstractRange.extend(function(e){this.win=e;this.className="W3Range";this.range=this.win.document.createRange()},{setStart:function(e,d){this.range.setStart(e,d)},setEnd:function(e,d){this.range.setEnd(e,d)},selectNode:function(e){this.range.selectNode(e)},selectNodeContents:function(e){this.range.selectNodeContents(e)},insertNode:function(e){this.range.insertNode(e)},deleteContents:function(){this.range.deleteContents()}});
W3Range.prototype.toString=function(){return this.range.toString()};function Range(e){return jQuery.browser.msie?new InternetExplorerRange(e):new W3Range(e)}function Selection(e){return jQuery.browser.msie?new InternetExplorerSelection(e):new W3Selection(e)}function W3Selection(e){this.win=e;this.className="W3Selection";this.ranges=[]}
W3Selection.prototype={addRange:function(e){this.ranges[this.ranges.length]=e;this.win.getSelection().addRange(e.range)},removeRange:function(e){for(var d in this.ranges)this.ranges[d]==e&&delete this.ranges[d]},removeAllRanges:function(){this.ranges.length=0;this.win.getSelection().removeAllRanges()},getRangeAt:function(e){return this.win.getSelection().getRangeAt(e)}};function InternetExplorerSelection(e){this.win=e;this.className="InternetExplorerSelection";this.ranges=[]}
InternetExplorerSelection.prototype={addRange:function(e){this.ranges[this.ranges.length]=e;this.ranges.length==1&&this._addRange()},setRangeAt:function(e,d){this.ranges[d]=e;this.ranges.length==1&&this._addRange()},removeRange:function(e){for(var d in this.ranges)this.ranges[d]==e&&delete this.ranges[d]},removeAllRanges:function(){this.ranges.length=0},getRangeAt:function(e){var d=this.win.document.selection.createRange(),b=new Range(this.win),c=d.duplicate();d=d.duplicate();c.collapse(true);c.move("Character",
1);c.move("Character",-1);c.pasteHTML("<b id='_range_decomposition_left_temporary'>L</b>");d.collapse(false);d.pasteHTML("<b id='_range_decomposition_right_temporary'>R</b>");var f=false,g=false;c=this.win.document.getElementById("_range_decomposition_left_temporary");var h=0;if(c.nextSibling&&c.nextSibling.id=="_range_decomposition_right_temporary"){f=true;log("getRangeAt: zero length range detected")}d=this.win.document.getElementsByTagName("b");for(h=0;h<d.length;h++)if(d[h].id=="_range_decomposition_left_temporary")break;
else if(d[h].id=="_range_decomposition_right_temporary"){log("getRangeAt: right before left detected");g=f=true}log("Getting left position");c=this._getObjectAndOffset(c,f,g,true);d=c[0];h=c[1];c=this.win.document.getElementById("_range_decomposition_right_temporary");if(f){f=d;g=h;c.parentNode.removeChild(c)}else{log("getting right position");c=this._getObjectAndOffset(c,f,g,false);f=c[0];g=c[1]}log("getRangeAt: setting range endpoints",d,f,h,g);b.setStart(d,h);b.setEnd(f,g);this.setRangeAt(b,e);
return b},_getObjectAndOffset:function(e,d,b,c){if(e.nextSibling&&e.nextSibling.nodeType==3||e.previousSibling&&e.previousSibling.nodeType==3){log("mode 1: something touched a text block");if(e.previousSibling&&e.nextSibling&&e.previousSibling.nodeType==3&&e.nextSibling.nodeType==3){leftOffset=e.previousSibling.data.length;nextNode=e.previousSibling;if(c){nextNode.data+=e.nextSibling.data;e.nextSibling.parentNode.removeChild(e.nextSibling)}}else if(!e.previousSibling||e.previousSibling.nodeType==
1){leftOffset=0;nextNode=e.nextSibling}else if(!e.nextSibling||e.nextSibling.nodeType==1){leftOffset=e.previousSibling.data.length;nextNode=e.previousSibling}e.parentNode.removeChild(e)}else if(!e.previousSibling||e.previousSibling&&e.previousSibling.nodeType==1){log("mode 3: no text nodes, either the previous is empty, or it is an element");leftOffset=0;if(b)nextNode=e.nextSibling?e.nextSibling:e.previousSibling&&e.previousSibling.id=="_range_decomposition_right_temporary"&&e.previousSibling.previousSibling?
e.previousSibling.previousSibling:e.parentNode;else if(d)nextNode=e.nextSibling.nextSibling?e.nextSibling.nextSibling:e.parentNode;else if(e.nextSibling)nextNode=e.nextSibling;else if(e.previousSibling){nextNode=e.previousSibling;if(nextNode.nodeType==3)leftOffset=nextNode.length}else{d=this.win.document.createTextNode("\u00a0");jQuery(e).after(d);nextNode=d}e.parentNode.removeChild(e);if(nextNode&&nextNode.nodeType==1){log("mode 3, we have an element node, going to bump to the parent",nextNode,leftOffset);
leftOffset=this._getElementIndex(nextNode);nextNode=nextNode.parentNode;log("bumped to parent node",nextNode,leftOffset,nextNode.childNodes.item(leftOffset))}}else if(e.nextSibling){log("FAILURE CASE NOT HANDLED",e.previousSibling,e.nextSibling);e.parentNode.removeChild(e)}else{log("mode 4: the next is empty");nextNode=e.previousSibling;e.parentNode.removeChild(e);if(nextNode.nodeType==3)leftOffset=nextNode.data.length;else if(nextNode.nodeType==1)leftOffset=nextNode.parentNode.childNodes.length;
else log("unknown node type")}log("found a preliminary endpoint",nextNode,leftOffset);if(nextNode.nodeType==1){e=nextNode.childNodes.item(leftOffset);var f=b=false,g=false,h=c;for(log("Looking for a text node at the "+(h?"start":"end")+" of current node",e);!b;)if(e.nodeType==3){nextNode=e;leftOffset=h?0:nextNode.length;b=true;log("found a text node to use",nextNode,leftOffset)}else if(e.nodeType==1&&e.tagName=="BR"){d=this.win.document.createTextNode("\u00a0");jQuery(e).before(d);nextNode=d;leftOffset=
0;b=true}else if(e.id!="_range_decomposition_right_temporary"&&e.id!="_range_decomposition_left_temporary"&&e.childNodes.length>0){e=e.childNodes.item(h?0:e.childNodes.length-1);log("Still looking, now checking",e)}else if(!f&&nextNode.childNodes.item(leftOffset).previousSibling){f=true;h=false;if(nextNode.childNodes.item(leftOffset).previousSibling&&nextNode.childNodes.item(leftOffset).previousSibling.id!="_range_decomposition_right_temporary"){e=nextNode.childNodes.item(leftOffset).previousSibling;
log("ran out of nodes, looking at the previous",e)}else{e=nextNode.childNodes.item(leftOffset).previousSibling.previousSibling.previousSibling;log("came across a BAD right temporary in before",e)}}else if(!g&&nextNode.childNodes.item(leftOffset).nextSibling){h=g=true;if(nextNode.childNodes.item(leftOffset).nextSibling&&nextNode.childNodes.item(leftOffset).nextSibling.id!="_range_decomposition_right_temporary"){e=nextNode.childNodes.item(leftOffset).nextSibling;log("ran out of nodes, looking at the next",
e)}else{e=nextNode.childNodes.item(leftOffset).nextSibling.nextSibling;log("came across a BAD right temporary in after",e)}}else{b=true;d=this.win.document.createTextNode("\u00a0");c?jQuery(nextNode.childNodes.item(leftOffset)).before(d):jQuery(nextNode.childNodes.item(leftOffset)).after(d);nextNode=d;leftOffset=0;log("Ran out of places to look, giving up and adding a new text node",nextNode,leftOffset)}}c=[];c[0]=nextNode;c[1]=leftOffset;return c},_addRange:function(){var e=this.ranges[this.ranges.length-
1];if(!e.fatal){var d=this._selectStart(e),b=this._selectEnd(e);d.setEndPoint("EndToStart",b);d.select();this.win.document.selection._selectedRange=e}},_selectStart:function(e){var d=this.win.document.body.createTextRange(),b=e.startContainer,c=e.startOffset,f=b;if(b.nodeType==3){log("looking for a spot to move to",b);e=c;c=null;for(var g=true;f.previousSibling;){switch(f.previousSibling.nodeType){case 1:c=f.previousSibling;g=false;break;case 3:e+=f.previousSibling.data.length;break}if(c!=null)break;
f=f.previousSibling}if(c==null){c=b.parentNode;g=true}log("Calling moveToElementText",c,e);d.moveToElementText(c);d.collapse(g);d.move("Character",e);return d}else if(b.nodeType==1)switch(e.startContainer.childNodes.item(e.startOffset).nodeType){case 1:case 3:break;default:log("error, invalid node type in selectStart");break}return d},_selectEnd:function(e){var d=this.win.document.body.createTextRange(),b=e.endContainer,c=b,f=e.endOffset;if(b.nodeType==3){e=b.data.length-f;f=null;for(var g=false;c.nextSibling;){switch(c.nextSibling.nodeType){case 1:f=
c.nextSibling;g=true;break;case 3:e+=c.nextSibling.data.length;break}if(f!=null)break;c=c.nextSibling}if(f==null){f=b.parentNode;g=false}switch(f.nodeName.toLowerCase()){case "p":case "div":case "h1":case "h2":case "h3":case "h4":case "h5":case "h6":e++}d.moveToElementText(f);d.collapse(g);d.move("Character",-e)}else if(b.nodeType==1)switch(e.endContainer.childNodes.item(e.endOffset).nodeType){case 3:f=0;d=e.endContainer.childNodes.item(e.endOffset);e.setEnd(d,f);return this._selectEnd(e);default:log("error invalid node type in selectEnd")}return d},
_getElementIndex:function(e){for(var d=e.parentNode.childNodes,b=0;b<d.length;b++)if(d[b]==e)return b;return null}};
function WikispacesReferenceTool(e){this.area=e;this.referencePopups=[];var d=this;this.openReferencePopup=function(b){log("openReferencePopup",b,this.referencePopups[b]);this.area.saveCursor();this.referencePopups[b].showCenter();this.referencePopups[b].toFront();jQuery("#"+b).ready(function(){setTimeout(function(){d.area.editor.getArea(b).initialRteCommands()},10)});WikispacesToolbar.setPopupSize(this.referencePopups[b],true);WikispacesToolbar.snapPopupToScreen(this.referencePopups[b])};this.addReferencePopup=
function(b,c){if(this.referencePopups[b])log("reusing existing reference popup",b);else{this.referencePopups[b]=new Window("referencePopup-"+b,{minWidth:300,title:"Edit Reference",resizable:false,maximizable:false,minimizable:false,closable:false,className:"wikispaces",onClose:function(){d.area.restoreCursor()},showEffect:Element.show,hideEffect:Element.hide,onMove:function(h){d.onMoveHandler(h)}});this.referencePopups[b].setHTMLContent('<div id="referenceDiv" class="editorPopup"><div id="referenceDivIframe"><iframe id="'+
b+'" name="'+b+'" frameborder="0" src="/s/blank.html" scrolling="no"></iframe></div><button type="submit" class="btn primary" id="'+b+'-close" name="save" value="1"><span><span>Save</span></span></button> <button type="submit" class="btn primary" id="'+b+'-remove" name="remove" value="1"><span><span>Remove</span></span></button> </div>',true,true);var f=this.area.editor.createArea(b);f.autosaveEnabled=false;f.mainEditor=false;f.referenceEditor=true;f.customEditorStart(b,false);var g=f.lookForHeightChange;
f.lookForHeightChange=function(){g.call(f);if(d.referencePopups[b].isVisible()){WikispacesToolbar.setPopupSize(d.referencePopups[b]);WikispacesToolbar.snapPopupToScreen(d.referencePopups[b])}};if(!c){c="Type your reference here.";f.highlightContent=true}setTimeout(function(){jQuery(f.getEditorWindow().document).find("#"+b).find("body").get(0).innerHTML=c;jQuery("#"+b+"-close").click(function(h){d.referencePopups[b].hide();h.preventDefault()});jQuery("#"+b+"-remove").click(function(h){d.referencePopups[b].close();
var k=b.substring(0,b.length-5);jQuery(d.area.editor.getMainArea().getEditorWindow().document.body).find("img#"+k).remove();h.preventDefault()})},1)}};this.insertReference=function(){if(this.area.editor.mode==this.area.editor.PLAIN)this.area.insertInEditor("<ref></ref>");else{var b=(new Date).getTime();this.addReferencePopup("reference-"+b+"-Area","");this.openReferencePopup("reference-"+b+"-Area");this.area.insertInEditor('<img src="/i/icon_16_numbersquare.png" alt="Reference - double click to edit" title="Reference - double click to edit" width="16" height="16" class="WikiReference" id="reference-'+
b+'"/> ');jQuery(this.area.getEditorWindow().document.body).find("#reference-"+b).ready(function(){d.area.lookForHeightChange()});jQuery(this.area.getEditorWindow().document).find("#reference-"+b).dblclick(function(){d.openReferencePopup(this.id+"-Area")})}};this.pullOutReferences=function(b){log("pullOutReferences",b);for(var c=jQuery("#"+b).html(),f=1,g=true,h=/&lt;ref(?:&gt;|>)((?:.|\n)*?)&lt;\/ref(?:&gt;|>)/;g;)if(g=c.match(h)){var k=g[1];c=c.replace(h,'<img src="/i/icon_16_numbersquare.png" alt="Reference - double click to edit" title="Reference - double click to edit"width="16" height="16" class="WikiReference" id="reference-'+
f+'"/> ');this.addReferencePopup("reference-"+f+"-Area",k);f++}jQuery("#"+b).html(c)};this.pushInReferences=function(b){log("pushInReferences");var c=document.createElement("div");c.innerHTML=b;jQuery(c).find(".WikiReference").each(function(){var f=jQuery(d.area.editor.getArea(this.id+"-Area").getEditorWindow().document).find("body").html();jQuery(this).replaceWith("&lt;ref&gt;"+f+"&lt;/ref&gt;")});return c.innerHTML};this.onMoveHandler=function(b){b=this.area.editor.getArea(jQuery(b.content).find("iframe").attr("id"));
if(b.tableTool.selectedTableCell){jQuery("#tableProperties").hide();b.editor.toolbar.tableToolbar.tablePropertiesShown?this.area.editor.toolbar.tableToolbar.showTablePropertiesPopup():this.area.editor.toolbar.tableToolbar.showTablePropertiesMenuHandle()}if(b.imageTool.selectedImage){b=this.area.editor.toolbar.getPositionWith(this.area.editor.toolbar.imageToolbar.imagePropertiesPopupWindow.element,b.imageTool.selectedImage);this.area.editor.toolbar.imageToolbar.imagePropertiesPopupWindow.setLocation(b.top,
b.left);this.area.editor.toolbar.imageToolbar.imagePropertiesPopupWindow.toFront()}};this.closeReferences=function(){for(var b in this.referencePopups)typeof this.referencePopups[b]=="object"&&this.referencePopups[b].close()}}
function RGBColor(e){this.ok=false;if(e.charAt(0)=="#")e=e.substr(1,6);e=e.replace(/ /g,"");e=e.toLowerCase();var d={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",
darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dodgerblue:"1e90ff",feldspar:"d19275",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",
gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",
lightslateblue:"8470ff",lightslategray:"778899",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"00ff00",limegreen:"32cd32",linen:"faf0e6",magenta:"ff00ff",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",
oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"ff0000",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",
slategray:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",violetred:"d02090",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"};for(var b in d)if(e==b)e=d[b];var c=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(h){return[parseInt(h[1]),parseInt(h[2]),parseInt(h[3])]}},{re:/^(\w{2})(\w{2})(\w{2})$/,
example:["#00ff00","336699"],process:function(h){return[parseInt(h[1],16),parseInt(h[2],16),parseInt(h[3],16)]}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(h){return[parseInt(h[1]+h[1],16),parseInt(h[2]+h[2],16),parseInt(h[3]+h[3],16)]}}];for(b=0;b<c.length;b++){var f=c[b].process,g=c[b].re.exec(e);if(g){channels=f(g);this.r=channels[0];this.g=channels[1];this.b=channels[2];this.ok=true}}this.r=this.r<0||isNaN(this.r)?0:this.r>255?255:this.r;this.g=this.g<0||isNaN(this.g)?
0:this.g>255?255:this.g;this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b;this.toRGB=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"};this.toHex=function(){var h=this.r.toString(16),k=this.g.toString(16),l=this.b.toString(16);if(h.length==1)h="0"+h;if(k.length==1)k="0"+k;if(l.length==1)l="0"+l;return"#"+h+k+l};this.getHelpXML=function(){for(var h=[],k=0;k<c.length;k++)for(var l=c[k].example,m=0;m<l.length;m++)h[h.length]=l[m];for(var n in d)h[h.length]=n;l=document.createElement("ul");
l.setAttribute("id","rgbcolor-examples");for(k=0;k<h.length;k++)try{var o=document.createElement("li"),p=new RGBColor(h[k]),r=document.createElement("div");r.style.cssText="margin: 3px; border: 1px solid black; background:"+p.toHex()+"; color:"+p.toHex();r.appendChild(document.createTextNode("test"));var q=document.createTextNode(" "+h[k]+" -> "+p.toRGB()+" -> "+p.toHex());o.appendChild(r);o.appendChild(q);l.appendChild(o)}catch(s){}return l}}
function WikispacesStyleTool(e){this.area=e;var d=this;this.applyStyle=function(){WikispacesCommon.track("Editor","Apply Style");return this.area.editor.mode==this.area.editor.PLAIN?this.applyStyleTextEditor():this.applyStyleVisualEditor()};this.cleanupEmptySpans=function(b){log("cleanupEmptySpans");for(var c=b.length-1;c>=0;c--){var f=jQuery(b[c]),g=jQuery.trim(f.text());if(f.parents("body").length>0&&(b[c].childNodes.length==0||b[c].childNodes.length==1&&b[c].childNodes[0].nodeType==3&&(g==""||
g.charCodeAt(0)==8203)))f.replaceWith(f.text())}};this.cleanupNoAttributeSpans=function(b){log("cleanupNoAttributeSpans");jQuery(b).find("span").each(function(){if(!(d.selectedSpans&&this==d.selectedSpans[0])){var c=jQuery(this);!c.attr("style")&&!c.attr("class")&&c.replaceWith(c.contents())}});if(jQuery(b).find(":last").is("span")||jQuery(b).find(":last").is("br")&&jQuery(b).find(":last").prev().is("span"))jQuery(b).append("&nbsp;")};this.applyStyleTextEditor=function(){var b=jQuery.trim(document.styleForm.styleText.value);
if(b.length>0){b=b.replace(/\n/gmi,"; ");var c=this.area.getSelectedText(),f=c.match(/^<span [\s\S]*?>([\s\S]*)<\/span>$/i);if(f&&f.length==2)c=f[1];document.getElementById("textEditor").focus();this.area.insertInEditor('<span style="'+b+'">'+c+"</span>")}else this.removeStyle();return false};this.applyStyleVisualEditor=function(){try{var b=this.area.getEditorWindow();if(!this.selectedSpans)return false;var c=jQuery.trim(document.styleForm.styleText.value);if(c.length>0){var f=c.replace(/;/gi,"\n").split("\n");
new Selection(b);log("exising span",this.selectedSpans);jQuery(this.selectedSpans).attr("style","");for(c=0;c<f.length;c++){var g=f[c].split(":"),h=g[0].camelize(),k=jQuery.trim(g[1]);log("setting attribute",h,k,this.selectedSpans);jQuery(this.selectedSpans).css(h,k)}}else this.removeStyle();this.flattenNodes(this.selectedSpans);if(jQuery.browser.msie){var l=b.document.body.createTextRange();l.moveToElementText(this.selectedSpans[0]);l.select()}else{var m=new Selection(b),n=new Range(b);n.selectNodeContents(this.selectedSpans[0]);
m.addRange(n)}b.focus();return false}catch(o){log(o.message,o);throw o;}};this.removeStyle=function(){WikispacesCommon.track("Editor","Remove Style");return this.area.editor.mode==this.area.editor.VISUAL?this.removeStyleVisualEditor():this.removeStyleTextEditor()};this.removeStyleTextEditor=function(){this.area.saveCursor();var b=this.area.getSelectedText().match(/^<span [\s\S]*?>([\s\S]*)<\/span>$/i);b&&b.length==2&&this.area.insertInEditor(b[1])};this.removeStyleVisualEditor=function(){this.selectedSpans&&
jQuery(this.selectedSpans).each(function(){jQuery(this).replaceWith(jQuery(this).html())})};this.getSelectedSpans=function(){var b=this.area.getEditorWindow();b.focus();var c=[],f=this.area.setRange(this.area.areaId);if(f.startContainer.nodeType==3&&f.endContainer.nodeType==3&&f.startOffset==0&&f.endOffset==f.endContainer.length){if(f.startContainer==f.endContainer&&f.startContainer.parentNode.tagName=="SPAN"){var g=this.area.selectParent("SPAN");log("SPAN (1) ",g,f);c[0]=g;return c}}else if(f.startContainer.nodeType==
1&&f.startContainer==f.endContainer&&f.startContainer.tagName=="SPAN"){g=f.startContainer;log("SPAN (2) ",g,f);c[0]=g;return c}else if(f.startContainer.nodeType==1&&f.startOffset==0&&f.endOffset==1&&f.startContainer.childNodes.length==1&&f.startContainer.childNodes[0].tagName=="SPAN"){g=f.startContainer.childNodes[0];log("SPAN (3) ",g,f);c[0]=g;return c}else if(f.startContainer.nodeType==1&&f.startContainer==f.endContainer&&f.startContainer.childNodes&&f.endContainer.childNodes&&f.startContainer.childNodes[f.startOffset]&&
f.endContainer.childNodes[f.endOffset]&&f.startContainer.childNodes[f.startOffset]==f.endContainer.childNodes[f.endOffset]&&f.startContainer.childNodes[f.startOffset].nodeType==1&&f.startContainer.childNodes[f.startOffset].tagName=="SPAN"){g=f.startContainer.childNodes[f.startOffset];log("SPAN (4) ",g,f);c[0]=g;return c}else if(f.startContainer.nodeType==1&&f.startContainer==f.endContainer&&f.startOffset+1==f.endOffset&&f.startContainer.childNodes&&f.endContainer.childNodes&&f.startContainer.childNodes[f.startOffset].nodeType==
1&&f.startContainer.childNodes[f.startOffset].tagName=="SPAN"&&f.endContainer.childNodes[f.endOffset].nodeType==3){g=f.startContainer.childNodes[f.startOffset];log("SPAN (5) ",g,f);c[0]=g;return c}if(f.startContainer==f.endContainer&&f.startOffset==f.endOffset)if(g=this.area.selectParent("SPAN")){f.setStart(g,0);f.setEnd(g,g.childNodes.length-1);log("SPAN (6) ",g,f);c[0]=g;return c}g=Array();for(var h=false,k=f.startContainer;!h;){if(k.nodeType==1&&k.tagName=="SPAN")g[g.length]=k;if(k.childNodes.length>
0&&k.childNodes[0].nodeType==1)k=k.childNodes[0];else h=true}h=Array();k=false;for(var l=f.endContainer;!k;){if(l.nodeType==1&&l.tagName=="SPAN")h[h.length]=l;if(l.childNodes.length>0&&l.childNodes[l.childNodes.length-1].nodeType==1)l=l.childNodes[l.childNodes.length-1];else k=true}for(k=0;k<g.length;k++)for(l=0;l<h.length;l++)if(g[k]==h[l]){log("SPAN (7) ",g[k],f);c[0]=g[k];return c}log("could not find span, creating a new one");if(f.collapsed){f=this.insertSpan(b,f,"insert","span");c[0]=f;return c}else{log("converting font to span");
this.area.rteCommand(this.area.areaId,"useCSS",true);this.area.rteCommand(this.area.areaId,"forecolor","#100010");jQuery(b.document.body).find("pre font[color='#100010']").each(function(){jQuery(this).replaceWith(jQuery(this).html())});var m=[];jQuery(b.document.body).find("font[color='#100010'], span[style]").each(function(){if(jQuery(this).attr("color")=="#100010"||jQuery(this).css("color")=="#100010"||jQuery(this).css("color")=="rgb(16, 0, 16)"){var n=b.document.createElement("span");jQuery(n).html(jQuery(this).html());
jQuery(this).replaceWith(n);m[m.length]=n}});log("new spans",m);return this.collapseNodes(m)}};this.insertSpan=function(b,c,f,g){if(jQuery.browser.msie){log("adding new "+g);c=document.selection.createRange();c.pasteHTML("<"+g+' id="798798769876">&#8203;</'+g+">");c=b.document.getElementById("798798769876");c.id="";b=b.document.selection.createRange();b.moveToElementText(c);b.select();g=="div"&&jQuery(c).css("display","inline");return c}else{log("adding new "+g);var h=b.document.createElement(g);
if(jQuery.browser.safari){var k=b.document.createTextNode(" ");h.appendChild(k)}f=="surround"?c.surroundContents(h):c.insertNode(h);c.selectNodeContents(h);b=b.getSelection();b.removeAllRanges();b.addRange(c);g=="div"&&jQuery(h).css("display","inline");return h}};this.getStyleArray=function(b){var c={};if(b.style.length)for(var f=0;f<b.style.length;f++){var g=b.style[f],h=b.style[g.camelize()];if(typeof h!="function"){var k=WikispacesStyleTool.normalizeCssSelector(g);if(k!="cssText")if(h&&h.length>
0)c[k]=h}}else for(g in b.style){h=b.style[g];if(typeof h!="function"){k=WikispacesStyleTool.normalizeCssSelector(g);if(k!="cssText")if(h&&h.length>0)c[k]=h}}return c};WikispacesStyleTool.normalizeCssSelector=function(b){if(b==b.toUpperCase())b=b.toLowerCase();return b.camelize()};this.mergeStyles=function(b,c){var f={};for(var g in b)if(typeof b[g]!="function")f[g]=b[g];for(g in c)if(typeof c[g]!="function")f[g]=this.mergeCss(b[g],g,c[g]);return f};this.collapseNodes=function(b){log("collapseNodes");
for(var c=Array(),f=b.length-1;f>=0;f--)if(jQuery(b[f]).parents("body").length>0){var g=this.collapseNodeDown(b[f]);c[c.length]=g}return c};this.flattenNodes=function(b){log("flattenNodes",b);for(var c=b.length-1;c>=0;c--)for(var f=[jQuery(b[c])],g;g=f.pop();){var h=g.parent();if(h.is("span")){log("flattening",g.get(0),g.html());var k=h.contents(),l=k.index(g);k=h.clone().empty().append(k.slice(l+1));jQuery(h).after(k).after(g);l=this.mergeStyles(this.getStyleArray(h.get(0)),this.getStyleArray(g.get(0)));
for(var m in l)if(typeof l[m]!="function")try{g.css(m,l[m])}catch(n){}jQuery.trim(h.html())==""&&h.remove();jQuery.trim(k.html())==""?k.remove():f.push(k);f.push(g)}}};this.collapseNodeDown=function(b){for(;jQuery(b).parent().is("span")&&jQuery(b).parent().attr("class")==jQuery(b).attr("class")&&jQuery(b).parent().children().length==1;){for(var c=true,f=0;f<b.parentNode.childNodes.length;f++)if(b.parentNode.childNodes[f].nodeType==3&&!jQuery.trim(b.parentNode.childNodes[f].nodeValue)==""){c=false;
break}if(!c)break;b=b.parentNode}for(var g="",h="",k=this.getStyleArray(b),l=b;jQuery(l).children().length==1&&jQuery(l).children().eq(0).is(l.tagName)&&jQuery(l).attr("class")==jQuery(l).children().eq(0).attr("class");){var m=true;c=true;for(f=0;f<l.childNodes.length;f++)if(l.childNodes[f].nodeType==1)m=false;else if(l.childNodes[f].nodeType==3&&jQuery.trim(l.childNodes[f].nodeValue)=="")if(m)g+=l.childNodes[f].nodeValue;else h+=l.childNodes[f].nodeValue;else{c=false;break}if(!c)break;l=jQuery(l).children().get(0);
k=this.mergeStyles(k,this.getStyleArray(l))}if(l&&l!=b){jQuery(l).prepend(g);jQuery(l).append(h);c=jQuery(l).html();jQuery(b).empty();jQuery(b).html(c);for(var n in k)if(typeof k[n]!="function")try{jQuery(b).css(n,k[n])}catch(o){}}return b};this.mergeNodes=function(b){log("mergeNodes",b);if(!(!b||b.length==0)){for(var c=this.area.getEditorWindow().document,f=b[0].tagName,g=true;g;){g=false;jQuery(c.body).find(f+" + br").each(function(){if(this.previousSibling.nodeType==1){g=true;jQuery(this).prev().append("<br/>");
jQuery(this).remove()}})}jQuery(c.body).find(f).each(function(){var k=this.nextSibling;if(k&&k.nodeType==3&&jQuery.trim(k.nodeValue)==""&&k.nextSibling&&k.nextSibling.nodeType==1&&k.nextSibling.tagName==f.toUpperCase()&&jQuery(k.nextSibling).attr("style")==jQuery(this).attr("style")&&jQuery(k.nextSibling).attr("class")==jQuery(this).attr("class")){jQuery(this).append(k.nodeValue);k.parentNode.removeChild(k)}});for(var h=b.length-1;h>=0;h--)jQuery(b[h]).parents("body").length>0&&this.mergeNode(b[h]);
for(g=true;g;){g=false;jQuery(c.body).find(f+" br:last-child").each(function(){if(!this.nextSibling){g=true;jQuery(this).parent().after("<br/>");jQuery(this).remove()}})}log("end mergeNodes",b)}};this.mergeNode=function(b){var c=jQuery(b);if(b.previousSibling&&b.previousSibling.tagName==b.tagName&&c.prev().attr("class")==c.attr("class")&&c.prev().attr("style")==c.attr("style")){b=c.prev();b.html(b.html()+c.html());c.remove()}};this.mergeNodeKeypressHandlerDelayed=function(){typeof this.mergeNodeHandle==
"number"&&clearTimeout(this.mergeNodeHandle);this.mergeNodeHandle=setTimeout(function(){var b=d.area.getEditorWindow().document;d.area.mergeNodes(b.getElementsByTagName("span"))},50)};this.mergeCss=function(b,c,f){if(!b||c!="fontSize")return f;c=b.substr(0,b.length-2);var g=b.substr(b.length-2,2);if(g[1]=="%"){g="%";c=b.substr(0,b.length-1)}b=f.substr(f.length-2,2);var h=f.substr(0,f.length-2);if(b[1]=="%"){b="%";h=f.substr(0,f.length-1)}if(b=="em"||b=="ex"){b="%";h*=100}if(g=="em"||g=="ex"){g="%";
c*=100}return b=="%"?Math.round(c*h*100)/1E4+g:f};this.removeSafariSpans=function(b){log("removeSafariSpans");this.area.getEditorWindow();jQuery(b).find("span").removeClass("Apple-tab-span");jQuery(b).find("span").removeClass("Apple-style-span");this.cleanupNoAttributeSpans(b)};this.removeMsoStyles=function(b){jQuery(b).each(function(){var c=d.getStyleArray(this),f=false;for(var g in c)if(typeof c[g]=="function")delete c[g];else if(g.indexOf("mso")==0){delete c[g];f=true}if(f)try{var h=jQuery("<span>").attr("class",
jQuery(this).attr("class")).html(jQuery(this).html()).attr("id",jQuery(this).attr("id")).css(c);jQuery(this).replaceWith(h)}catch(k){}})};this.getPreviousColors=function(){var b=[];if(this.area.editor.mode==this.area.editor.VISUAL)jQuery(this.area.getEditorWindow().document.body).find("span").each(function(){var h=jQuery(this);if(h.css("color")&&h.css("color")!="transparent")b[b.length]=(new RGBColor(h.css("color"))).toHex().toUpperCase();if(h.css("backgroundColor")&&h.css("backgroundColor")!="transparent")b[b.length]=
(new RGBColor(h.css("backgroundColor"))).toHex().toUpperCase()});else{var c=this.area.getContent().match(/style=\"[^\"]*?color:\s*.*?[;\"]/gi);if(c)for(var f=0;f<c.length;f++){var g=c[f].match(/color:\s*(.*?)[;\"]/i);b[b.length]=(new RGBColor(g[1])).toHex().toUpperCase()}}b.sort();c=[];g=null;for(f=0;f<b.length;f++){if(b[f]!=g)c[c.length]=b[f];g=b[f]}return c};this.cleanup=function(b,c,f){log("cleanup",c);var g=[];if(c!="none"){if(c)g=c.split(",");if(g.length>0){f&&this.area.editor.toolbar.styleToolbar.openCleanupPopup();
(new Date).getTime();g.indexOf("safari")!=-1&&this.removeSafariSpans(b);g.indexOf("mso")!=-1&&this.removeMsoStyles(b.getElementsByTagName("span"));g.indexOf("collapse")!=-1&&this.collapseNodes(b.getElementsByTagName("span"));g.indexOf("merge")!=-1&&this.mergeNodes(b.getElementsByTagName("span"));g.indexOf("flatten")!=-1&&this.flattenNodes(b.getElementsByTagName("span"));g.indexOf("empty")!=-1&&this.cleanupEmptySpans(b.getElementsByTagName("span"));setTimeout(function(){d.area.editor.toolbar.styleToolbar.closeCleanupPopup()},
11)}}}}
function WikispacesStyleToolbar(e){this.toolbar=e;var d=this;this.openStylePopup=function(){WikispacesCommon.track("Editor","Open Style Tool");this.toolbar.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.stylePopup){this.stylePopup=new Window("stylePopup",{minWidth:600,minHeight:400,title:"Color and Style",resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){var h=d.toolbar.editor.getCurrentArea();d.toolbar.editor.mode==
d.toolbar.editor.VISUAL&&h.styleTool.cleanupNoAttributeSpans(h.getEditorWindow().document.body);if(h.styleTool.selectedSpans)h.styleTool.selectedSpans=null;else d.toolbar.editor.getCurrentArea().restoreCursor();WindowUtilities.enableScreen("overlay_modal")},showEffect:Element.show,hideEffect:Element.hide});this.stylePopup.setHTMLContent(WikispacesToolbar.getContent("stylePopupContents"),true,true);this.stylePopup.getContent().style.overflow="hidden";WikispacesToolbar.setPopupSize(this.stylePopup,
true);this.setup()}this.stylePopup.showCenter();this.stylePopup.toFront();var b=this.getStyleColors();jQuery("#styleColors").empty();for(var c={"float":"left",margin:"3px",width:"20px",height:"15px",cursor:"crosshair",border:"1px black solid"},f=0;f<b.length;f++){var g=document.createElement("div");c["background-color"]=b[f];jQuery(g).css(c);jQuery(g).attr("title",b[f]);jQuery(g).click(function(h){d.chooseStyleColor(jQuery(this).css("backgroundColor"));h.preventDefault()});jQuery("#styleColors").append(g)}this.updatePreviewStyle();
jQuery("#styleColors").hide();jQuery("#colorpickerColor").hide();jQuery("#colorpickerBackgroundColor").hide()};this.updatePreviewStyle=function(){jQuery(".styleBasic").css("display")!="none"&&this.mergeBasicStyleToAdvanced();var b=jQuery.trim(document.styleForm.styleText.value).replace(/\n/gmi,"; ");jQuery("#stylePreviewApplied").attr("style",b)};this.chooseStyleColor=function(b){if(b=(new RGBColor(b)).toHex().toUpperCase()){var c=this.currentColorInput.name;jQuery.farbtastic("#colorpicker"+c.substring(5)).setColor(b);
document.styleForm[c].focus()}};this.openCleanupPopup=function(){d.toolbar.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.cleanupPopup){this.cleanupPopup=new Window("cleanupPopup",{minWidth:500,minHeight:150,title:"Optimize Page",closable:false,resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal");d.toolbar.editor.getCurrentArea().restoreCursor()},showEffect:Element.show,
hideEffect:Element.hide});this.cleanupPopup.setHTMLContent(WikispacesToolbar.getContent("cleanupPopupContents"),true,true);this.cleanupPopup.getContent().style.overflow="hidden";WikispacesToolbar.setPopupSize(this.cleanupPopup,true)}this.cleanupPopup.showCenter();this.cleanupPopup.toFront()};this.closeCleanupPopup=function(){if(this.cleanupPopup){this.cleanupPopup.close();this.toolbar.editor.getCurrentArea().getEditorWindow().focus()}};this.mergeBasicStyleToAdvanced=function(){var b=jQuery(document.styleForm.styleText).val(),
c=jQuery(document.styleForm.styleSize).val(),f=jQuery(document.styleForm.styleFont).val(),g=jQuery(document.styleForm.styleColor).val(),h=jQuery(document.styleForm.styleBackgroundColor).val(),k=jQuery(document.styleForm.styleAlignment).val(),l=jQuery(document.styleForm.styleVertical).val(),m=jQuery(document.styleForm.styleStrike).attr("checked");b=c&&c!="100%"?b.match(/^\s*font-size:\s*.*$/gmi)?b.replace(/^\s*font-size:\s*.*$/gmi,"font-size: "+c):b+"\nfont-size: "+c:b.replace(/^\s*font-size:\s*.*$/gmi,
"");b=f?b.match(/^\s*font-family:\s*.*$/gmi)?b.replace(/^\s*font-family:\s*.*$/gmi,"font-family: "+f):b+"\nfont-family: "+f:b.replace(/^\s*font-family:\s*.*$/gmi,"");b=g?b.match(/^\s*color:\s*.*$/gmi)?b.replace(/^\s*color:\s*.*$/gmi,"color: "+g):b+"\ncolor: "+g:b.replace(/^\s*color:\s*.*$/gmi,"");b=h?b.match(/^\s*background-color:\s*.*$/gmi)?b.replace(/^\s*background-color:\s*.*$/gmi,"background-color: "+h):b+"\nbackground-color: "+h:b.replace(/^\s*background-color:\s*.*$/gmi,"");if(k){b=b.match(/^\s*text-align:\s*.*$/gmi)?
b.replace(/^\s*text-align:\s*.*$/gmi,"text-align: "+k):b+"\ntext-align: "+k;b.match(/^\s*display:\s*block\s*$/gmi)||(b+="\ndisplay: block")}else{b=b.replace(/^\s*text-align:\s*.*$/gmi,"");b=b.replace(/^\s*display:\s*block\s*$/gmi,"")}b=l?b.match(/^\s*vertical-align:\s*.*$/gmi)?b.replace(/^\s*vertical-align:\s*.*$/gmi,"vertical-align: "+l):b+"\nvertical-align: "+l:b.replace(/^\s*vertical-align:\s*.*$/gmi,"");if(m)if(b.match(/^\s*text-decoration:\s*.*$/gmi))b=b.replace(/^\s*text-decoration:\s*.*$/gmi,
"text-decoration: line-through");else b+="\ntext-decoration: line-through";else b=b.replace(/^\s*text-decoration:\s*.*$/gmi,"");jQuery(document.styleForm.styleText).val(jQuery.trim(b))};this.resetSpanText=function(){jQuery(document.styleForm.styleSize).val("100%");jQuery(document.styleForm.styleFont).val("");jQuery.farbtastic("#colorpickerColor").setColor("#000000");jQuery(document.styleForm.styleColor).val("");jQuery.farbtastic("#colorpickerBackgroundColor").setColor("#FFFFFF");jQuery(document.styleForm.styleBackgroundColor).val("");
jQuery(document.styleForm.styleAlignment).val("");jQuery(document.styleForm.styleVertical).val("");jQuery(document.styleForm.styleText).val("");jQuery(document.styleForm.styleStrike).attr("checked",false);document.styleForm.removeStyleButton.disabled=true;this.updatePreviewStyle()};this.setSpanTextTextEditor=function(b){this.resetSpanText();if((b=b.match(/^<span\s+.*?style="([\s\S]*?)"[\s\S]*<\/span>$/i))&&b.length==2){b=b[1].split(";");for(var c=0;c<b.length;c++){var f=b[c].split(":"),g=jQuery.trim(f[0]);
f=jQuery.trim(f[1]);if(g&&f){this.setSpanTextValue(g,f);document.styleForm.removeStyleButton.disabled=false}}}this.mergeBasicStyleToAdvanced()};this.setSpanTextVisualEditor=function(b){this.resetSpanText();if(b&&jQuery(b).attr("style")){document.styleForm.removeStyleButton.disabled=false;if(b.style.length)for(var c=0;c<b.style.length;c++)this.setSpanTextValue(b.style[c],b.style[b.style[c].camelize()]);else for(c in b.style){var f=b.style[c];typeof f!="function"&&f&&f.length>0&&this.setSpanTextValue(c,
f)}}this.mergeBasicStyleToAdvanced()};this.mergeAdvancedStyleToBasic=function(){var b=jQuery(document.styleForm.styleText).val(),c;if(c=b.match(/^\s*font-size:\s*(.+?)\s*$/mi))this.setSpanTextValue("font-size",c[1]);if(c=b.match(/^\s*font-family:\s*(.+?)\s*$/mi))this.setSpanTextValue("font-family",c[1]);if(c=b.match(/^\s*color:\s*(.+?)\s*$/mi))this.setSpanTextValue("color",c[1]);if(c=b.match(/^\s*background-color:\s*(.+?)\s*$/mi))this.setSpanTextValue("background-color",c[1]);if(c=b.match(/^\s*text-align:\s*(.+?)\s*$/mi))this.setSpanTextValue("text-align",
c[1]);if(c=b.match(/^\s*vertical-align:\s*(.+?)\s*$/mi))this.setSpanTextValue("vertical-align",c[1]);if(c=b.match(/^\s*text-deocration:\s*(.+?)\s*$/mi))this.setSpanTextValue("text-decoration",c[1])};this.setSpanTextValue=function(b,c){var f=WikispacesStyleTool.normalizeCssSelector(b);log("setting "+b+" as "+f+" with "+c);switch(f){case "fontSize":jQuery(document.styleForm.styleSize).val(c);break;case "fontFamily":c=c.replace(/,.*/gi,"").replace(/\'/gi,"");jQuery(document.styleForm.styleFont).val(c);
break;case "color":c=(new RGBColor(c)).toHex().toUpperCase();jQuery(document.styleForm.styleColor).val(c);jQuery.farbtastic("#colorpickerColor").setColor(c);break;case "backgroundColor":c=(new RGBColor(c)).toHex().toUpperCase();jQuery(document.styleForm.styleBackgroundColor).val(c);jQuery.farbtastic("#colorpickerBackgroundColor").setColor(c);break;case "textAlign":jQuery(document.styleForm.styleAlignment).val(c);break;case "verticalAlign":jQuery(document.styleForm.styleVertical).val(c);if(jQuery(document.styleForm.styleVertical).val()!=
c){b=jQuery("<option>").val(c).html(c);jQuery(document.styleForm.styleVertical).append(b);jQuery(document.styleForm.styleVertical).val(c)}break;case "textDecoration":if(c=="line-through"||c=="lineThrough")jQuery(document.styleForm.styleStrike).attr("checked",true);break;case "accelerator":case "csstext":case "cssText":break;default:jQuery(document.styleForm.styleText).val("\n"+jQuery(document.styleForm.styleText).val()+b+": "+c)}};this.farbtasticCallback=function(b,c){jQuery(c).css({backgroundColor:b,
color:this.hsl[2]>0.5?"#000":"#fff"});jQuery(c).each(function(){this.value=b})};this.getBasicColors=function(){return["#000000","#404040","#808080","#C0C0C0","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#00FFFF","#FF00FF","#800000","#008000","#000080","#808000","#008080","#800080"]};this.getStyleColors=function(){for(var b=this.getBasicColors(),c=this.toolbar.editor.getCurrentArea().styleTool.getPreviousColors(),f=0;f<c.length;f++){for(var g=false,h=0;h<b.length;h++)if(c[f]==b[h]){g=true;break}g||
(b[b.length]=c[f])}return b};this.adjustFont=function(b){var c=jQuery(document.styleForm.styleSize).val();if(c.match(/%\s*$/gi)){c=parseInt(c);c+=b;jQuery(document.styleForm.styleSize).val(c+"%")}this.updatePreviewStyle()};this.hideColorPickers=function(){jQuery("#colorpickerColor").hide();jQuery("#colorpickerBackgroundColor").hide();jQuery("#styleColors").hide()};this.setup=function(){jQuery("#switchToAdvanced").click(function(){d.hideColorPickers();d.mergeBasicStyleToAdvanced();jQuery("#stylePopupContents .styleAdvanced").show();
jQuery("#stylePopupContents .styleBasic").hide();return false});jQuery("#switchToBasic").click(function(){d.mergeAdvancedStyleToBasic();jQuery("#stylePopupContents .styleAdvanced").hide();jQuery("#stylePopupContents .styleBasic").show();return false});jQuery("#styleAdvancedTextarea").keyup(function(){d.updatePreviewStyle()});jQuery("#styleAdvancedTextarea").change(function(){d.updatePreviewStyle()});jQuery("#styleFont").focus(function(){d.hideColorPickers()});jQuery("#styleFont").change(function(){d.updatePreviewStyle()});
jQuery("#sizeDown").click(function(){d.hideColorPickers();d.adjustFont(-10);return false});jQuery("#styleSize").focus(function(){d.hideColorPickers()});jQuery("#styleSize").keyup(function(){d.updatePreviewStyle()});jQuery("#sizeUp").click(function(){d.hideColorPickers();d.adjustFont(10);return false});jQuery("#styleColor").focus(function(){d.hideColorPickers();jQuery("#colorpickerColor").show();jQuery("#styleColors").show();d.currentColorInput=this});jQuery("#styleColor").focus(function(){d.updatePreviewStyle()});
jQuery("#styleBackgroundColor").focus(function(){d.hideColorPickers();jQuery("#colorpickerBackgroundColor").show();jQuery("#styleColors").show();d.currentColorInput=this});jQuery("#styleBackgroundColor").focus(function(){d.updatePreviewStyle()});jQuery("#styleAlignment").focus(function(){d.hideColorPickers()});jQuery("#styleAlignment").change(function(){d.updatePreviewStyle()});jQuery("#styleVertical").focus(function(){d.hideColorPickers()});jQuery("#styleVertical").change(function(){d.updatePreviewStyle()});
jQuery("#styleStrike").focus(function(){d.hideColorPickers()});jQuery("#styleStrike").click(function(){d.updatePreviewStyle()}).change(function(){d.updatePreviewStyle()});jQuery("#applyStyleButton").click(function(){jQuery("#stylePopupContents .styleBasic").is(":visible")&&d.mergeBasicStyleToAdvanced();d.toolbar.editor.getCurrentArea().styleTool.applyStyle();d.stylePopup.close();return false});jQuery("#removeStyleButton").click(function(){d.toolbar.editor.getCurrentArea().styleTool.removeStyle();
d.stylePopup.close()});jQuery("#styleCancel").click(function(){d.stylePopup.close();return false});jQuery("#colorpickerColor").farbtastic(function(b){d.farbtasticCallback.call(this,b,document.styleForm.styleColor);d.updatePreviewStyle()});jQuery("#colorpickerBackgroundColor").farbtastic(function(b){d.farbtasticCallback.call(this,b,document.styleForm.styleBackgroundColor);d.updatePreviewStyle()})}}
function WikispacesTableTool(e){this.area=e;this.selectTableCell=function(d){log("selectTableCell",d);this.selectedTableCell=d;this.area.editor.toolbar.tableToolbar.hideTablePropertiesPopup();this.area.editor.toolbar.tableToolbar.showTablePropertiesMenuHandle();this.area.editor.toolbar.tableToolbar.selectTableCell(d)};this.unselectTableCell=function(){if(this.selectedTableCell){this.removeHighlight();this.selectedTableCell=null}this.area.editor.toolbar.tableToolbar.hideTablePropertiesPopup()};this.highlightCell=
function(d){this.selectedTableCell&&jQuery(this.selectedTableCell).addClass(d)};this.highlightCellForMerge=function(d){if(this.selectedTableCell)d?jQuery(this.selectedTableCell).prev("td,th").addClass("highlightTableCellForMerge"):jQuery(this.selectedTableCell).next("td,th").addClass("highlightTableCellForMerge")};this.highlightCellForRowMerge=function(d){if(this.selectedTableCell){var b=this.getColumnNumber(this.selectedTableCell);d?this.getColumnInPosition(jQuery(this.selectedTableCell).parent().prev("tr").children("td,th"),
b).addClass("highlightTableCellForMerge"):this.getColumnInPosition(jQuery(this.selectedTableCell).parent().next("tr").children("td,th"),b).addClass("highlightTableCellForMerge")}};this.convertCells=function(d,b){var c=this.area.getEditorWindow().document;jQuery(d).each(function(){var f=parseInt(jQuery(this).attr("colspan")),g=c.createElement(b);jQuery(g).attr("colspan",f);jQuery(g).html(jQuery(this).html());jQuery(this).replaceWith(g);this==this.selectedTableCell&&this.selectTableCell(g)})};this.convertCellType=
function(){this.convertCells(this.selectedTableCell,jQuery(this.selectedTableCell).is("td")?"th":"td")};this.convertColType=function(){var d=this.getColCells(this.getColumnNumber(this.selectedTableCell),false),b=jQuery(this.selectedTableCell).is("td")?"th":"td";this.convertCells(d,b)};this.convertRowType=function(){var d=jQuery(this.selectedTableCell).parent("tr").find("td,th"),b=jQuery(this.selectedTableCell).is("td")?"th":"td";this.convertCells(d,b)};this.mergeCell=function(d){if(this.selectedTableCell){var b=
this.area.getEditorWindow().document,c=parseInt(jQuery(this.selectedTableCell).attr("colspan")>1?jQuery(this.selectedTableCell).attr("colspan"):1);d?jQuery(this.selectedTableCell).prev("td,th").remove():jQuery(this.selectedTableCell).next("td,th").remove();d="td";if(jQuery(this.selectedTableCell).is("th"))d="th";d=b.createElement(d);jQuery(d).html(jQuery(this.selectedTableCell).html());jQuery(d).attr("colspan",c+1);jQuery(this.selectedTableCell).replaceWith(d);c=jQuery(d).parent("tr").eq(0);b=b.createElement("tr");
jQuery(b).html(jQuery(c).html());jQuery(c).after(b);jQuery(c).remove();this.unselectTableCell()}};this.splitCell=function(){if(this.selectedTableCell&&jQuery(this.selectedTableCell).attr("colspan")>1){var d="td";if(jQuery(this.selectedTableCell).is("th"))d="th";d="<"+d+">"+jQuery(this.selectedTableCell).html()+"</"+d+">";for(var b=parseInt(jQuery(this.selectedTableCell).attr("colspan"))-1,c=0;c<b;c++)d+="<td>&nbsp;</td>";jQuery(this.selectedTableCell).replaceWith(d);this.unselectTableCell()}};this.highlightTable=
function(d){this.selectedTableCell&&jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).find("td,th").each(function(){jQuery(this).addClass(d)})};this.highlightSelectedTable=function(){this.highlightTable("highlightTableCell")};this.highlightTableForRemoval=function(){this.highlightTable("highlightTableCellForRemoval")};this.highlightSelectedRow=function(){this.highlightRow("highlightTableCell")};this.highlightRowForRemoval=function(){this.highlightRow("highlightTableCellForRemoval")};
this.highlightRow=function(d){this.selectedTableCell&&jQuery(this.selectedTableCell).parent("tr").eq(0).find("td,th").each(function(){jQuery(this).addClass(d)})};this.getColumnNumber=function(d){var b=0;d=jQuery(d).prevAll("td,th");for(var c=0;c<d.length;c++)b+=parseInt(jQuery(d[c]).attr("colspan")>1?jQuery(d[c]).attr("colspan"):1);return b};this.getColumnInPosition=function(d,b){for(var c=0;c<d.length;c++)if(this.getColumnNumber(d[c])>=b)return d[c]};this.highlightSelectedCol=function(){this.highlightCol("highlightTableCell")};
this.highlightColForRemoval=function(){this.highlightCol("highlightTableCellForRemoval")};this.highlightCol=function(d){if(this.selectedTableCell){var b=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);jQuery(b).each(function(){jQuery(this).addClass(d)})}};this.removeHighlight=function(d){d?jQuery(this.selectedTableCell).parents("table.wiki_table").find("."+d).each(function(){jQuery(this).removeClass(d)}):jQuery(this.selectedTableCell).parents("table.wiki_table").find(".highlightTableCell,.highlightTableCellForRemoval,.highlightTableCellForMerge").each(function(){jQuery(this).removeClass("highlightTableCell").removeClass("highlightTableCellForRemoval").removeClass("highlightTableCellForMerge")})};
this.addNewRow=function(d,b){if(this.selectedTableCell){for(var c=0,f=jQuery(this.selectedTableCell).parent("tr").eq(0).find("td,th"),g=0;g<f.length;g++)c+=parseInt(jQuery(f[g]).attr("colspan")>1?jQuery(f[g]).attr("colspan"):1);if(d)f='<tr class="tablePreview"><td colspan="'+c+'">&nbsp;</td></tr>';else{f="<tr>";for(g=0;g<c;g++)f+="<td>&nbsp;</td>";f+="</tr>"}b?jQuery(this.selectedTableCell).parent("tr").eq(0).before(f):jQuery(this.selectedTableCell).parent("tr").eq(0).after(f);if(!d){this.removePreviews();
this.unselectTableCell()}}};this.removeRow=function(){if(this.selectedTableCell){jQuery(this.selectedTableCell).parent("tr").eq(0).remove();this.unselectTableCell()}};this.addNewCol=function(d,b){if(this.selectedTableCell){var c=d?'<td class="tablePreview">&nbsp;&nbsp;&nbsp;&nbsp;</td>':"<td>&nbsp;</td>",f=this.getColumnNumber(this.selectedTableCell);if(!b){var g=parseInt(jQuery(this.selectedTableCell).attr("colspan")>1?jQuery(this.selectedTableCell).attr("colspan"):1);f=f+g-1}f=this.getColCells(f,
true);jQuery(f).each(function(){b?jQuery(this).before(c):jQuery(this).after(c)});if(!d){this.removePreviews();this.unselectTableCell()}}};this.removeTable=function(){if(this.selectedTableCell){jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).remove();this.unselectTableCell()}};this.removeCol=function(){if(this.selectedTableCell){var d=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);jQuery(d).each(function(){jQuery(this).remove()});this.unselectTableCell()}};this.alignCell=
function(d){jQuery(this.selectedTableCell).is("td")&&jQuery(this.selectedTableCell).css("text-align",d)};this.alignRow=function(d){var b=jQuery(this.selectedTableCell).parent("tr").eq(0).find("td,th");jQuery(b).each(function(){jQuery(this).is("td")&&jQuery(this).css("text-align",d)})};this.alignCol=function(d){var b=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);jQuery(b).each(function(){jQuery(this).is("td")&&jQuery(this).css("text-align",d)})};this.alignTable=function(d){var b=
jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).find("td,th");jQuery(b).each(function(){jQuery(this).is("td")&&jQuery(this).css("text-align",d)})};this.getColCells=function(d,b){if(this.selectedTableCell){for(var c=jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).find("tr"),f=[],g=0;g<c.length;g++)for(var h=jQuery(c[g]).children(),k=0,l=0;l<h.length;l++){k+=parseInt(jQuery(h[l]).attr("colspan")>1?jQuery(h[l]).attr("colspan"):1);if(k>d){f[f.length]=h[l];break}else if(k>
d&&b){f[f.length]=h[l-1];break}}return f}};this.removePreviews=function(){jQuery(this.selectedTableCell).parents("table.wiki_table").find(".tablePreview").each(function(){jQuery(this).remove()})};this.addTable=function(d,b){WikispacesCommon.track("Editor","Add Table",d+"x"+b);if(this.area.editor.mode==this.area.editor.VISUAL){for(var c='<table class="wiki_table" id="__newTable__">\n',f=0;f<d;f++){c+="<tr>\n";for(var g=0;g<b;g++)c+="<td>&nbsp;</td>\n";c+="</tr>\n"}c+="</table>\n";this.area.insertInEditor(c);
this.area.showGuidelines("");d=jQuery(this.area.getEditorWindow().document.body).find("#__newTable__").attr("id","");d.find("td,th").each(function(){jQuery(this).height()<20&&jQuery(this).height(20);jQuery(this).width()<5&&jQuery(this).width(5)});d=d.find("td:first,th:first").get(0);(new Selection(this.area.getEditorWindow())).getRangeAt(0).selectNode(d);this.area.selectElement(d);this.area.getEditorWindow().focus()}else{c="";for(f=0;f<d;f++){c+="\n||";for(g=0;g<b;g++)c+=" ||"}c+="\n";this.area.insertInEditor(c)}}}
function WikispacesTableToolbar(e){this.toolbar=e;this.menuHandleLoaded=this.tablePropertiesShown=false;var d=this;this.openTablePopup=function(){if(this.toolbar.editor.getCurrentArea().tableTool.selectedTableCell)this.showTablePropertiesPopup();else{WikispacesCommon.track("Editor","Open Table Tool");this.toolbar.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.tablePopup){this.tablePopup=new Window("tablePopup",{minWidth:300,title:"Insert Table",
resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal");d.toolbar.editor.getCurrentArea().restoreCursor()},showEffect:Element.show,hideEffect:Element.hide});this.tablePopup.setHTMLContent(WikispacesToolbar.getContent("tablePopupContents"),true,true);this.tablePopup.getContent().style.overflow="hidden";WikispacesToolbar.setPopupSize(this.tablePopup,true);this.setup()}this.tablePopup.showCenter();this.tablePopup.toFront()}};
this.hideTablePropertiesPopup=function(){if(this.tablePropertiesShown){jQuery("#tablePropertiesList ul").hide();jQuery("#tablePropertiesMenuHandle").hide();jQuery("#tableProperties").hide();this.tablePropertiesShown=false}};this.showTablePropertiesMenuHandle=function(){if(!this.menuHandleLoaded){jQuery("body").append(WikispacesToolbar.getContent("tableMenu"));this.setupMenu();this.menuHandleLoaded=true}var b=this.toolbar.getPositionWith(jQuery("#tablePropertiesMenuHandle").get(0),this.toolbar.editor.getCurrentArea().tableTool.selectedTableCell);
jQuery("#tablePropertiesMenuHandle").css("position","absolute").css("left",b.left+5).css("top",b.top+5).show();b=this.toolbar.editor.getCurrentArea().getZIndex()+1;jQuery("#tablePropertiesMenuHandle").css("z-index",b);this.tablePropertiesShown=true};this.showTablePropertiesPopup=function(){jQuery("#tablePropertiesMenuHandle").hide();var b=this.toolbar.getPositionWith(jQuery("#tableProperties").get(0),this.toolbar.editor.getCurrentArea().tableTool.selectedTableCell);jQuery("#tableProperties").css("position",
"absolute").css("left",b.left+5).css("top",b.top+5).show();b=this.toolbar.editor.getCurrentArea().getZIndex()+1;jQuery("#tableProperties").css("z-index",b);this.tablePropertiesShown=true};this.selectTableCell=function(b){if(jQuery(b).is("td")){jQuery("#tablePropertiesList .headerToggleLabel").text("Make Header");jQuery("#tablePropertiesList .alignmentMenu").not(".tableAlignmentMenu").removeClass("disabledMenu")}else{jQuery("#tablePropertiesList .headerToggleLabel").text("Remove Header");jQuery("#tablePropertiesList .alignmentMenu").not(".tableAlignmentMenu").addClass("disabledMenu")}jQuery(b).attr("colspan")>
1?jQuery("#tablePropertiesList .mergeSplit").removeClass("disabledMenu"):jQuery("#tablePropertiesList .mergeSplit").addClass("disabledMenu");jQuery(b).prev("td,th").length>0?jQuery("#tablePropertiesList .mergeLeft").removeClass("disabledMenu"):jQuery("#tablePropertiesList .mergeLeft").addClass("disabledMenu");jQuery(b).next("td,th").length>0?jQuery("#tablePropertiesList .mergeRight").removeClass("disabledMenu"):jQuery("#tablePropertiesList .mergeRight").addClass("disabledMenu")};this.tablePropertiesShow=
function(b,c){b.is("ul")&&b.is(":visible")&&b.slideUp("fast");if(b.is("ul")&&!b.is(":visible")){jQuery(c).slideUp("fast");b.slideDown("fast")}};this.getScope=function(b){var c;b=jQuery(b);if(b.is("#cellItem")||b.parents("#cellItem").length)c="Cell";else if(b.is("#rowItem")||b.parents("#rowItem").length)c="Row";else if(b.is("#colItem")||b.parents("#colItem").length)c="Col";else if(b.is("#tableItem")||b.parents("#tableItem").length)c="Table";return c};this.setup=function(){jQuery("#addTableButton").click(function(){d.toolbar.editor.getCurrentArea().tableTool.addTable(document.insertTableForm.rows.value,
document.insertTableForm.cols.value);d.tablePopup.close()});jQuery("#tableCancelLink").click(function(){d.tablePopup.close();return false})};this.setupMenu=function(){jQuery("#tablePropertiesList ul").hide();jQuery("#tablePropertiesList .topmenu").click(function(b){b.stopPropagation();d.tablePropertiesShow(jQuery(this).next(),"#tablePropertiesList li ul:visible");return false});jQuery("#tablePropertiesList .submenu").click(function(b){b.stopPropagation();d.tablePropertiesShow(jQuery(this).next(),
"#tablePropertiesList li ul li ul:visible");return false});jQuery("#tablePropertiesMenuHandle").click(function(b){b.stopPropagation();jQuery("#tablePropertiesList ul").hide();d.showTablePropertiesPopup();return false});jQuery("#cellItem, #rowItem, #colItem, #tableItem").mouseover(function(){var b="highlight"+d.getScope(this);d.toolbar.editor.getCurrentArea().tableTool[b]("highlightTableCell");return true});jQuery("#cellItem, #rowItem, #colItem, #tableItem").mouseout(function(){d.toolbar.editor.getCurrentArea().tableTool.removeHighlight();
return true});jQuery("#tableProperties .mergeMenu li").mouseover(function(){var b,c;switch(jQuery(this).attr("class")){case "mergeLeft":c=true;b="highlight"+d.getScope(this)+"ForMerge";break;case "mergeRight":c=false;b="highlight"+d.getScope(this)+"ForMerge";break;case "mergeUp":c=true;b="highlight"+d.getScope(this)+"ForRowMerge";break;case "mergeDown":c=false;b="highlight"+d.getScope(this)+"ForRowMerge";break}b&&d.toolbar.editor.getCurrentArea().tableTool[b](c);return true});jQuery("#tableProperties .mergeMenu li").mouseout(function(){d.toolbar.editor.getCurrentArea().tableTool.removeHighlight("highlightTableCellForMerge");
return true});jQuery("#tableProperties .mergeMenu li").click(function(){var b,c;switch(jQuery(this).attr("class")){case "mergeLeft":c=true;b="merge"+d.getScope(this);break;case "mergeRight":c=false;b="merge"+d.getScope(this);break;case "mergeUp":c=true;b="mergeRow"+d.getScope(this);break;case "mergeDown":c=false;b="mergeRow"+d.getScope(this);break;case "mergeSplit":c=d.toolbar.editor.getCurrentArea().tableTool.selectTableCell;b="splitCell";break}d.toolbar.editor.getCurrentArea().tableTool[b](c);return false});
jQuery("#tableProperties .headerMenu").click(function(){d.toolbar.editor.getCurrentArea();var b="convert"+d.getScope(this)+"Type";d.toolbar.editor.getCurrentArea().tableTool[b]();return false});jQuery("#tableProperties .addMenu li").mouseover(function(){var b,c;switch(jQuery(this).attr("class")){case "addPre":log("pre");c=true;b="addNew"+d.getScope(this);break;case "addPost":log("post");c=false;b="addNew"+d.getScope(this);break}d.toolbar.editor.getCurrentArea().tableTool[b](true,c);return true});
jQuery("#tableProperties .addMenu li").mouseout(function(){d.toolbar.editor.getCurrentArea().tableTool.removePreviews();return true});jQuery("#tableProperties .addMenu li").click(function(){var b,c;switch(jQuery(this).attr("class")){case "addPre":c=true;b="addNew"+d.getScope(this);break;case "addPost":c=false;b="addNew"+d.getScope(this);break}d.toolbar.editor.getCurrentArea().tableTool[b](false,c);return false});jQuery("#tableProperties .alignmentMenu li").click(function(){var b="align"+d.getScope(this),
c=jQuery(this).attr("class");d.toolbar.editor.getCurrentArea().tableTool[b](c);return false});jQuery("#tableProperties .removeMenu").mouseover(function(){var b="highlight"+d.getScope(this)+"ForRemoval";d.toolbar.editor.getCurrentArea().tableTool[b]();return true});jQuery("#tableProperties .removeMenu").mouseout(function(){d.toolbar.editor.getCurrentArea().tableTool.removeHighlight("highlightTableCellForRemoval");return true});jQuery("#tableProperties .removeMenu").click(function(){var b="remove"+
d.getScope(this);d.toolbar.editor.getCurrentArea().tableTool[b]();return false})}}
function WikispacesTextEditor(){this.openStylePopup=function(){this.expandSelectionToTag("<span","","</span>");var e=this.getSelectedText();this.editor.toolbar.styleToolbar.openStylePopup();this.editor.toolbar.styleToolbar.setSpanTextTextEditor(e)};this.insertImageInEditorCallback=function(e,d,b){if("embed"==document.forms.imageToolForm.insertMode.value)if(d=="audio"||d=="video")this.insertInEditor('[[media type="file" key="'+e+'"]]');else{var c="";if(d=="image"&&b.width>800)c=' width="800" height="'+
Math.floor(800/b.width*b.height)+'"';this.insertInEditor("[["+d+":"+e+c+"]]")}else this.insertInEditor("[[http://"+window.location.hostname+"/file/view/"+encodeURIComponent(e)+"|"+e+"]]")};this.editorSubmit=function(){this.autosave(false);var e=jQuery("#mergeStatus").html(),d=jQuery("#mergeResult").val();if(e=="success"){jQuery("#textEditor").val(d);WikispacesCommon.track("Editor","Concurrent Editing","Merge Success")}if(this.anotherEditDetected&&e!="success"&&this.editorSaving){this.showConcurrentEditorPopup();
this.editorSaving=false;if(confirm("Someone else has made changes to this page since you started editing.\n\nIf you click OK, we will save your page incorporating as much of their revision as possible, and overwrite the changes that cannot be merged. You will still be able to look back at their changes from the page history tab.\n\nIf you click Cancel, you can either cancel your edit entirely and start again with the latest copy of the page, or use the Page Activity window to look at the changes they have made.")){jQuery("#textEditor").val(d);
WikispacesCommon.track("Editor","Stop","Save");this.timeTracker._recordEndTime();this.timeTracker._track(pageTracker,undefined,"Editor");WikispacesCommon.track("Editor","Concurrent Editing","Merge Failed - Overwrite");return true}else{WikispacesCommon.track("Editor","Concurrent Editing","Merge Failed - Cancel");return false}}WikispacesCommon.track("Editor","Stop","Save");this.timeTracker._recordEndTime();this.timeTracker._track(pageTracker,undefined,"Editor");return true};this.insertInEditor=function(e){var d=
document.getElementById("textEditor");d.focus();if(document.selection){sel=document.selection.createRange();sel.text=e;sel.select()}else if(d.selectionStart||d.selectionStart=="0"){var b=d.scrollTop,c=d.selectionStart,f=d.selectionEnd;d.value=d.value.substring(0,c)+e+d.value.substring(f,d.value.length);c==f?this.setSelectionRange(d,c+e.length,c+e.length):this.setSelectionRange(d,c,c+e.length);d.scrollTop=b}else d.value+=e;this.detectedChange()};this.insertCode=function(){var e=document.codeMediaForm.code.value,
d=document.codeMediaForm.format.value;d||(d="text");WikispacesCommon.track("Editor","Add Code",d);this.insertInEditor('\n[[code format="'+d+'"]]\n'+e+"\n[[code]]\n");document.codeMediaForm.reset();Windows.close("codePopup")};this.addListInTextEditor=function(e){this.getSelectedText()||this.expandSelectionToLine();var d=document.getElementById("textEditor");this.prepareSelection(d);var b=d.sel_text,c="",f=true;b=b.split("\n");for(var g=0;g<b.length;g++){var h;if(h=b[g].match(/^(\#|\*|\>)+\s(.*)$/i)){if(h[1].charAt(0)!=
e)f=false;c+="\n"+e+" "+h[2]}else{f=false;c+="\n"+e+" "+b[g]}}if(d.sel_text_pre.length==0||d.sel_text_pre.charAt(d.sel_text_pre.length-1)=="\n")c=c.substring(1,c.length);if(f){b=d.sel_text;c="";b=b.split("\n");for(g=0;g<b.length;g++)if(h=b[g].match(/^(\#|\*|\>)+\s(.*)$/i))c+=h[2]+"\n";if(d.sel_text.charAt(d.sel_text.length-1)!="\n")c=c.substring(0,c.length-1)}this.insertInEditor(c)};this.wrapTextEditorSelection=function(e){var d=this.getSelectedText(),b=d.length;d=d.replace(/^\s+/,"");var c=b-d.length;
d=d.replace(/\s+$/,"");var f=b-c-d.length;b="";b=d.substring(0,e.length)==e&&d.substring(d.length-e.length,d.length)==e?d.substring(e.length,d.length-e.length):e+d+e;for(e=0;e<c;e++)b=" "+b;for(e=0;e<f;e++)b+=" ";c=document.getElementById("textEditor");this.prepareSelection(c);d=c.cur_start;f=c.cur_end;var g=b.length;if(jQuery.browser.msie)for(e=0;e<=b.length;e++)b.charAt(e)=="\n"&&g--;this.insertInEditor(b);d==f?this.setSelectionRange(c,d+g/2,d+g/2):this.setSelectionRange(c,d,g+d);c.focus()};this.editorBold=
function(){WikispacesCommon.track("Editor","Bold");this.editor.getCurrentArea().wrapTextEditorSelection("**")};this.editorItalic=function(){WikispacesCommon.track("Editor","Italic");this.editor.getCurrentArea().wrapTextEditorSelection("//")};this.editorUnderline=function(){WikispacesCommon.track("Editor","Underline");this.editor.getCurrentArea().wrapTextEditorSelection("__")};this.editorOL=function(){WikispacesCommon.track("Editor","Add Ordered List");this.editor.getCurrentArea().addListInTextEditor("#")};
this.editorUL=function(){WikispacesCommon.track("Editor","Add Unordered List");this.editor.getCurrentArea().addListInTextEditor("*")};this.editorHR=function(){WikispacesCommon.track("Editor","Add Horizontal Rule");this.insertInEditor("\n----\n")};this.editorInsertLink=function(){this.expandSelectionToTag("[[","","]]");this.editor.toolbar.linkToolbar.openLinkPopup()};this.editorRemoveLink=function(){WikispacesCommon.track("Editor","Remove Link");if(this.expandSelectionToTag("[[","","]]")){var e=this.getSelectedText();
if(e!="[[code]]"&&!e.match(/^\[\[media /)&&!e.match(/^\[\[file /)&&!e.match(/^\[\[image /)&&!e.match(/^\[\[include /)){e=e.match(/(\s*)\[\[([^\]]*)\]\](\s*)/);e=e[1]+e[2]+e[3];this.insertInEditor(e);return}}alert("Please put your cursor inside of the link wikitext to remove it")};this.editorInsertImage=function(){this.editor.toolbar.imageToolbar.toggleImageEditTool();return false};this.editorEmbedMedia=function(){var e;this.editor.toolbar.mediaToolbar.showMediaTool();this.editor.toolbar.mediaToolbar.setMediaMenu("main");
if(this.expandSelectionToTag("[[","media","]]")){e=this.getSelectedText().match(/\[\[media (.*)\]\]/)[1];this.editor.toolbar.mediaToolbar.loadMedia("wikitext@@media@@"+e)}else if(this.expandSelectionToTag("[[","rss","]]")){e=this.getSelectedText().match(/\[\[rss (.*)\]\]/)[1];this.editor.toolbar.mediaToolbar.loadMedia("wikitext@@rss@@"+e)}};this.editorSelectFont=function(e){var d=e.options[e.selectedIndex].value;WikispacesCommon.track("Editor","Select Font",d);var b="";if(d=="<h1>")b="=";else if(d==
"<h2>")b="==";else if(d=="<h3>")b="===";else if(d=="<h4>")b="====";else if(d=="<h5>")b="=====";else if(d=="<h6>")b="======";if(b)if(this.getSelectedText())this.insertInEditor("\n"+b+this.getSelectedText()+b+"\n");else{d=document.getElementById("textEditor");this.prepareSelection(d);var c=d.sel_start+b.length+1;this.insertInEditor("\n"+b+b+"\n");this.setSelectionRange(d,c,c)}document.getElementById("textEditor").focus();e.selectedIndex=3};this.autosaveLoadDraft=function(e){WikispacesCommon.track("Editor",
"Autosave","Load");this.version=this.autosaveVersion;document.rte.version.value=this.version;document.rte[this.areaId].value=jQuery("#autosaveContent").val();this.customEditorStartSecondary(e);this.detectedChangeDelayed()};this.customEditorStartSecondary=function(){var e=this;this.editor.toolbar.floatToolbar();jQuery("#textEditor").keypress(function(){e.detectedChange()});WikispacesCommon.track("Editor","Start","Text");return true};this.getSelectedText=function(){var e=document.getElementById("textEditor");
if(e){this.prepareSelection(e);return e.sel_text?e.sel_text:""}return""}}var TimeTracker=function(e){this.bucket_=e?e.sort(this.sortNumber):TimeTracker.DEFAULT_BUCKET};TimeTracker.DEFAULT_BUCKET=[100,500,1500,2500,5E3];a=TimeTracker.prototype;a._getTimeDiff=function(){return this.stopTime_-this.startTime_};a.sortNumber=function(e,d){return e-d};a._recordStartTime=function(e){this.startTime_=e!=undefined?e:(new Date).getTime()};a._recordEndTime=function(e){this.stopTime_=e!=undefined?e:(new Date).getTime()};
a._track=function(e,d,b){e=d!=undefined&&d.length!=0?e._createEventTracker(d):e._createEventTracker("TimeTracker");var c;for(d=0;d<this.bucket_.length;d++)if(this._getTimeDiff()<this.bucket_[d]){c=d==0?"0-"+this.bucket_[0]:this.bucket_[d-1]+"-"+(this.bucket_[d]-1);break}c||(c=this.bucket_[d-1]+"+");e._trackEvent(c,b,this._getTimeDiff())};a._setHistogramBuckets=function(e){this.bucket_=e.sort(this.sortNumber)};
function WikispacesToolbar(e){this.editor=e;this.imageToolbar=new WikispacesImageToolbar(this);this.linkToolbar=new WikispacesLinkToolbar(this);this.tableToolbar=new WikispacesTableToolbar(this);this.mediaToolbar=new WikispacesMediaToolbar(this);this.styleToolbar=new WikispacesStyleToolbar(this);this.onScrollFunctions=Array();var d=this;this.floatToolbar=function(){if(!this.toolbarPopup){this.toolbarPopup=new Window("toolbarPopup",{minWidth:800,minHeight:36,title:"Editor",resizable:false,maximizable:false,
minimizable:false,closable:false,className:"wikispaces",showEffect:Element.show,hideEffect:Element.hide,helpText:""});this.toolbarPopup.setHTMLContent(WikispacesToolbar.getContent("toolbar"),true,true);this.toolbarPopup.setSize(800,36);var b;b=this.editor.mode==this.editor.PLAIN?document.getElementById("textEditor"):document.getElementById("editor");this.toolbarPopup.element.style.left=jQuery(b).offset().left-16+"px";if(jQuery.browser.msie&&jQuery.browser.version<7){this.toolbarPopup.element.style.top=
document.documentElement.scrollTop+"px";this.registerOnScroll(function(){WikispacesToolbar.scrollWindow(d.toolbarPopup,true)})}else{this.toolbarPopup.element.style.position="fixed";this.toolbarPopup.element.style.top="0px"}this.toolbarPopup.getContent().style.overflow="hidden";this.setup()}this.toolbarPopup.show();this.toolbarPopup.toFront();this.toolbarPopup.updateWidth();this.toolbarPopup.updateHeight()};this.setup=function(){var b=jQuery(this.toolbarPopup.getContent());b.find("#rteBoldBtn").click(function(){d.editor.getCurrentArea().editorBold()});
b.find("#rteItalicBtn").click(function(){d.editor.getCurrentArea().editorItalic()});b.find("#rteUnderlineBtn").click(function(){d.editor.getCurrentArea().editorUnderline()});b.find("#rteTextColorBtn").click(function(){d.editor.getCurrentArea().openStylePopup()});b.find("#rteFormatBlock").change(function(){d.editor.getCurrentArea().editorSelectFont(this)});b.find("#rteOrderedListBtn").click(function(){d.editor.getCurrentArea().editorOL()});b.find("#rteUnorderedListBtn").click(function(){d.editor.getCurrentArea().editorUL()});
b.find("#rteHRBtn").click(function(){d.editor.getCurrentArea().editorHR()});b.find("#rteLinkBtn").click(function(){d.editor.getCurrentArea().editorInsertLink()});b.find("#rteLinkRemoveBtn").click(function(){d.editor.getCurrentArea().editorRemoveLink()});b.find("#rteImageBtn").click(function(){d.editor.getCurrentArea().editorInsertImage()});b.find("#rteMediaBtn").click(function(){d.editor.getCurrentArea().editorEmbedMedia()});b.find("#rteTableBtn").click(function(){d.tableToolbar.openTablePopup()});
b=this.editor.mode==this.editor.VISUAL?"WikiText Editor":"Visual Editor";jQuery(document.rte).submit(function(){return d.editor.getMainArea().editorSubmit()});jQuery("#switch_to").val(b).attr("name","switch_to_"+(this.editor.mode==this.editor.VISUAL?this.editor.PLAIN:this.editor.VISUAL));jQuery(document.rte.update).click(function(){d.editor.getMainArea().editorConfirmDeparture=false;d.editor.getMainArea().editorSaving=true});jQuery("#switch_top").val(b).find("#switch_top_text").html("<span><span>"+
b+"</span></span>").closest("li").click(function(c){d.editor.getMainArea().editorConfirmDeparture=false;jQuery("#switch_to").get(0).click();c.preventDefault()});jQuery("#savewithcomment_top").closest("li").click(function(c){d.showSaveWithCommentPopup();c.preventDefault()});if(jQuery.browser.safari&&jQuery.browser.version<500||jQuery.browser.opera){jQuery("#switch_to").hide();jQuery("#switch_top").hide()}jQuery("#preview_top").click(function(c){d.editor.getMainArea().showPreview();c.preventDefault()});
jQuery("#update_top").click(function(c){document.rte.update.click();c.preventDefault()});jQuery("#cancel_top").click(function(c){d.editor.getMainArea().cancelEdit(this);c.preventDefault()});jQuery.browser.msie&&"6.0"==jQuery.browser.version&&jQuery("#wikispacesEditorToolbar .rteButton").hover(function(){jQuery(this).addClass("rteButtonHover")},function(){jQuery(this).removeClass("rteButtonHover").removeClass("rteButtonPressed")}).mousedown(function(){jQuery(this).addClass("rteButtonPressed")}).mouseup(function(){jQuery(this).removeClass("rteButtonPressed")})};
this.showSaveWithCommentPopup=function(){WikispacesCommon.track("Editor","Stop","Comment");this.editor.getCurrentArea().saveCursor();WindowUtilities.disableScreen("wikispaces","overlay_modal",0);if(!this.saveWithCommentPopup){this.saveWithCommentPopup=new Window("saveWithCommentPopup",{minWidth:420,minHeight:90,title:"Save With Comment",resizable:false,maximizable:false,minimizable:false,closable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal");d.editor.getCurrentArea().restoreCursor()},
showEffect:Element.show,hideEffect:Element.hide,helpText:""});this.saveWithCommentPopup.setHTMLContent(WikispacesToolbar.getContent("saveWithComment"),true,true);this.saveWithCommentPopup.setSize(420,90);jQuery("#saveWithCommentComment").val(jQuery(document.rte.comment).val());jQuery("#saveWithCommentSave").click(function(b){jQuery(document.rte.comment).val(jQuery("#saveWithCommentComment").val());document.rte.update.click();b.preventDefault()});jQuery("#saveWithCommentCancel").click(function(b){d.saveWithCommentPopup.close();
b.preventDefault()})}this.saveWithCommentPopup.show();jQuery("#saveWithCommentComment").focus();this.saveWithCommentPopup.toFront();this.saveWithCommentPopup.updateWidth();this.saveWithCommentPopup.updateHeight();this.saveWithCommentPopup.showCenter()};this.showAutosavePopup=function(b){var c=Dialog.confirm(document.getElementById("autosavePrompt").innerHTML,{title:"Draft Recovered",windowParameters:{className:"wikispaces",width:450},id:"popupDialog",ok:function(){d.editor.getCurrentArea().autosaveLoadDraft(b);
c.hide()},cancel:function(){d.editor.getCurrentArea().autosaveDiscardDraft(b)},okLabel:"Load Previous Draft",cancelLabel:"Discard Previous Draft",resizable:false,showEffectOptions:{duration:3}})};this.getPositionWith=function(b,c){b=jQuery(b);c=jQuery(c);Position.prepare();var f=Position.cumulativeOffset(c.get(0)),g=jQuery("#"+this.editor.getCurrentArea().areaId).get(0),h=Position.cumulativeOffset(g);g=f[0]+h[0]+c.outerWidth({margin:true});c=f[1]+h[1]+c.outerHeight({margin:true});f=b.outerWidth({margin:true});
h=jQuery("body").width();if(g+f>h)g=h-f;b.outerHeight({margin:true});jQuery("body").height();if(c<0)c=0;if(g<0)g=0;return{left:g,top:c}};this.setAutosaveStatus=function(b,c){var f=jQuery("#autosaveStatus");if(!f.length){f=jQuery('<div id="autosaveStatus">');jQuery("#toolbarPopup_top").append(f)}f.html(b);c?f.css("color","red"):f.css("color","");f.hide().fadeIn("slow")};this.registerOnScroll=function(b){this.onScrollFunctions[this.onScrollFunctions.length]=b};this.onScrollCallback=function(){for(i=
0;i<this.onScrollFunctions.length;i++)this.onScrollFunctions[i]()};window.onscroll=function(){d.onScrollCallback()}}
WikispacesToolbar.setPopupSize=function(e,d){var b=jQuery(e.getContent()).children().eq(0);jQuery(e).ready(function(){setTimeout(function(){var c=b.outerWidth({margin:true}),f=b.outerHeight({margin:true});if(jQuery.browser.safari){alternateWidth=b.outerWidth();alternateHeight=b.outerHeight();if(alternateWidth>c)c=alternateWidth;if(alternateHeight>f)f=alternateHeight}b.find("table").each(function(){var g=jQuery(this).outerWidth({margin:true}),h=jQuery(this).outerHeight({margin:true});if(g>c)c=g;if(h>
f)f=h});b.find("iframe").each(function(){var g=jQuery(this).outerWidth({margin:true})+20,h=jQuery(this).outerHeight({margin:true})+20;if(g>c)c=g;if(h>f)f=h});if(f<e.options.minHeight)f=e.options.minHeight;if(c<e.options.minWidth)c=e.options.minWidth;if(f>jQuery(window).height()-25)f=jQuery(window).height()-25;if(c>jQuery(window).width()-5)c=jQuery(window).width()-5;e.setSize(c,f);d&&e.showCenter()},10)})};
WikispacesToolbar.scrollWindow=function(e,d){if(e)d?jQuery(e.element).css("top",document.documentElement.scrollTop):jQuery(e.element).css("top",document.documentElement.clientHeight+document.documentElement.scrollTop-e.element.getHeight())};
WikispacesToolbar.snapPopupToScreen=function(e){var d=jQuery(e.element).width(),b=jQuery(e.element).height(),c=document.documentElement.scrollTop,f=document.documentElement.scrollLeft,g=document.documentElement.clientWidth+document.documentElement.scrollLeft,h=document.documentElement.clientHeight+document.documentElement.scrollTop,k=false,l=false;if(Position.positionedOffset(e.element)[0]+d>g)k=g-d-5;if(Position.positionedOffset(e.element)[1]+b>h)l=h-b-5;if(Position.positionedOffset(e.element)[0]<
f||k!==false&&k<f)k=f;if(Position.positionedOffset(e.element)[1]<c||l!==false&&l<c)l=c;if(k!==false)e.element.style.left=k+"px";if(l!==false)e.element.style.top=l+"px"};WikispacesToolbar.getContent=function(e){if(WikispacesContent[e])return WikispacesContent[e];else throw"Unloaded editor part: "+e;};
function WikispacesVisualEditor(){this.openStylePopup=function(){if(jQuery("#rteFormatBlock").val()=="<code>")alert("You cannot apply a style inside of a code block.");else{this.editor.toolbar.styleToolbar.openStylePopup();var e=this.styleTool.getSelectedSpans();this.styleTool.selectedSpans=e;if(jQuery(this.styleTool.selectedSpans).parents("a").eq(0).length>0){document.styleForm.styleColor.disabled=true;document.styleForm.styleColor.style.backgroundColor="#CCCCCC"}else document.styleForm.styleColor.disabled=
false;this.editor.toolbar.styleToolbar.setSpanTextVisualEditor(e[0])}};this.insertImageInEditorCallback=function(e,d,b){var c=this;if("embed"==document.forms.imageToolForm.insertMode.value){var f="newImage-"+this.imageTool.newImageIdCounter++;if(d=="image"){d="";if(b.width>800)d=' width="800" height="'+Math.floor(800/b.width*b.height)+'"';e.substring(0,7)=="http://"||e.substring(0,8)=="https://"||e.substring(0,6)=="ftp://"?this.insertInEditor('<img id="'+f+'" src="'+e+'"'+d+"/>"):this.insertInEditor('<img id="'+
f+'" src="/file/view/'+encodeURIComponent(e)+'"'+d+"/>");this.imageTool.selectImage(this.getEditorWindow().document.getElementById(f))}else if(d=="audio"){b=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");d="type=&quot;file&quot; key=&quot;"+b+"&quot;";f="wikitext@@media@@"+d;this.insertInEditor('<img src="http://www.'+wikispaces_domain+"/site/embedthumbnail/file-audio/"+encodeURIComponent(e)+'?h=20&w=240" class="WikiMedia WikiMediaFile" id="wikitext@@media@@'+d+'" title="Audio Player: '+
b+'" />')}else if(d=="video"){b=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");d="type=&quot;file&quot; key=&quot;"+b+"&quot;";f="wikitext@@media@@"+d;this.insertInEditor('<img src="http://www.'+wikispaces_domain+"/site/embedthumbnail/file-video/"+encodeURIComponent(e)+'?h=300&w=300" class="WikiMedia WikiMediaFile" id="wikitext@@media@@'+d+'" title="Video Player: '+b+'" />')}else{d=b=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");f="wikitext@@file@@"+d;this.insertInEditor('<img src="http://www.'+
wikispaces_domain+"/site/embedthumbnail/file/"+encodeURIComponent(e)+'?h=40&w=200" class="WikiFile" id="wikitext@@file@@'+d+'" title="File: '+b+'" />')}jQuery(this.getEditorWindow().document).find("#"+f).ready(function(){c.lookForHeightChange()})}else this.insertInEditor('<a href="http://'+window.location.hostname+"/file/view/"+encodeURIComponent(e)+'">'+e+"</a>")};this.editorSubmit=function(){this.autosave(false);var e=jQuery("#mergeStatus").html(),d=jQuery("#mergeResult").html(),b=document.getElementById("hdn"+
this.areaId);if(e=="success"){if(b.value==null)b.value="";b.value=d;WikispacesCommon.track("Editor","Concurrent Editing","Merge Success");return true}this.rteCleanup();if(this.anotherEditDetected&&e!="success"&&this.editorSaving){this.showConcurrentEditorPopup();this.editorSaving=false;if(confirm("Someone else has made changes to this page since you started editing.\n\nIf you click OK, we will save your page incorporating as much of their revision as possible, and overwrite the changes that cannot be merged. You will still be able to look back at their changes from the page history tab.\n\nIf you click Cancel, you can either cancel your edit entirely and start again with the latest copy of the page, or use the Page Activity window to look at the changes they have made.")){b.value=
d;WikispacesCommon.track("Editor","Stop","Save");this.timeTracker._recordEndTime();this.timeTracker._track(pageTracker,undefined,"Editor");WikispacesCommon.track("Editor","Concurrent Editing","Merge Failed - Overwrite");return true}else{WikispacesCommon.track("Editor","Concurrent Editing","Merge Failed - Cancel");return false}}WikispacesCommon.track("Editor","Stop","Save");this.timeTracker._recordEndTime();this.timeTracker._track(pageTracker,undefined,"Editor");return true};this.insertInEditor=function(e){this.insertInEditorActual(e,
true)};this.insertInEditorActual=function(e,d){var b=this.getEditorWindow();b.focus();d&&this.restoreCursor();b.focus();this.moveSelectionIntoEditor(b);if(this.imageTool.selectedImage){jQuery(this.imageTool.selectedImage).replaceWith(e);this.imageTool.unSelectImage()}else if(this.mediaTool.selectedMedia){jQuery(this.mediaTool.selectedMedia).replaceWith(e);this.mediaTool.unSelectMedia()}else if(jQuery.browser.msie){b=b.document.selection.createRange();b.pasteHTML(e);b.collapse(false);b.select()}else{d=
b.getSelection();for(var c=0;c<d.rangeCount;c++)d.getRangeAt(c).deleteContents();c=d.getRangeAt(0);e=c.createContextualFragment(e);c.insertNode(e);d.removeAllRanges();d=b.getSelection();d.addRange(c);b.focus()}this.detectedChangeDelayed()};this.insertCode=function(){var e=document.codeMediaForm.code.value;e=e.escapeHTML();var d=document.codeMediaForm.format.value;d||(d="text");WikispacesCommon.track("Editor","Add Code",d);this.insertInEditor('<pre class="'+d+'">'+e+"</pre>");document.codeMediaForm.reset();
Windows.close("codePopup")};this.editorBold=function(){WikispacesCommon.track("Editor","Bold");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"bold","")};this.editorItalic=function(){WikispacesCommon.track("Editor","Italic");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"italic","")};this.editorUnderline=function(){WikispacesCommon.track("Editor","Underline");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"underline","")};this.editorOL=
function(){WikispacesCommon.track("Editor","Add Ordered List");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"insertorderedlist","")};this.editorUL=function(){WikispacesCommon.track("Editor","Add Unordered List");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"insertunorderedlist","")};this.editorHR=function(){WikispacesCommon.track("Editor","Add Horizontal Rule");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"inserthorizontalrule",
"")};this.editorInsertLink=function(){this.editor.toolbar.linkToolbar.openLinkPopup()};this.editorRemoveLink=function(){WikispacesCommon.track("Editor","Remove Link");jQuery.browser.safari&&this.selectParent("A");this.rteCommand(this.areaId,"useCSS",true);this.rteCommand(this.areaId,"unlink","")};this.editorInsertImage=function(){this.editor.toolbar.imageToolbar.toggleImageEditTool();return false};this.editorEmbedMedia=function(){this.editor.toolbar.mediaToolbar.showMediaTool();this.editor.toolbar.mediaToolbar.setMediaMenu("main");
this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode&&this.editor.toolbar.mediaToolbar.loadMedia(this.mediaTool.selectedMedia.id)};this.editorSelectFont=function(){this.selectFont();this.updateHierarchy()};this.autosaveLoadDraft=function(e){WikispacesCommon.track("Editor","Autosave","Load");this.version=this.autosaveVersion;document.rte.version.value=this.version;jQuery("#"+e).html(jQuery("#autosaveContent").val());this.editorCleanup=this.autosaveCleanup;this.customEditorStartSecondary(e);
this.detectedChangeDelayed()};this.customEditorStartSecondary=function(e){var d=this;log("customEditorStartSecondary",e);try{var b=false;if(""==jQuery.trim(document.getElementById(e).innerHTML)&&this.mainEditor){b=true;document.getElementById(e).innerHTML=WikispacesToolbar.getContent("blankPageContent")}this.styleTool.cleanup(document.getElementById(e),this.editorCleanup,true);this.startingSpanCount=document.getElementById(e).getElementsByTagName("span").length;var c=Element.getDimensions(document.getElementById(e)).height;
if(c<300)c=300;document.getElementById(this.areaId).height=c;if(this.mainEditor){this.referenceTool.pullOutReferences(e);log("success with pull out references")}this.enableDesignMode(document.getElementById(e).innerHTML,this.editor.stylesheetUrl);var f=jQuery(document.getElementById(this.areaId)).ready;if(jQuery.browser.msie&&parseInt(jQuery.browser.version.substring(0,jQuery.browser.version.indexOf(".")))<=7)f=jQuery(document.getElementById(this.areaId)).load;f.call(jQuery(document.getElementById(this.areaId)),
function(){d.showGuidelines();d.showCursor();d.enableSpellCheck();if(jQuery.browser.msie&&parseInt(jQuery.browser.version.substring(0,jQuery.browser.version.indexOf(".")))<=7){jQuery("#"+d.areaId).height(5E5);var h=d.getEditorWindow().document.getElementById("editor_body").scrollHeight;jQuery("#"+d.areaId).height(h)}d.lookForHeightChange();jQuery(d.getEditorWindow().document.body).find("img").load(function(){d.lookForHeightChange()});setTimeout(function(){d.lookForHeightChange()},1E3);d.mainEditor&&
d.initialRteCommands();d.attachDoubleClickEventHandlers(d.getEditorWindow().document)});if(this.mainEditor){this.editor.toolbar.floatToolbar();WikispacesCommon.disableHideOverlappingEmbeds=true}this.attachEditorEventHandlers();WikispacesCommon.track("Editor","Start","Visual")}catch(g){log("customEditorStartSecondary ("+this.areaId+") exception: "+g.name+" - "+g.message,g);return false}return true};this.attachEditorEventHandlers=function(){var e=this;log("attachEditorEventHandlers");var d=this.getEditorWindow().document;
jQuery(d).keyup(function(b){e.keyEventHandler(b)});jQuery(d).mousedown(function(b){e.mouseEventHandler(b)});jQuery(d).keydown(function(b){e.handleTabs(b)});jQuery.browser.msie&&jQuery(d).keydown(function(b){e.ieKeyPress(b)});jQuery.browser.safari&&jQuery(d).keypress(function(b){e.safariKeyPress(b)});jQuery.browser.mozilla&&jQuery(d).keypress(function(b){e.geckoKeyPress(b)});jQuery(d.body).focus(function(){e.editor.setCurrentArea(e.areaId)})};this.getSelectedText=function(){return jQuery.browser.msie?
this.getEditorWindow().document.selection.createRange().text:(new Selection(this.getEditorWindow())).getRangeAt(0).toString()}}var Window=Class.create();Window.keepMultiModalWindow=false;Window.hasEffectLib=typeof Effect!="undefined";Window.resizeEffectDuration=0.4;
Window.prototype={initialize:function(){var e,d=0;if(arguments.length>0)if(typeof arguments[0]=="string"){e=arguments[0];d=1}else e=arguments[0]?arguments[0].id:null;e||(e="window_"+(new Date).getTime());$(e)&&alert("Window "+e+" is already registered in the DOM! Make sure you use setDestroyOnClose() or destroyOnClose: true in the constructor");this.options=Object.extend({className:"dialog",blurClassName:null,minWidth:100,minHeight:20,resizable:true,closable:true,minimizable:true,maximizable:true,
draggable:true,userData:null,showEffect:Window.hasEffectLib?Effect.Appear:Element.show,hideEffect:Window.hasEffectLib?Effect.Fade:Element.hide,showEffectOptions:{},hideEffectOptions:{},effectOptions:null,parent:document.body,title:"&nbsp;",url:null,onload:Prototype.emptyFunction,width:200,height:300,opacity:1,recenterAuto:true,wiredDrag:false,closeCallback:null,destroyOnClose:false,gridX:1,gridY:1},arguments[d]||{});if(this.options.blurClassName)this.options.focusClassName=this.options.className;
if(typeof this.options.top=="undefined"&&typeof this.options.bottom=="undefined")this.options.top=this._round(Math.random()*500,this.options.gridY);if(typeof this.options.left=="undefined"&&typeof this.options.right=="undefined")this.options.left=this._round(Math.random()*500,this.options.gridX);if(this.options.effectOptions){Object.extend(this.options.hideEffectOptions,this.options.effectOptions);Object.extend(this.options.showEffectOptions,this.options.effectOptions);if(this.options.showEffect==
Element.Appear)this.options.showEffectOptions.to=this.options.opacity}if(Window.hasEffectLib){if(this.options.showEffect==Effect.Appear)this.options.showEffectOptions.to=this.options.opacity;if(this.options.hideEffect==Effect.Fade)this.options.hideEffectOptions.from=this.options.opacity}if(this.options.hideEffect==Element.hide)this.options.hideEffect=function(){Element.hide(this.element);this.options.destroyOnClose&&this.destroy()}.bind(this);if(this.options.parent!=document.body)this.options.parent=
$(this.options.parent);this.element=this._createWindow(e);this.element.win=this;this.eventMouseDown=this._initDrag.bindAsEventListener(this);this.eventMouseUp=this._endDrag.bindAsEventListener(this);this.eventMouseMove=this._updateDrag.bindAsEventListener(this);this.eventOnLoad=this._getWindowBorderSize.bindAsEventListener(this);this.eventMouseDownContent=this.toFront.bindAsEventListener(this);this.eventResize=this._recenter.bindAsEventListener(this);this.topbar=$(this.element.id+"_top");this.bottombar=
$(this.element.id+"_bottom");this.content=$(this.element.id+"_content");Event.observe(this.topbar,"mousedown",this.eventMouseDown);Event.observe(this.bottombar,"mousedown",this.eventMouseDown);Event.observe(this.content,"mousedown",this.eventMouseDownContent);Event.observe(window,"load",this.eventOnLoad);Event.observe(window,"resize",this.eventResize);Event.observe(window,"scroll",this.eventResize);Event.observe(this.options.parent,"scroll",this.eventResize);if(this.options.draggable){var b=this;
[this.topbar,this.topbar.up().previous(),this.topbar.up().next()].each(function(c){c.observe("mousedown",b.eventMouseDown);c.addClassName("top_draggable")});[this.bottombar.up(),this.bottombar.up().previous(),this.bottombar.up().next()].each(function(c){c.observe("mousedown",b.eventMouseDown);c.addClassName("bottom_draggable")})}if(this.options.resizable){this.sizer=$(this.element.id+"_sizer");Event.observe(this.sizer,"mousedown",this.eventMouseDown)}this.useTop=this.useLeft=null;if(typeof this.options.left!=
"undefined"){this.element.setStyle({left:parseFloat(this.options.left)+"px"});this.useLeft=true}else{this.element.setStyle({right:parseFloat(this.options.right)+"px"});this.useLeft=false}if(typeof this.options.top!="undefined"){this.element.setStyle({top:parseFloat(this.options.top)+"px"});this.useTop=true}else{this.element.setStyle({bottom:parseFloat(this.options.bottom)+"px"});this.useTop=false}this.storedLocation=null;this.setOpacity(this.options.opacity);this.options.zIndex&&this.setZIndex(this.options.zIndex);
this.options.destroyOnClose&&this.setDestroyOnClose(true);this._getWindowBorderSize();this.width=this.options.width;this.height=this.options.height;this.constraint=this.visible=false;this.constraintPad={top:0,left:0,bottom:0,right:0};this.width&&this.height&&this.setSize(this.options.width,this.options.height);this.setTitle(this.options.title);Windows.register(this)},destroy:function(){this._notify("onDestroy");Event.stopObserving(this.topbar,"mousedown",this.eventMouseDown);Event.stopObserving(this.bottombar,
"mousedown",this.eventMouseDown);Event.stopObserving(this.content,"mousedown",this.eventMouseDownContent);Event.stopObserving(window,"load",this.eventOnLoad);Event.stopObserving(window,"resize",this.eventResize);Event.stopObserving(window,"scroll",this.eventResize);Event.stopObserving(this.content,"load",this.options.onload);if(this._oldParent){for(var e=this.getContent(),d=null,b=0;b<e.childNodes.length;b++){d=e.childNodes[b];if(d.nodeType==1)break;d=null}d&&this._oldParent.appendChild(d);this._oldParent=
null}this.sizer&&Event.stopObserving(this.sizer,"mousedown",this.eventMouseDown);if(this.options.url)this.content.src=null;this.iefix&&Element.remove(this.iefix);Element.remove(this.element);Windows.unregister(this)},setCloseCallback:function(e){this.options.closeCallback=e},getContent:function(){return this.content},setContent:function(e,d,b){var c=$(e);if(null==c)throw"Unable to find element '"+e+"' in DOM";this._oldParent=c.parentNode;var f=e=null;if(d)e=Element.getDimensions(c);if(b)f=Position.cumulativeOffset(c);
var g=this.getContent();this.setHTMLContent("");g=this.getContent();g.appendChild(c);c.show();d&&this.setSize(e.width,e.height);b&&this.setLocation(f[1]-this.heightN,f[0]-this.widthW)},setHTMLContent:function(e){if(this.options.url){this.content.src=null;this.options.url=null;var d='<div id="'+this.getId()+'_content" class="'+this.options.className+'_content"> </div>';$(this.getId()+"_table_content").innerHTML=d;this.content=$(this.element.id+"_content")}this.getContent().innerHTML=e},setAjaxContent:function(e,
d,b,c){this.showFunction=b?"showCenter":"show";this.showModal=c||false;d=d||{};this.setHTMLContent("");this.onComplete=d.onComplete;if(!this._onCompleteHandler)this._onCompleteHandler=this._setAjaxContent.bind(this);d.onComplete=this._onCompleteHandler;new Ajax.Request(e,d);d.onComplete=this.onComplete},_setAjaxContent:function(e){Element.update(this.getContent(),e.responseText);this.onComplete&&this.onComplete(e);this.onComplete=null;this[this.showFunction](this.showModal)},setURL:function(e){if(this.options.url)this.content.src=
null;this.options.url=e;e="<iframe frameborder='0' name='"+this.getId()+"_content'  id='"+this.getId()+"_content' src='"+e+"' width='"+this.width+"' height='"+this.height+"'> </iframe>";$(this.getId()+"_table_content").innerHTML=e;this.content=$(this.element.id+"_content")},getURL:function(){return this.options.url?this.options.url:null},refresh:function(){if(this.options.url)$(this.element.getAttribute("id")+"_content").src=this.options.url},setCookie:function(e,d,b,c,f){e=e||this.element.id;this.cookie=
[e,d,b,c,f];if(e=WindowUtilities.getCookie(e)){var g=e.split(",");e=g[0].split(":");d=g[1].split(":");b=parseFloat(g[2]);c=parseFloat(g[3]);f=g[4];g=g[5];this.setSize(b,c);if(f=="true")this.doMinimize=true;else if(g=="true")this.doMaximize=true;this.useLeft=e[0]=="l";this.useTop=d[0]=="t";this.element.setStyle(this.useLeft?{left:e[1]}:{right:e[1]});this.element.setStyle(this.useTop?{top:d[1]}:{bottom:d[1]})}},getId:function(){return this.element.id},setDestroyOnClose:function(){this.options.destroyOnClose=
true},setConstraint:function(e,d){this.constraint=e;this.constraintPad=Object.extend(this.constraintPad,d||{});this.useTop&&this.useLeft&&this.setLocation(parseFloat(this.element.style.top),parseFloat(this.element.style.left))},_initDrag:function(e){if(!(Event.element(e)==this.sizer&&this.isMinimized()))if(!(Event.element(e)!=this.sizer&&this.isMaximized())){Prototype.Browser.IE&&this.heightN==0&&this._getWindowBorderSize();this.pointer=[this._round(Event.pointerX(e),this.options.gridX),this._round(Event.pointerY(e),
this.options.gridY)];this.currentDrag=this.options.wiredDrag?this._createWiredElement():this.element;if(Event.element(e)==this.sizer){this.doResize=true;this.widthOrg=this.width;this.heightOrg=this.height;this.bottomOrg=parseFloat(this.element.getStyle("bottom"));this.rightOrg=parseFloat(this.element.getStyle("right"));this._notify("onStartResize")}else{this.doResize=false;var d=$(this.getId()+"_close");if(d&&Position.within(d,this.pointer[0],this.pointer[1])){this.currentDrag=null;return}this.toFront();
if(!this.options.draggable)return;this._notify("onStartMove")}Event.observe(document,"mouseup",this.eventMouseUp,false);Event.observe(document,"mousemove",this.eventMouseMove,false);WindowUtilities.disableScreen("__invisible__","__invisible__",this.overlayOpacity);document.body.ondrag=function(){return false};document.body.onselectstart=function(){return false};this.currentDrag.show();Event.stop(e)}},_round:function(e,d){return d==1?e:Math.floor(e/d)*d},_updateDrag:function(e){var d=[this._round(Event.pointerX(e),
this.options.gridX),this._round(Event.pointerY(e),this.options.gridY)],b=d[0]-this.pointer[0],c=d[1]-this.pointer[1];if(this.doResize){d=this.widthOrg+b;var f=this.heightOrg+c;b=this.width-this.widthOrg;c=this.height-this.heightOrg;if(this.useLeft)d=this._updateWidthConstraint(d);else this.currentDrag.setStyle({right:this.rightOrg-b+"px"});if(this.useTop)f=this._updateHeightConstraint(f);else this.currentDrag.setStyle({bottom:this.bottomOrg-c+"px"});this.setSize(d,f);this._notify("onResize")}else{this.pointer=
d;if(this.useLeft){b=parseFloat(this.currentDrag.getStyle("left"))+b;d=this._updateLeftConstraint(b);this.pointer[0]+=d-b;this.currentDrag.setStyle({left:d+"px"})}else this.currentDrag.setStyle({right:parseFloat(this.currentDrag.getStyle("right"))-b+"px"});if(this.useTop){c=parseFloat(this.currentDrag.getStyle("top"))+c;b=this._updateTopConstraint(c);this.pointer[1]+=b-c;this.currentDrag.setStyle({top:b+"px"})}else this.currentDrag.setStyle({bottom:parseFloat(this.currentDrag.getStyle("bottom"))-
c+"px"});this._notify("onMove")}if(this.iefix){this._fixIEOverlapping();this.iefix=null}this._removeStoreLocation();Event.stop(e)},_endDrag:function(e){WindowUtilities.enableScreen("__invisible__");this.doResize?this._notify("onEndResize"):this._notify("onEndMove");Event.stopObserving(document,"mouseup",this.eventMouseUp,false);Event.stopObserving(document,"mousemove",this.eventMouseMove,false);Event.stop(e);this._hideWiredElement();this._saveCookie();document.body.ondrag=null;document.body.onselectstart=
null},_updateLeftConstraint:function(e){if(this.constraint&&this.useLeft&&this.useTop){var d=this.options.parent==document.body?WindowUtilities.getPageSize().windowWidth:this.options.parent.getDimensions().width;if(e<this.constraintPad.left)e=this.constraintPad.left;if(e+this.width+this.widthE+this.widthW>d-this.constraintPad.right)e=d-this.constraintPad.right-this.width-this.widthE-this.widthW}return e},_updateTopConstraint:function(e){if(this.constraint&&this.useLeft&&this.useTop){var d=this.options.parent==
document.body?WindowUtilities.getPageSize().windowHeight:this.options.parent.getDimensions().height,b=this.height+this.heightN+this.heightS;if(e<this.constraintPad.top)e=this.constraintPad.top;if(e+b>d-this.constraintPad.bottom)e=d-this.constraintPad.bottom-b}return e},_updateWidthConstraint:function(e){if(this.constraint&&this.useLeft&&this.useTop){var d=this.options.parent==document.body?WindowUtilities.getPageSize().windowWidth:this.options.parent.getDimensions().width,b=parseFloat(this.element.getStyle("left"));
if(b+e+this.widthE+this.widthW>d-this.constraintPad.right)e=d-this.constraintPad.right-b-this.widthE-this.widthW}return e},_updateHeightConstraint:function(e){if(this.constraint&&this.useLeft&&this.useTop){var d=this.options.parent==document.body?WindowUtilities.getPageSize().windowHeight:this.options.parent.getDimensions().height,b=parseFloat(this.element.getStyle("top"));if(b+e+this.heightN+this.heightS>d-this.constraintPad.bottom)e=d-this.constraintPad.bottom-b-this.heightN-this.heightS}return e},
_createWindow:function(e){var d=this.options.className,b=document.createElement("div");b.setAttribute("id",e);b.className="dialog";b.innerHTML=(this.options.closable?"<div class='"+d+"_close' id='"+e+"_close' onclick='Windows.close(\""+e+"\", event)'> </div>":"")+(this.options.minimizable?"<div class='"+d+"_minimize' id='"+e+"_minimize' onclick='Windows.minimize(\""+e+"\", event)'> </div>":"")+(this.options.maximizable?"<div class='"+d+"_maximize' id='"+e+"_maximize' onclick='Windows.maximize(\""+
e+"\", event)'> </div>":"")+"      <table id='"+e+"_row1' class=\"top table_window\">        <tr>          <td class='"+d+"_nw'></td>          <td class='"+d+"_n'><div id='"+e+"_top' class='"+d+"_title title_window'>"+this.options.title+"</div></td>          <td class='"+d+"_ne'></td>        </tr>      </table>      <table id='"+e+"_row2' class=\"mid table_window\">        <tr>          <td class='"+d+"_w'></td>            <td id='"+e+"_table_content' class='"+d+"_content' valign='top'>"+(this.options.url?
'<iframe frameborder="0" name="'+e+'_content"  id="'+e+'_content" src="'+this.options.url+'"> </iframe>':'<div id="'+e+'_content" class="'+d+'_content"> </div>')+"</td>          <td class='"+d+"_e'></td>        </tr>      </table>        <table id='"+e+"_row3' class=\"bot table_window\">        <tr>          <td class='"+d+"_sw'></td>            <td class='"+d+"_s'><div id='"+e+"_bottom' class='status_bar'><span style='float:left; width:1px; height:1px'></span></div></td>            <td "+(this.options.resizable?
"class='"+d+"_sizer' id='"+e+"_sizer'":"class='"+d+"_se'")+"></td>        </tr>      </table>    ";Element.hide(b);this.options.parent.insertBefore(b,this.options.parent.firstChild);Event.observe($(e+"_content"),"load",this.options.onload);return b},changeClassName:function(e){var d=this.options.className,b=this.getId();$A(["_close","_minimize","_maximize","_sizer","_content"]).each(function(c){this._toggleClassName($(b+c),d+c,e+c)}.bind(this));this._toggleClassName($(b+"_top"),d+"_title",e+"_title");
$$("#"+b+" td").each(function(c){c.className=c.className.sub(d,e)});this.options.className=e},_toggleClassName:function(e,d,b){if(e){e.removeClassName(d);e.addClassName(b)}},setLocation:function(e,d){e=this._updateTopConstraint(e);d=this._updateLeftConstraint(d);var b=this.currentDrag||this.element;if(b){b.setStyle({top:e+"px"});b.setStyle({left:d+"px"});this.useTop=this.useLeft=true}},getLocation:function(){var e={};e=this.useTop?Object.extend(e,{top:this.element.getStyle("top")}):Object.extend(e,
{bottom:this.element.getStyle("bottom")});return e=this.useLeft?Object.extend(e,{left:this.element.getStyle("left")}):Object.extend(e,{right:this.element.getStyle("right")})},getSize:function(){return{width:this.width,height:this.height}},setSize:function(e,d,b){e=parseFloat(e);d=parseFloat(d);if(!this.minimized&&e<this.options.minWidth)e=this.options.minWidth;if(!this.minimized&&d<this.options.minHeight)d=this.options.minHeight;if(this.options.maxHeight&&d>this.options.maxHeight)d=this.options.maxHeight;
if(this.options.maxWidth&&e>this.options.maxWidth)e=this.options.maxWidth;if(this.useTop&&this.useLeft&&Window.hasEffectLib&&Effect.ResizeWindow&&b)new Effect.ResizeWindow(this,null,null,e,d,{duration:Window.resizeEffectDuration});else{this.width=e;this.height=d;b=this.currentDrag?this.currentDrag:this.element;b.setStyle({width:e+this.widthW+this.widthE+"px"});b.setStyle({height:d+this.heightN+this.heightS+"px"});if(!this.currentDrag||this.currentDrag==this.element){b=$(this.element.id+"_content");
b.setStyle({height:d+"px"});b.setStyle({width:e+"px"})}}},updateHeight:function(){this.setSize(this.width,this.content.scrollHeight,true)},updateWidth:function(){this.setSize(this.content.scrollWidth,this.height,true)},toFront:function(){this.element.style.zIndex<Windows.maxZIndex&&this.setZIndex(Windows.maxZIndex+1);this.iefix&&this._fixIEOverlapping()},getBounds:function(e){if(!this.width||!this.height||!this.visible)this.computeBounds();var d=this.width,b=this.height;if(!e){d+=this.widthW+this.widthE;
b+=this.heightN+this.heightS}return Object.extend(this.getLocation(),{width:d+"px",height:b+"px"})},computeBounds:function(){if(!this.width||!this.height){var e=WindowUtilities._computeSize(this.content.innerHTML,this.content.id,this.width,this.height,0,this.options.className);if(this.height)this.width=e+5;else this.height=e+5}this.setSize(this.width,this.height);this.centered&&this._center(this.centerTop,this.centerLeft)},show:function(e){this.visible=true;if(e){if(typeof this.overlayOpacity=="undefined"){var d=
this;setTimeout(function(){d.show(e)},10);return}Windows.addModalWindow(this);this.modal=true;this.setZIndex(Windows.maxZIndex+1);Windows.unsetOverflow(this)}else this.element.style.zIndex||this.setZIndex(Windows.maxZIndex+1);this.oldStyle&&this.getContent().setStyle({overflow:this.oldStyle});this.computeBounds();this._notify("onBeforeShow");this.options.showEffect!=Element.show&&this.options.showEffectOptions?this.options.showEffect(this.element,this.options.showEffectOptions):this.options.showEffect(this.element);
this._checkIEOverlapping();WindowUtilities.focusedWindow=this;this._notify("onShow")},showCenter:function(e,d,b){this.centered=true;this.centerTop=d;this.centerLeft=b;this.show(e)},isVisible:function(){return this.visible},_center:function(e,d){var b=WindowUtilities.getWindowScroll(this.options.parent),c=WindowUtilities.getPageSize(this.options.parent);if(typeof e=="undefined")e=(c.windowHeight-(this.height+this.heightN+this.heightS))/2;e+=b.top;if(typeof d=="undefined")d=(c.windowWidth-(this.width+
this.widthW+this.widthE))/2;d+=b.left;this.setLocation(e,d)},_recenter:function(){if(this.centered){var e=WindowUtilities.getPageSize(this.options.parent),d=WindowUtilities.getWindowScroll(this.options.parent);if(!(this.pageSize&&this.pageSize.windowWidth==e.windowWidth&&this.pageSize.windowHeight==e.windowHeight&&this.windowScroll.left==d.left&&this.windowScroll.top==d.top)){this.pageSize=e;this.windowScroll=d;$("overlay_modal")&&$("overlay_modal").setStyle({height:e.pageHeight+"px"});this.options.recenterAuto&&
this._center(this.centerTop,this.centerLeft)}}},hide:function(){this.visible=false;if(this.modal){Windows.removeModalWindow(this);Windows.resetOverflow()}this.oldStyle=this.getContent().getStyle("overflow")||"auto";this.getContent().setStyle({overflow:"hidden"});this.options.hideEffect(this.element,this.options.hideEffectOptions);this.iefix&&this.iefix.hide();this.doNotNotifyHide||this._notify("onHide")},close:function(){if(this.visible)if(!(this.options.closeCallback&&!this.options.closeCallback(this))){if(this.options.destroyOnClose){var e=
this.destroy.bind(this);if(this.options.hideEffectOptions.afterFinish){var d=this.options.hideEffectOptions.afterFinish;this.options.hideEffectOptions.afterFinish=function(){d();e()}}else this.options.hideEffectOptions.afterFinish=function(){e()}}Windows.updateFocusedWindow();this.doNotNotifyHide=true;this.hide();this.doNotNotifyHide=false;this._notify("onClose")}},minimize:function(){if(!this.resizing){var e=$(this.getId()+"_row2");if(this.minimized){this.minimized=false;d=this.r2Height;this.r2Height=
null;if(this.useLeft&&this.useTop&&Window.hasEffectLib&&Effect.ResizeWindow)new Effect.ResizeWindow(this,null,null,null,this.height+d,{duration:Window.resizeEffectDuration});else{b=this.element.getHeight()+d;this.height+=d;this.element.setStyle({height:b+"px"});e.show()}if(!this.useTop){e=parseFloat(this.element.getStyle("bottom"));this.element.setStyle({bottom:e-d+"px"})}this.toFront()}else{this.minimized=true;var d=e.getDimensions().height;this.r2Height=d;var b=this.element.getHeight()-d;if(this.useLeft&&
this.useTop&&Window.hasEffectLib&&Effect.ResizeWindow)new Effect.ResizeWindow(this,null,null,null,this.height-d,{duration:Window.resizeEffectDuration});else{this.height-=d;this.element.setStyle({height:b+"px"});e.hide()}if(!this.useTop){e=parseFloat(this.element.getStyle("bottom"));this.element.setStyle({bottom:e+d+"px"})}}this._notify("onMinimize");this._saveCookie()}},maximize:function(){if(!(this.isMinimized()||this.resizing)){Prototype.Browser.IE&&this.heightN==0&&this._getWindowBorderSize();
if(this.storedLocation!=null){this._restoreLocation();this.iefix&&this.iefix.hide()}else{this._storeLocation();Windows.unsetOverflow(this);var e=WindowUtilities.getWindowScroll(this.options.parent),d=WindowUtilities.getPageSize(this.options.parent),b=e.left;e=e.top;if(this.options.parent!=document.body){b=this.options.parent.getDimensions();d.windowWidth=b.width;d.windowHeight=b.height;b=e=0}if(this.constraint){d.windowWidth-=Math.max(0,this.constraintPad.left)+Math.max(0,this.constraintPad.right);
d.windowHeight-=Math.max(0,this.constraintPad.top)+Math.max(0,this.constraintPad.bottom);b+=Math.max(0,this.constraintPad.left);e+=Math.max(0,this.constraintPad.top)}var c=d.windowWidth-this.widthW-this.widthE;d=d.windowHeight-this.heightN-this.heightS;if(this.useLeft&&this.useTop&&Window.hasEffectLib&&Effect.ResizeWindow)new Effect.ResizeWindow(this,e,b,c,d,{duration:Window.resizeEffectDuration});else{this.setSize(c,d);this.element.setStyle(this.useLeft?{left:b}:{right:b});this.element.setStyle(this.useTop?
{top:e}:{bottom:e})}this.toFront();this.iefix&&this._fixIEOverlapping()}this._notify("onMaximize");this._saveCookie()}},isMinimized:function(){return this.minimized},isMaximized:function(){return this.storedLocation!=null},setOpacity:function(e){Element.setOpacity&&Element.setOpacity(this.element,e)},setZIndex:function(e){this.element.setStyle({zIndex:e});Windows.updateZindex(e,this)},setTitle:function(e){if(!e||e=="")e="&nbsp;";Element.update(this.element.id+"_top",e)},getTitle:function(){return $(this.element.id+
"_top").innerHTML},setStatusBar:function(e){$(this.getId()+"_bottom");if(typeof e=="object")this.bottombar.firstChild?this.bottombar.replaceChild(e,this.bottombar.firstChild):this.bottombar.appendChild(e);else this.bottombar.innerHTML=e},_checkIEOverlapping:function(){if(!this.iefix&&navigator.appVersion.indexOf("MSIE")>0&&navigator.userAgent.indexOf("Opera")<0&&this.element.getStyle("position")=="absolute"){new Insertion.After(this.element.id,'<iframe id="'+this.element.id+'_iefix" style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
this.iefix=$(this.element.id+"_iefix")}this.iefix&&setTimeout(this._fixIEOverlapping.bind(this),50)},_fixIEOverlapping:function(){if(this.element&&this.iefix){Position.clone(this.element,this.iefix);this.iefix.style.zIndex=this.element.style.zIndex-1;this.iefix.show()}},_getWindowBorderSize:function(){var e=this._createHiddenDiv(this.options.className+"_n");this.heightN=Element.getDimensions(e).height;e.parentNode.removeChild(e);e=this._createHiddenDiv(this.options.className+"_s");this.heightS=Element.getDimensions(e).height;
e.parentNode.removeChild(e);e=this._createHiddenDiv(this.options.className+"_e");this.widthE=Element.getDimensions(e).width;e.parentNode.removeChild(e);e=this._createHiddenDiv(this.options.className+"_w");this.widthW=Element.getDimensions(e).width;e.parentNode.removeChild(e);e=document.createElement("div");e.className="overlay_"+this.options.className;document.body.appendChild(e);var d=this;setTimeout(function(){d.overlayOpacity=$(e).getStyle("opacity");e.parentNode.removeChild(e)},10);if(Prototype.Browser.IE){this.heightS=
$(this.getId()+"_row3").getDimensions().height;this.heightN=$(this.getId()+"_row1").getDimensions().height}Prototype.Browser.WebKit&&Prototype.Browser.WebKitVersion<420&&this.setSize(this.width,this.height);this.doMaximize&&this.maximize();this.doMinimize&&this.minimize()},_createHiddenDiv:function(e){var d=document.body,b=document.createElement("div");b.setAttribute("id",this.element.id+"_tmp");b.className=e;b.style.display="none";b.innerHTML="";d.insertBefore(b,d.firstChild);return b},_storeLocation:function(){if(this.storedLocation==
null)this.storedLocation={useTop:this.useTop,useLeft:this.useLeft,top:this.element.getStyle("top"),bottom:this.element.getStyle("bottom"),left:this.element.getStyle("left"),right:this.element.getStyle("right"),width:this.width,height:this.height}},_restoreLocation:function(){if(this.storedLocation!=null){this.useLeft=this.storedLocation.useLeft;this.useTop=this.storedLocation.useTop;if(this.useLeft&&this.useTop&&Window.hasEffectLib&&Effect.ResizeWindow)new Effect.ResizeWindow(this,this.storedLocation.top,
this.storedLocation.left,this.storedLocation.width,this.storedLocation.height,{duration:Window.resizeEffectDuration});else{this.element.setStyle(this.useLeft?{left:this.storedLocation.left}:{right:this.storedLocation.right});this.element.setStyle(this.useTop?{top:this.storedLocation.top}:{bottom:this.storedLocation.bottom});this.setSize(this.storedLocation.width,this.storedLocation.height)}Windows.resetOverflow();this._removeStoreLocation()}},_removeStoreLocation:function(){this.storedLocation=null},
_saveCookie:function(){if(this.cookie){var e="";e+=this.useLeft?"l:"+(this.storedLocation?this.storedLocation.left:this.element.getStyle("left")):"r:"+(this.storedLocation?this.storedLocation.right:this.element.getStyle("right"));e+=this.useTop?",t:"+(this.storedLocation?this.storedLocation.top:this.element.getStyle("top")):",b:"+(this.storedLocation?this.storedLocation.bottom:this.element.getStyle("bottom"));e+=","+(this.storedLocation?this.storedLocation.width:this.width);e+=","+(this.storedLocation?
this.storedLocation.height:this.height);e+=","+this.isMinimized();e+=","+this.isMaximized();WindowUtilities.setCookie(e,this.cookie)}},_createWiredElement:function(){if(!this.wiredElement){Prototype.Browser.IE&&this._getWindowBorderSize();var e=document.createElement("div");e.className="wired_frame "+this.options.className+"_wired_frame";e.style.position="absolute";this.options.parent.insertBefore(e,this.options.parent.firstChild);this.wiredElement=$(e)}this.useLeft?this.wiredElement.setStyle({left:this.element.getStyle("left")}):
this.wiredElement.setStyle({right:this.element.getStyle("right")});this.useTop?this.wiredElement.setStyle({top:this.element.getStyle("top")}):this.wiredElement.setStyle({bottom:this.element.getStyle("bottom")});e=this.element.getDimensions();this.wiredElement.setStyle({width:e.width+"px",height:e.height+"px"});this.wiredElement.setStyle({zIndex:Windows.maxZIndex+30});return this.wiredElement},_hideWiredElement:function(){if(this.wiredElement&&this.currentDrag)if(this.currentDrag==this.element)this.currentDrag=
null;else{this.useLeft?this.element.setStyle({left:this.currentDrag.getStyle("left")}):this.element.setStyle({right:this.currentDrag.getStyle("right")});this.useTop?this.element.setStyle({top:this.currentDrag.getStyle("top")}):this.element.setStyle({bottom:this.currentDrag.getStyle("bottom")});this.currentDrag.hide();this.currentDrag=null;this.doResize&&this.setSize(this.width,this.height)}},_notify:function(e){this.options[e]?this.options[e](this):Windows.notify(e,this)}};
var Windows={windows:[],modalWindows:[],observers:[],focusedWindow:null,maxZIndex:2E5,overlayShowEffectOptions:{duration:0.5},overlayHideEffectOptions:{duration:0.5},addObserver:function(e){this.removeObserver(e);this.observers.push(e)},removeObserver:function(e){this.observers=this.observers.reject(function(d){return d==e})},notify:function(e,d){this.observers.each(function(b){b[e]&&b[e](e,d)})},getWindow:function(e){return this.windows.detect(function(d){return d.getId()==e})},getFocusedWindow:function(){return this.focusedWindow},
updateFocusedWindow:function(){this.focusedWindow=this.windows.length>=2?this.windows[this.windows.length-2]:null},register:function(e){this.windows.push(e)},addModalWindow:function(e){if(this.modalWindows.length==0)WindowUtilities.disableScreen(e.options.className,"overlay_modal",e.overlayOpacity,e.getId(),e.options.parent);else{if(Window.keepMultiModalWindow){$("overlay_modal").style.zIndex=Windows.maxZIndex+1;Windows.maxZIndex+=1;WindowUtilities._hideSelect(this.modalWindows.last().getId())}else this.modalWindows.last().element.hide();
WindowUtilities._showSelect(e.getId())}this.modalWindows.push(e)},removeModalWindow:function(){this.modalWindows.pop();if(this.modalWindows.length==0)WindowUtilities.enableScreen();else if(Window.keepMultiModalWindow){this.modalWindows.last().toFront();WindowUtilities._showSelect(this.modalWindows.last().getId())}else this.modalWindows.last().element.show()},register:function(e){this.windows.push(e)},unregister:function(e){this.windows=this.windows.reject(function(d){return d==e})},closeAll:function(){this.windows.each(function(e){Windows.close(e.getId())})},
closeAllModalWindows:function(){WindowUtilities.enableScreen();this.modalWindows.each(function(e){e&&e.close()})},minimize:function(e,d){(e=this.getWindow(e))&&e.visible&&e.minimize();Event.stop(d)},maximize:function(e,d){(e=this.getWindow(e))&&e.visible&&e.maximize();Event.stop(d)},close:function(e,d){(e=this.getWindow(e))&&e.close();d&&Event.stop(d)},blur:function(e){if(e=this.getWindow(e)){e.options.blurClassName&&e.changeClassName(e.options.blurClassName);if(this.focusedWindow==e)this.focusedWindow=
null;e._notify("onBlur")}},focus:function(e){if(e=this.getWindow(e)){this.focusedWindow&&this.blur(this.focusedWindow.getId());e.options.focusClassName&&e.changeClassName(e.options.focusClassName);this.focusedWindow=e;e._notify("onFocus")}},unsetOverflow:function(e){this.windows.each(function(d){d.oldOverflow=d.getContent().getStyle("overflow")||"auto";d.getContent().setStyle({overflow:"hidden"})});e&&e.oldOverflow&&e.getContent().setStyle({overflow:e.oldOverflow})},resetOverflow:function(){this.windows.each(function(e){e.oldOverflow&&
e.getContent().setStyle({overflow:e.oldOverflow})})},updateZindex:function(e,d){if(e>this.maxZIndex){this.maxZIndex=e;this.focusedWindow&&this.blur(this.focusedWindow.getId())}(this.focusedWindow=d)&&this.focus(this.focusedWindow.getId())}},Dialog={dialogId:null,onCompleteFunc:null,callFunc:null,parameters:null,confirm:function(e,d){if(e&&typeof e!="string")Dialog._runAjaxRequest(e,d,Dialog.confirm);else{e=e||"";d=d||{};var b=d.okLabel?d.okLabel:"Ok",c=d.cancelLabel?d.cancelLabel:"Cancel";d=Object.extend(d,
d.windowParameters||{});d.windowParameters=d.windowParameters||{};d.className=d.className||"alert";e="      <div class='"+d.className+"_message'>"+e+"</div>        <div class='"+d.className+"_buttons'>          <input type='button' value='"+b+"' onclick='Dialog.okCallback()' "+("class ='"+(d.buttonClass?d.buttonClass+" ":"")+" ok_button'")+"/>          <input type='button' value='"+c+"' onclick='Dialog.cancelCallback()' "+("class ='"+(d.buttonClass?d.buttonClass+" ":"")+" cancel_button'")+"/>        </div>    ";
return this._openDialog(e,d)}},alert:function(e,d){if(e&&typeof e!="string")Dialog._runAjaxRequest(e,d,Dialog.alert);else{e=e||"";d=d||{};var b=d.okLabel?d.okLabel:"Ok";d=Object.extend(d,d.windowParameters||{});d.windowParameters=d.windowParameters||{};d.className=d.className||"alert";e="      <div class='"+d.className+"_message'>"+e+"</div>        <div class='"+d.className+"_buttons'>          <input type='button' value='"+b+"' onclick='Dialog.okCallback()' "+("class ='"+(d.buttonClass?d.buttonClass+
" ":"")+" ok_button'")+"/>        </div>";return this._openDialog(e,d)}},info:function(e,d){if(e&&typeof e!="string")Dialog._runAjaxRequest(e,d,Dialog.info);else{e=e||"";d=d||{};d=Object.extend(d,d.windowParameters||{});d.windowParameters=d.windowParameters||{};d.className=d.className||"alert";e="<div id='modal_dialog_message' class='"+d.className+"_message'>"+e+"</div>";if(d.showProgress)e+="<div id='modal_dialog_progress' class='"+d.className+"_progress'>  </div>";d.ok=null;d.cancel=null;return this._openDialog(e,
d)}},setInfoMessage:function(e){$("modal_dialog_message").update(e)},closeInfo:function(){Windows.close(this.dialogId)},_openDialog:function(e,d){var b=d.className;if(!d.height&&!d.width)d.width=WindowUtilities.getPageSize(d.options.parent||document.body).pageWidth/2;if(d.id)this.dialogId=d.id;else{this.dialogId="modal_dialog_"+(new Date).getTime();d.id=this.dialogId}if(!d.height||!d.width){b=WindowUtilities._computeSize(e,this.dialogId,d.width,d.height,5,b);if(d.height)d.width=b+5;else d.height=
b+5}d.effectOptions=d.effectOptions;d.resizable=d.resizable||false;d.minimizable=d.minimizable||false;d.maximizable=d.maximizable||false;d.draggable=d.draggable||false;d.closable=d.closable||false;b=new Window(d);b.getContent().innerHTML=e;b.showCenter(true,d.top,d.left);b.setDestroyOnClose();b.cancelCallback=d.onCancel||d.cancel;b.okCallback=d.onOk||d.ok;return b},_getAjaxContent:function(e){Dialog.callFunc(e.responseText,Dialog.parameters)},_runAjaxRequest:function(e,d,b){if(e.options==null)e.options=
{};Dialog.onCompleteFunc=e.options.onComplete;Dialog.parameters=d;Dialog.callFunc=b;e.options.onComplete=Dialog._getAjaxContent;new Ajax.Request(e.url,e.options)},okCallback:function(){var e=Windows.focusedWindow;if(!e.okCallback||e.okCallback(e)){$$("#"+e.getId()+" input").each(function(d){d.onclick=null});e.close()}},cancelCallback:function(){var e=Windows.focusedWindow;$$("#"+e.getId()+" input").each(function(d){d.onclick=null});e.close();e.cancelCallback&&e.cancelCallback(e)}};
if(Prototype.Browser.WebKit){var array=navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));Prototype.Browser.WebKitVersion=parseFloat(array[1])}
var WindowUtilities={getWindowScroll:function(e){var d,b,c;e=e||document.body;if(e!=document.body){d=e.scrollTop;b=e.scrollLeft;c=e.scrollWidth;e=e.scrollHeight}else{e=window;with(e.document){if(e.document.documentElement&&documentElement.scrollTop){d=documentElement.scrollTop;b=documentElement.scrollLeft}else if(e.document.body){d=body.scrollTop;b=body.scrollLeft}if(e.innerWidth){c=e.innerWidth;e=e.innerHeight}else if(e.document.documentElement&&documentElement.clientWidth){c=documentElement.clientWidth;
e=documentElement.clientHeight}else{c=body.offsetWidth;e=body.offsetHeight}}}return{top:d,left:b,width:c,height:e}},getPageSize:function(e){e=e||document.body;var d,b,c;if(e!=document.body){d=e.getWidth();b=e.getHeight();c=e.scrollWidth;e=e.scrollHeight}else{if(window.innerHeight&&window.scrollMaxY){c=document.body.scrollWidth;e=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){c=document.body.scrollWidth;e=document.body.scrollHeight}else{c=document.body.offsetWidth;
e=document.body.offsetHeight}if(self.innerHeight){d=self.innerWidth;b=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){d=document.documentElement.clientWidth;b=document.documentElement.clientHeight}else if(document.body){d=document.body.clientWidth;b=document.body.clientHeight}e=e<b?b:e;c=c<d?d:c}return{pageWidth:c,pageHeight:e,windowWidth:d,windowHeight:b}},disableScreen:function(e,d,b,c,f){WindowUtilities.initLightbox(d,e,function(){this._disableScreen(e,
d,b,c)}.bind(this),f||document.body)},_disableScreen:function(e,d,b,c){e=$(d);var f=WindowUtilities.getPageSize(e.parentNode);if(c&&Prototype.Browser.IE){WindowUtilities._hideSelect();WindowUtilities._showSelect(c)}e.style.height=f.pageHeight+"px";e.style.display="none";if(d=="overlay_modal"&&Window.hasEffectLib&&Windows.overlayShowEffectOptions){e.overlayOpacity=b;new Effect.Appear(e,Object.extend({from:0,to:b},Windows.overlayShowEffectOptions))}else e.style.display="block"},enableScreen:function(e){e=
e||"overlay_modal";var d=$(e);if(d){if(e=="overlay_modal"&&Window.hasEffectLib&&Windows.overlayHideEffectOptions)new Effect.Fade(d,Object.extend({from:d.overlayOpacity,to:0},Windows.overlayHideEffectOptions));else{d.style.display="none";d.parentNode.removeChild(d)}e!="__invisible__"&&WindowUtilities._showSelect()}},_hideSelect:function(e){if(Prototype.Browser.IE){e=e==null?"":"#"+e+" ";$$(e+"select").each(function(d){if(!WindowUtilities.isDefined(d.oldVisibility)){d.oldVisibility=d.style.visibility?
d.style.visibility:"visible";d.style.visibility="hidden"}})}},_showSelect:function(e){if(Prototype.Browser.IE){e=e==null?"":"#"+e+" ";$$(e+"select").each(function(d){if(WindowUtilities.isDefined(d.oldVisibility)){try{d.style.visibility=d.oldVisibility}catch(b){d.style.visibility="visible"}d.oldVisibility=null}else if(d.style.visibility)d.style.visibility="visible"})}},isDefined:function(e){return typeof e!="undefined"&&e!=null},initLightbox:function(e,d,b,c){if($(e)){Element.setStyle(e,{zIndex:Windows.maxZIndex+
1});Windows.maxZIndex++;b()}else{var f=document.createElement("div");f.setAttribute("id",e);f.className="overlay_"+d;f.style.display="none";f.style.position="absolute";f.style.top="0";f.style.left="0";f.style.zIndex=Windows.maxZIndex+1;Windows.maxZIndex++;f.style.width="100%";c.insertBefore(f,c.firstChild);Prototype.Browser.WebKit&&e=="overlay_modal"?setTimeout(function(){b()},10):b()}},setCookie:function(e,d){document.cookie=d[0]+"="+escape(e)+(d[1]?"; expires="+d[1].toGMTString():"")+(d[2]?"; path="+
d[2]:"")+(d[3]?"; domain="+d[3]:"")+(d[4]?"; secure":"")},getCookie:function(e){var d=document.cookie;e=e+"=";var b=d.indexOf("; "+e);if(b==-1){b=d.indexOf(e);if(b!=0)return null}else b+=2;var c=document.cookie.indexOf(";",b);if(c==-1)c=d.length;return unescape(d.substring(b+e.length,c))},_computeSize:function(e,d,b,c,f,g){var h=document.body,k=document.createElement("div");k.setAttribute("id",d);k.className=g+"_content";if(c)k.style.height=c+"px";else k.style.width=b+"px";k.style.position="absolute";
k.style.top="0";k.style.left="0";k.style.display="none";k.innerHTML=e;h.insertBefore(k,h.firstChild);e=c?$(k).getDimensions().width+f:$(k).getDimensions().height+f;h.removeChild(k);return e}};
