/* 50f2c02d1145011beee2ab80c2f0a749 */
function WikispacesEditor(E,A,C,B,D){this.VISUAL="visual";
this.PLAIN="plain";
this.mode=E;
this.stylesheetUrl=A;
this.cancelUrl=C;
this.uploadUrl=B;
this.maxFileSize=D;
this.plugins=[];
this.currentArea=null;
this.areaMap=Array();
this.toolbar=new WikispacesToolbar(this);
this.createArea=function(G){return new WikispacesEditorArea(this,G);
var F;
return area
};
this.addArea=function(G,F){this.areaMap[G]=F
};
this.removeArea=function(F){delete this.areaMap[F]
};
this.getArea=function(F){return this.areaMap[F]
};
this.getMainArea=function(){return this.getArea("WikispacesEditorContent")
};
this.getCurrentArea=function(){return this.getArea(this.currentArea)
};
this.setCurrentArea=function(G){log("switching editor",G);
var F=this.getCurrentArea();
if(F&&F.areaId!=G){F.selectElement(jQuery(F.getEditorWindow().document).find("body").get(0))
}this.currentArea=G
};
this.setMode=function(H){this.mode=H;
var F;
if(this.mode==this.VISUAL){F=new WikispacesVisualEditor()
}else{F=new WikispacesTextEditor()
}for(var G in F){WikispacesEditorArea.prototype[G]=F[G]
}};
this.sessionReloadFailed=function(){this.getCurrentArea().autosaveEnabled=false;
jQuery("#saveDraftButton").attr("disabled",true).val("Autosave Disabled");
var F=jQuery("#autosaveStatus");
F.html("Autosave Disabled").css("color","red");
F.fadeIn("slow");
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.")
});
if(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(F){this.plugins[this.plugins.length]=F
};
this.setMode(E);
WikispacesEditor.editor=this
}WikispacesEditor.getEditor=function(){return WikispacesEditor.editor
};
function WikispacesEditorArea(editor,areaId){this.editor=editor;
this.areaId=areaId;
var me=this;
this.editor.addArea(areaId,this);
if(!this.editor.getCurrentArea()){this.editor.setCurrentArea(areaId)
}this.zeroBorder="#c0c0c0";
this.updateHierarchyHandle;
this.updateHierarchyElement;
this.cursorPos;
this.originalToolbar;
this.detectedChangeHandle;
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 me.editorUnsavedChangesWarning()
}
};
this.detectedChangeDelayed=function(){if(typeof this.detectedChangeHandle=="number"){clearTimeout(this.detectedChangeHandle)
}this.detectedChangeHandle=setTimeout(function(){me.detectedChange()
},50)
};
this.detectedChange=function(){if(typeof this.detectedChangeHandle=="number"){clearTimeout(this.detectedChangeHandle)
}if(!document.rte.changeDetected.value){document.rte.changeDetected.value=true;
if(this.mainEditor){this.registerCleanup()
}setTimeout(function(){me.autosaveLoop()
},this.AUTOSAVE_INTERVAL)
}if(this.editor.mode==this.editor.VISUAL){this.lookForHeightChange();
var children=jQuery(this.editor.getMainArea().getEditorWindow().document.body)[0].childNodes;
var lastNode=children[children.length-1];
var done=false;
var addBr=false;
while(!done&&!addBr){if(lastNode&&lastNode.nodeType==3){if(jQuery.trim(jQuery(lastNode).text())==""){lastNode=lastNode.previousSibling
}else{done=true
}}else{if(jQuery(lastNode).is("br")){done=true
}else{addBr=true
}}}if(addBr){jQuery(this.editor.getMainArea().getEditorWindow().document.body).append("<br/>")
}}};
this.lookForHeightChange=function(){var contentHeight=this.getContentHeight();
var contentWidth=this.getMaxWidth();
if(!this.editorMinWidth){this.editorMinWidth=jQuery("#toolbarPopup").width()-32
}if(contentHeight<290){contentHeight=290
}if(contentWidth<this.editorMinWidth){contentWidth=this.editorMinWidth
}if(!this.editorHeight){this.editorHeight=jQuery("#editor").height()
}if(!this.editorWidth){this.editorWidth=jQuery("#editor").width()
}if(contentHeight>this.editorHeight){this.editorHeight=contentHeight+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(contentWidth>this.editorWidth){this.editorWidth=contentWidth+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)
}return 
};
this.getContentHeight=function(){var editorDocument=this.getEditorWindow().document;
var editorBody=editorDocument.getElementById("editor_body");
if(editorBody){var contentHeight=editorBody.scrollHeight;
return contentHeight*1
}};
this.getMaxWidth=function(){var editorDocument=this.getEditorWindow().document;
var editorBody=editorDocument.body;
if(editorBody){var contentWidth=editorBody.scrollWidth;
jQuery(editorBody).find("img").each(function(){if(jQuery(this).width()>contentWidth){contentWidth=jQuery(this).width()
}});
jQuery(editorBody).find("table").each(function(){if(jQuery(this).width()>contentWidth){contentWidth=jQuery(this).width()
}});
return contentWidth*1
}};
this.enableDesignMode=function(html,css){log("enableDesignMode: ",arguments);
var frameHtml='<!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';
if(css.length>0){frameHtml+='<link media="all" type="text/css" href="'+css+'" rel="stylesheet">\n'
}else{frameHtml+='<style>@charset "utf-8"; body {background:#FFFFFF;margin:8px;padding:0px;}</style>\n'
}frameHtml+='</head><body id="editor_body" class="wiki" style="margin: 0 1px;">';
frameHtml+=html;
frameHtml+="</body></html>";
var editorDocument=this.getEditorWindow().document;
if(jQuery.browser.msie){editorDocument.open();
editorDocument.write(frameHtml);
editorDocument.close();
editorDocument.designMode="On"
}else{try{editorDocument.designMode="on";
editorDocument.open();
editorDocument.write(frameHtml);
editorDocument.close()
}catch(e){log("enableDesignMode exception",e);
setTimeout(function(){me.enableDesignMode(html,css)
},200);
return 
}}};
this.enableSpellCheck=function(){try{document.getElementById(this.areaId).contentWindow.document.getElementsByTagName("body")[0].spellcheck=true
}catch(e){setTimeout(function(){me.enableSpellCheck()
},5000)
}};
this.rteCleanup=function(){this.stripGuidelines();
this.rteSync()
};
this.rteSync=function(){log("rteSync",this.areaId);
var oHdnField=jQuery("#hdn"+this.areaId);
if(oHdnField.val()==null){oHdnField.val("")
}var content=this.getContent();
content=this.referenceTool.pushInReferences(content);
oHdnField.val(content)
};
this.rteCommand=function(rte,command,option){var editorDocument=this.getEditorWindow().document;
if(jQuery.browser.msie){if((command=="insertorderedlist"||command=="insertunorderedlist")&&!editorDocument.queryCommandState("InsertOrderedList")&&!editorDocument.queryCommandState("InsertUnorderedList")){var oRng=editorDocument.selection.createRange();
if(oRng.htmlText==""){var sUnique=new Date().getTime();
if(command=="insertunorderedlist"){oRng.pasteHTML('<ul><li><p id="'+sUnique+'"> &nbsp; </p></li></ul>')
}else{oRng.pasteHTML('<ol><li><p id="'+sUnique+'"> &nbsp; </p></li></ol>')
}var oP=editorDocument.getElementById(sUnique);
oRng.moveToElementText(oP);
oRng.select();
oRng.collapse(true);
jQuery(oP).replaceWith(jQuery(oP).html())
}else{var htmlText=oRng.htmlText;
htmlText=htmlText.replace(/<br[\s*\/]?>/gmi,"</li> <li>");
htmlText="<li>"+htmlText+"</li>";
var sUnique=new Date().getTime();
if(command=="insertunorderedlist"){oRng.pasteHTML('<ul id="'+sUnique+'">'+htmlText+"</ul>")
}else{oRng.pasteHTML('<ol id="'+sUnique+'">'+htmlText+"</ol>")
}var oP=editorDocument.getElementById(sUnique);
oRng.moveToElementText(oP);
oRng.select()
}this.updateHierarchy();
this.detectedChangeDelayed();
return true
}if(command=="formatblock"){var oRng=editorDocument.selection.createRange();
var htmlText=oRng.htmlText;
if(htmlText!=""){var parentNode=this.ieGetParent();
var sTag=option.toUpperCase().replace(/[<>]/g,"");
if(sTag.match(/^H\d$/)){if(parentNode.nodeName.match(/^H\d$/)){if(parentNode.nodeName!=sTag){var sPreserve=parentNode.innerHTML;
var oNewNode=editorDocument.createElement(sTag);
parentNode.replaceNode(oNewNode);
oNewNode.innerHTML=sPreserve;
this.splitOnBr(sTag,editorDocument)
}else{return false
}}else{htmlText=htmlText.replace(/<br[ \/]*>\s*$/i,"");
htmlText=htmlText.replace(/^\s*<p>/i,"");
htmlText=htmlText.replace(/<\/p>\s*$/i,"");
oRng.pasteHTML("<"+sTag+">"+htmlText+"</"+sTag+">");
this.splitOnBr(sTag,editorDocument)
}}else{if(parentNode!=null&&parentNode.nodeName.match(/^H\d$/)){var sPreserve=parentNode.innerHTML;
var oNewNode=editorDocument.createElement("SPAN");
parentNode.replaceNode(oNewNode);
oNewNode.innerHTML=sPreserve
}}oRng.select();
this.getEditorWindow().focus()
}this.updateHierarchy();
this.detectedChangeDelayed();
return true
}}try{this.getEditorWindow().focus();
editorDocument.execCommand(command,false,option);
this.getEditorWindow().focus();
if(command!="useCSS"&&command!="enableInlineTableEditing"&&command!="enableObjectResizing"){this.updateHierarchy();
this.detectedChangeDelayed()
}}catch(e){log("rteCommand exception "+e.name+" - "+e.message,e,command,option)
}};
this.selectFont=function(){var selected=jQuery("#rteFormatBlock").val();
WikispacesCommon.track("Editor","Select Font",selected);
this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"formatblock",selected)
};
this.moveSelectionIntoEditor=function(win){if(jQuery.browser.msie){return 
}var sel=win.getSelection();
var range=sel.getRangeAt(0);
var startContainer=range.startContainer;
var bodyElement=win.document.getElementById("editor_body");
if(startContainer!=bodyElement&&!Element.childOf(startContainer,bodyElement)){var newRange=win.document.createRange();
newRange.setStart(win.document.getElementById("editor_body"),0);
newRange.setStart(win.document.getElementById("editor_body"),0);
newRange.collapse(true);
sel.addRange(newRange);
sel.removeRange(range)
}};
this.insertNodeAtSelection=function(win,insertNode){this.moveSelectionIntoEditor(win);
var sel=new Selection(win);
var rng=sel.getRangeAt(0);
sel.removeAllRanges();
rng.deleteContents();
rng.insertNode(insertNode);
this.detectedChangeDelayed()
};
this.setRange=function(){var rng=new Selection(this.getEditorWindow());
return rng.getRangeAt(0)
};
this.stripHTML=function(strU){var strN=strU.replace(/(<([^>]+)>)/ig,"");
strN=strN.replace(/\r\n/g," ");
strN=strN.replace(/\n/g," ");
strN=strN.replace(/\r/g," ");
return strN
};
this.showCursor=function(){try{var editorWindow=this.getEditorWindow();
if(jQuery.browser.msie){editorWindow.focus()
}else{editorWindow.focus();
var oNode=jQuery(editorWindow.document).find("body").children(":last").get(0);
if(!oNode){oNode=jQuery(editorWindow.document).find("body").get(0)
}var oRange=editorWindow.document.createRange();
oRange.setEndAfter(oNode);
oRange.setStartAfter(oNode);
var oSel=editorWindow.getSelection();
oSel.addRange(oRange);
editorWindow.focus()
}}catch(e){setTimeout(function(){me.showCursor()
},5000)
}};
this.showGuidelines=function(){try{var editorWindow=this.getEditorWindow(this.areaId);
var tables=editorWindow.document.getElementsByTagName("table");
for(var i=0;
i<tables.length;
i++){if(tables[i].getAttribute("border")=="0"){var trs=tables[i].getElementsByTagName("tr");
for(var j=0;
j<trs.length;
j++){var tds=trs[j].getElementsByTagName("td");
for(var k=0;
k<tds.length;
k++){if(j==0&&k==0){tds[k].style.border="dashed 1px "+this.zeroBorder
}else{if(j==0&&k!=0){tds[k].style.borderBottom="dashed 1px "+this.zeroBorder;
tds[k].style.borderTop="dashed 1px "+this.zeroBorder;
tds[k].style.borderRight="dashed 1px "+this.zeroBorder
}else{if(j!=0&&k==0){tds[k].style.borderBottom="dashed 1px "+this.zeroBorder;
tds[k].style.borderLeft="dashed 1px "+this.zeroBorder;
tds[k].style.borderRight="dashed 1px "+this.zeroBorder
}else{if(j!=0&&k!=0){tds[k].style.borderBottom="dashed 1px "+this.zeroBorder;
tds[k].style.borderRight="dashed 1px "+this.zeroBorder
}}}}}}}}}catch(e){setTimeout(function(){me.showGuidelines()
},5000)
}};
this.stripGuidelines=function(){var editorWindow=this.getEditorWindow();
var tbls=editorWindow.document.getElementsByTagName("table");
for(var j=0;
j<tbls.length;
j++){if(tbls[j].getAttribute("border")=="0"){var tds=tbls[j].getElementsByTagName("td");
for(var k=0;
k<tds.length;
k++){tds[k].removeAttribute("style")
}}}};
this.getRangeParent=function(range){var editorDocument=this.getEditorWindow().document;
var oNode=null;
if(editorDocument.selection.type=="Control"){for(i=0;
i<range.length;
i++){if(range(i).parentNode){oNode=range(i).parentNode;
break
}}}else{oNode=range.parentElement()
}return oNode
};
this.selectParent=function(tag){if(this.imageTool.selectedImage&&this.imageTool.selectedImage.parentNode){var oNode=this.imageTool.selectedImage;
while(oNode&&oNode.nodeName!=tag){oNode=oNode.parentNode
}return oNode
}if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode){var oNode=this.mediaTool.selectedMedia;
while(oNode&&oNode.nodeName!=tag){oNode=oNode.parentNode
}return oNode
}var editorWindow=this.getEditorWindow();
if(jQuery.browser.msie){editorWindow.focus();
var oRange=editorWindow.document.selection.createRange();
var oNode=this.getRangeParent(oRange);
while(oNode&&oNode.nodeName!=tag){oNode=oNode.parentNode
}if(oNode&&oNode.nodeName==tag){editorWindow.focus();
editorWindow.document.selection.empty();
var oRange=editorWindow.document.selection.createRange();
oRange.moveToElementText(oNode);
oRange.select()
}return oNode
}editorWindow.focus();
var oNode=null;
var oRng=editorWindow.window.getSelection().getRangeAt(0);
if(oRng.startContainer.nodeType==1){oNode=oRng.startContainer.childNodes[oRng.startOffset]
}else{oNode=oRng.startContainer
}if(oNode&&oNode.hasChildNodes()){var children=oNode.childNodes;
for(var i=0;
i<children.length;
i++){if(children[i].nodeName==tag){oNode=children[i]
}}}while(oNode&&oNode.nodeName!=tag){oNode=oNode.parentNode
}if(oNode&&oNode.nodeName==tag){editorWindow.focus();
var oRange=editorWindow.document.createRange();
oRange.selectNode(oNode);
var oSel=editorWindow.getSelection();
oSel.removeAllRanges();
oSel.addRange(oRange)
}return oNode
};
this.geckoKeyPress=function(e){if(e.ctrlKey){var key=String.fromCharCode(e.charCode).toLowerCase();
var cmd="";
switch(key){case"b":cmd="bold";
break;
case"i":cmd="italic";
break;
case"u":cmd="underline";
break
}if(cmd){this.rteCommand(this.areaId,cmd,null);
e.preventDefault();
e.stopPropagation()
}}};
this.safariKeyPress=function(e){var editorWindow=this.getEditorWindow();
var editorDocument=editorWindow.document;
switch(e.keyCode){case 13:var sel=new Selection(this.getEditorWindow());
var rng=sel.getRangeAt(0);
var parentNode=rng.startContainer.parentNode;
if((!e.shiftKey&&(editorWindow.document.queryCommandState("InsertOrderedList")||editorWindow.document.queryCommandState("InsertUnorderedList")))||"H1"==parentNode.nodeName||"H2"==parentNode.nodeName||"H3"==parentNode.nodeName||"H4"==parentNode.nodeName||"H5"==parentNode.nodeName||"H6"==parentNode.nodeName){return true
}if(!(e.ctrlKey||e.altKey)){this.insertInEditor('<br id="wikispacesNewline" />&nbsp;');
var nbsp=jQuery(editorDocument.body).find("#wikispacesNewline").attr("id",null).get(0).nextSibling;
var sel=editorWindow.getSelection();
var range=editorDocument.createRange();
range.setStart(nbsp,0);
range.setEnd(nbsp,0);
sel.removeAllRanges();
sel.addRange(range);
e.preventDefault();
e.stopPropagation();
return false
}break;
case 9:if(!(e.ctrlKey||e.altKey)){if(editorDocument.queryCommandState("InsertOrderedList")||editorDocument.queryCommandState("InsertUnorderedList")){if(e.shiftKey){this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"outdent","");
e.preventDefault();
e.stopPropagation();
return false
}else{this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"indent","");
e.preventDefault();
e.stopPropagation();
return false
}}e.preventDefault();
e.stopPropagation();
return false
}break;
case 21:if(e.ctrlKey){this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"underline",null);
e.preventDefault();
e.stopPropagation();
return false
}break
}};
this.ieKeyPress=function(event){var editorWindow=this.getEditorWindow();
switch(event.keyCode){case 13:if(!(event.ctrlKey||event.altKey||event.shiftKey)){var parentNode=this.ieGetParent();
if(editorWindow.document.queryCommandState("InsertOrderedList")||editorWindow.document.queryCommandState("InsertUnorderedList")||"H1"==parentNode.nodeName||"H2"==parentNode.nodeName||"H3"==parentNode.nodeName||"H4"==parentNode.nodeName||"H5"==parentNode.nodeName||"H6"==parentNode.nodeName){return true
}this.insertInEditor("<br />&nbsp;");
var oRange=editorWindow.document.selection.createRange();
oRange.moveStart("character",-1);
oRange.select();
editorWindow.document.selection.clear();
event.preventDefault();
event.stopPropagation();
return false
}break;
case 9:if(!(event.ctrlKey||event.altKey)){if(editorWindow.document.queryCommandState("InsertOrderedList")||editorWindow.document.queryCommandState("InsertUnorderedList")){if(event.shiftKey){this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"outdent","");
event.preventDefault();
event.stopPropagation();
return false
}else{this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"indent","");
event.preventDefault();
event.stopPropagation();
return false
}}}break
}return true
};
this.ieGetParent=function(){var oNode=null;
var editorWindow=this.getEditorWindow();
editorWindow.focus();
var oRange=editorWindow.document.selection.createRange();
oNode=this.getRangeParent(oRange);
while(oNode){if(oNode.nodeType==1&&oNode.nodeName!="P"&&oNode.nodeName!="SPAN"&&oNode.nodeName!="A"){return(oNode)
}if(oNode.parentNode){oNode=oNode.parentNode
}else{return null
}}};
this.splitOnBr=function(tag,d){var listElements=jQuery(d).find(tag);
listElements.each(function(){var oLiChildren=jQuery(this).children();
if(oLiChildren.length>0&&oLiChildren.get(0).tagName.toLowerCase()=="p"){oLiChildren=oLiChildren.get(0).children()
}var listLi=jQuery(this);
var oNewLi=d.createElement(tag);
var isBrFound=false;
var j=0;
while(oLiChildren.length>j){if(oLiChildren.get(j).nodeType==1&&oLiChildren.get(j).tagName.toLowerCase()=="br"){if(oNewLi.childNodes.length){lastLi=lastLi.insertAdjacentElement("afterEnd",oNewLi);
log("added a new li")
}oNewLi=d.createElement(tag);
oLiChildren.remove(j);
isBrFound=true;
log("BR FOUND IN LIST")
}else{if(isBrFound){oNewLi.appendChild(oLiChildren.item(j).cloneNode(true));
oLiChildren.item(j).removeNode();
log("appended a cloned node")
}else{j++
}}}if(oNewLi.childNodes.length){lastLi=lastLi.insertAdjacentElement("afterEnd",oNewLi)
}})
};
this.customEditorStart=function(contentStorageId,autosaveDetected){this.timeTracker=new TimeTracker();
this.timeTracker._setHistogramBuckets([1*60*1000,2*60*1000,5*60*1000,10*60*1000,20*60*1000,30*60*1000,60*60*1000]);
this.timeTracker._recordStartTime();
if(this.mainEditor){this.fadeEditor();
this.registerCleanup()
}if(autosaveDetected){log("autosaveDetected");
if(typeof (Dialog)!="undefined"){log("showAutosavePopup");
this.editor.toolbar.showAutosavePopup(contentStorageId);
return true
}else{log("ERROR: undefined Dialog");
return false
}}else{return this.customEditorStartSecondary(contentStorageId)
}};
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(editorDocument){jQuery(editorDocument.body).find("a").unbind("dblclick");
jQuery(editorDocument.body).find("img.WikiAnchor").unbind("dblclick");
jQuery(editorDocument.body).find(".WikiMedia").not(".WikiMediaFile").unbind("dblclick");
jQuery(editorDocument.body).find("img.WikiAnchor").dblclick(function(){me.editor.toolbar.linkToolbar.openAnchor(this)
});
jQuery(editorDocument.body).find(".WikiMedia").not(".WikiMediaFile").dblclick(function(){me.editorEmbedMedia()
});
jQuery(editorDocument.body).find(".WikiReference").dblclick(function(){me.referenceTool.openReferencePopup(this.id+"-Area")
})
};
this.handleTabs=function(e){if(e.ctrlKey||e.altKey){return 
}if(e.keyCode=="9"){var oNode=this.getSelectionContainer();
if(jQuery(oNode).is("li")||jQuery(oNode).parents("li").length>0){if(jQuery.browser.mozilla&&jQuery.browser.version.substring(0,3)>=1.9){if(e.shiftKey){this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"outdent","")
}else{this.rteCommand(this.areaId,"useCSS",true);
this.rteCommand(this.areaId,"indent","")
}e.preventDefault();
e.stopPropagation()
}}else{if(jQuery(oNode).is("td,th")||jQuery(oNode).parents("td,th").length>0){var currentCell;
if(jQuery(oNode).is("td,th")){currentCell=jQuery(oNode)
}else{var currentCell=jQuery(oNode).parents("td,th").eq(0)
}var moveCell;
if(e.shiftKey){moveCell=currentCell.prev("td,th");
if(moveCell.length==0&&currentCell.parents("tr").eq(0).prev("tr").length>0){moveCell=currentCell.parents("tr").eq(0).prev("tr").find("td,th").eq(currentCell.parents("tr").eq(0).prev("tr").find("td,th").length-1)
}if(!moveCell.length){this.tableTool.addNewRow(false,true);
moveCell=currentCell.parents("tr").eq(0).prev("tr").find("td,th").eq(currentCell.parents("tr").eq(0).prev("tr").find("td,th").length-1)
}}else{moveCell=currentCell.next("td,th");
if(moveCell.length==0&&currentCell.parents("tr").eq(0).next("tr").length>0){moveCell=currentCell.parents("tr").eq(0).next("tr").find("td,th").eq(0)
}if(!moveCell.length){this.tableTool.addNewRow(false,false);
moveCell=currentCell.parents("tr").eq(0).next("tr").find("td,th").eq(0)
}}if(moveCell.length){moveCell=moveCell.get(0);
var editorDocument=this.getEditorWindow().document;
if(jQuery.browser.msie){this.getEditorWindow().focus();
editorDocument.selection.empty();
var oRange=editorDocument.selection.createRange();
oRange.moveToElementText(moveCell);
oRange.select()
}else{if(jQuery.browser.safari){var sel=this.getEditorWindow().getSelection();
var range=editorDocument.createRange();
range.setStart(this.findTextNode(moveCell),0);
range.setEnd(this.findTextNode(moveCell),0);
sel.removeAllRanges();
sel.addRange(range)
}else{var sel=new Selection(this.getEditorWindow());
var range=sel.getRangeAt(0);
range.setStart(moveCell,0);
range.collapse(true)
}}this.selectElement(moveCell);
e.preventDefault();
e.stopPropagation()
}else{this.detectedChange()
}}}}};
this.findTextNode=function(node){var checkNode;
for(var i=0;
i<node.childNodes.length;
i++){checkNode=node.childNodes[i];
if(checkNode.nodeType==3){return checkNode
}else{if(checkNode.nodeType==1){var subCheck=this.findTextNode(checkNode);
if(subCheck.nodeType==3){return subCheck
}}}}return null
};
this.keyEventHandler=function(e){if(typeof this.updateHierarchyHandle=="number"){clearTimeout(this.updateHierarchyHandle)
}this.updateHierarchyHandle=setTimeout(function(){me.updateHierarchy()
},100);
switch(e.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(e.target);
break;
case Event.KEY_BACKSPACE:case Event.KEY_RETURN:case Event.KEY_DELETE:this.selectElement(e.target);
this.detectedChange();
break;
default:this.detectedChange()
}};
this.mouseEventHandler=function(e){if(typeof this.updateHierarchyHandle=="number"){clearTimeout(this.updateHierarchyHandle)
}this.updateHierarchyHandle=setTimeout(function(){me.updateHierarchy()
},100);
this.selectElement(e.target)
};
this.selectElement=function(elem){log("selectElement",elem);
var enableResizing=false;
if(this!=this.editor.getCurrentArea()){log("selectElement called on non active editor, switch",this);
this.editor.setCurrentArea(this.areaId)
}if(jQuery(elem).is("html")){elem=this.getSelectionContainer()
}if(elem.parentNode&&jQuery(elem).is("img")&&(jQuery(elem).is(".WikiMediaFile")||!jQuery(elem).is(".WikiAnchor, .WikiMedia, .WikiReference"))){log("selectElement: image on");
this.imageTool.selectImage(elem);
if(!jQuery(elem).is(".WikiFile")){enableResizing=true
}}else{if(this.imageTool.selectedImage){log("selectElement: image off");
this.imageTool.unSelectImage()
}}if(elem.parentNode&&jQuery(elem).is("img.WikiMedia, img.WikiAnchor, img.WikiReference")&&!jQuery(elem).is(".WikiMediaFile")){log("selectElement: media on");
this.mediaTool.selectMedia(elem);
var mediaProperties=elem.id.match(/wikitext@@(.*)@@/);
if(mediaProperties&&mediaProperties.length>0){var type=mediaProperties[1];
if(type=="media"){var mediaType=elem.id.match(/type="(.*)"\s/)[1];
if(mediaType!="custom"){enableResizing=true
}}}}else{if(this.mediaTool.selectedMedia){log("selectElement: media off");
this.mediaTool.unSelectMedia()
}}if(jQuery(elem).is("td,th")){log("selectElement: table on");
this.tableTool.selectTableCell(elem)
}else{if(jQuery(elem).parents("td,th").length>0){log("selectElement: table on");
this.tableTool.selectTableCell(jQuery(elem).parents("td,th").get(0))
}else{if(this.tableTool.selectedTableCell){log("selectElement: table off");
this.tableTool.unselectTableCell()
}}}if(enableResizing!=this.currentResizing){this.rteCommand(this.areaId,"enableObjectResizing",enableResizing);
this.currentResizing=enableResizing
}};
this.getSelectionContainer=function(){if(this.imageTool.selectedImage&&this.imageTool.selectedImage.parentNode){var oNode=this.imageTool.selectedImage;
return oNode
}if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode){var oNode=this.mediaTool.selectedMedia;
return oNode
}var editorWindow=this.getEditorWindow();
var editorDocument=this.getEditorWindow().document;
if(jQuery.browser.msie){this.getEditorWindow().focus();
var oRange=editorDocument.selection.createRange();
return this.getRangeParent(oRange)
}else{this.getEditorWindow().focus();
var oNode=this.getEditorWindow().getSelection().getRangeAt(0).commonAncestorContainer;
return oNode
}};
this.isSelectionUnderTag=function(rte,tagName){var oNode=this.getSelectionContainer();
var examineNode=oNode;
while(examineNode!=null){if(examineNode.tagName==tagName){return examineNode
}examineNode=examineNode.parentNode
}return false
};
this.updateHierarchy=function(){log("updateHierarchy top");
if(typeof this.updateHierarchyHandle=="number"){clearTimeout(this.updateHierarchyHandle)
}var elem=this.getSelectionContainer();
var parentString="";
if(null!=this.updateHierarchyElement&&elem==this.updateHierarchyElement){return 
}this.updateHierarchyElement=elem;
this.unsetAllButtons();
while(elem&&elem.tagName!="BODY"&&elem.tagName!="HTML"){if(elem.tagName){this.setChildStatus(elem);
parentString=elem.tagName+" &gt; "+parentString
}else{parentString="text &gt; "+parentString
}elem=elem.parentNode
}if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode){if(jQuery(this.mediaTool.selectedMedia).is(".WikiAnchor")){this.setButton("rteLinkBtn")
}else{this.setButton("rteMediaBtn")
}this.unsetButton("rteImageBtn")
}jQuery("#hierarchy").html(parentString)
};
this.unsetAllButtons=function(){jQuery("#wikispacesEditorToolbar .rteButtonActive").removeClass("rteButtonActive");
this.setFormat("p")
};
this.setFormat=function(value){jQuery("#rteFormatBlock").val("<"+value+">");
if(value=="pre"||value=="code"){jQuery("#rteFormatBlock").attr("disabled",true)
}else{jQuery("#rteFormatBlock").attr("disabled",false)
}};
this.setChildStatus=function(node){switch(node.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(node.className);
this.setButton("rteCodeBtn");
break;
case"SPAN":if(jQuery(node).attr("style")||jQuery(node).attr("class")){this.setButton("rteTextColorBtn")
}break
}if(node.style.fontStyle=="italic"){this.setButton("rteItalicBtn")
}if(node.style.fontWeight=="bold"){this.setButton("rteBoldBtn")
}if(node.style.textDecoration=="underline"){this.setButton("rteUnderlineBtn")
}};
this.setCodeFormat=function(className){this.setFormat("code");
var optionValue="Code";
if(className){optionValue+=" ("+className+")"
}document.getElementById("rteFormatBlock").options[document.getElementById("rteFormatBlock").selectedIndex].innerHTML=optionValue
};
this.setButton=function(buttonName){jQuery("#"+buttonName).addClass("rteButtonActive")
};
this.unsetButton=function(buttonName){jQuery("#"+buttonName).removeClass("rteButtonActive")
};
this.getContent=function(){if(this.editor.mode==this.editor.VISUAL){var editorDocument=this.getEditorWindow().document;
bodyTags=editorDocument.getElementsByTagName("HTML")[0].getElementsByTagName("BODY");
for(i=1;
i<bodyTags.length;
i++){bodyTags[0].innerHTML=bodyTags[0].innerHTML+bodyTags[i].innerHTML;
bodyTags[i].parentNode.removeChild(bodyTags[i])
}return editorDocument.body.innerHTML
}else{return jQuery("#textEditor").val()
}};
this.saveCursor=function(){if(!jQuery.browser.msie){return 
}if(!document.selection){return 
}if(this.editor.mode==this.editor.VISUAL){if(this.mediaTool.selectedMedia||this.imageTool.selectedImage){return 
}var rng=this.getEditorWindow().document.selection.createRange();
var rng2=document.selection.createRange();
if(jQuery.browser.version.substring(0,1)>=8&&rng.text==""){jQuery(this.getEditorWindow().document.body).find("#__IERANGE__").remove();
this.insertInEditorActual('<span id="__IERANGE__"></span>',false)
}else{if(rng.duplicate){this.cursorPos=rng.duplicate()
}else{if(rng2.duplicate){this.cursorPos=rng2.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 elem=jQuery(this.getEditorWindow().document).find("#__IERANGE__").get(0);
if(elem&&jQuery(elem).parents("body").length>0){try{var newRange=this.getEditorWindow().document.selection.createRange();
newRange.moveToElementText(elem);
newRange.select();
jQuery(this.getEditorWindow().document).find("#__IERANGE__").remove()
}catch(e){}return 
}}if(this.cursorPos){try{this.cursorPos.select();
delete this.cursorPos
}catch(e){}}};
this.prepareSelection=function(textarea){textarea.sel_text="";
textarea.sel_text_pre="";
textarea.sel_text_post="";
textarea.sel_start=0;
textarea.sel_end=0;
textarea.cur_start=0;
textarea.cur_end=0;
textarea.focus();
if(typeof (textarea.selectionStart)=="number"){textarea.sel_start=textarea.selectionStart;
textarea.cur_start=textarea.selectionStart;
textarea.sel_end=textarea.selectionEnd;
textarea.cur_end=textarea.selectionEnd;
textarea.sel_text=textarea.value.substring(textarea.sel_start,textarea.sel_end);
textarea.sel_text_pre=textarea.value.substring(0,textarea.sel_start);
textarea.sel_text_post=textarea.value.substring(textarea.sel_end,textarea.value.length)
}else{if(document.selection){var range=document.selection.createRange();
if(true||this.getRangeParent(range).id==textarea.id){var range_all=document.body.createTextRange();
range_all.moveToElementText(textarea);
for(var sel_start=0;
range_all.compareEndPoints("StartToStart",range)<0;
sel_start++){range_all.moveStart("character",1)
}textarea.cur_start=sel_start;
for(var i=0;
i<=sel_start;
i++){if(textarea.value.charAt(i)=="\n"){sel_start++
}}textarea.sel_start=sel_start;
var range_all=document.body.createTextRange();
range_all.moveToElementText(textarea);
for(var sel_end=0;
range_all.compareEndPoints("StartToEnd",range)<0;
sel_end++){range_all.moveStart("character",1)
}textarea.cur_end=sel_end;
for(var i=0;
i<=sel_end;
i++){if(textarea.value.charAt(i)=="\n"){sel_end++
}}textarea.sel_end=sel_end;
textarea.sel_text=range.text;
textarea.sel_text_pre=textarea.value.substring(0,textarea.sel_start);
textarea.sel_text_post=textarea.value.substring(textarea.sel_end,textarea.value.length)
}}}};
this.expandSelectionToLine=function(){var myField=document.getElementById("textEditor");
this.prepareSelection(myField);
var newStart;
for(var i=myField.sel_start;
i>=0;
i--){if(myField.value.substring(i,i+1)=="\n"){newStart=i+1;
break
}}for(i=myField.sel_end;
i<myField.value.length-1;
i++){if(myField.value.substring(i,i+1)=="\n"){this.setSelectionRange(myField,newStart,i);
return true
}}return false
};
this.expandSelectionToTag=function(tagPrefix,tagName,tagSuffix){var currentSelection=this.getSelectedText().replace(/^\s+/,"").replace(/\s+$/,"");
if(currentSelection){if(currentSelection.substring(0,tagName.length+tagPrefix.length)==tagPrefix+tagName&&currentSelection.substring(currentSelection.length-tagSuffix.length,currentSelection.length)==tagSuffix){return true
}else{return false
}}else{var myField=document.getElementById("textEditor");
this.prepareSelection(myField);
var openingTagsFound=0;
var closingTagsFound=0;
var startFrom=myField.sel_start-1;
if(startFrom<0){startFrom=0
}var newStart=null;
for(var i=startFrom;
i>=0;
i--){if(myField.value.substring(i,i+tagName.length+tagPrefix.length)==tagPrefix+tagName){if(closingTagsFound==0){newStart=i;
break
}else{closingTagsFound--
}}else{if(myField.value.substring(i,i+tagPrefix.length)==tagPrefix){return false
}else{if(myField.value.substring(i,i+tagSuffix.length)==tagSuffix){if(myField.sel_start-i>=tagSuffix.length){closingTagsFound++
}}}}}if(newStart==null){return false
}startFrom=myField.sel_end-(tagSuffix.length-1);
if(startFrom<0){startFrom=0
}if(startFrom<(newStart+tagName.length+tagPrefix.length)){startFrom=newStart+tagName.length+tagPrefix.length
}for(i=startFrom;
i<myField.value.length-1;
i++){if(myField.value.substring(i,i+tagSuffix.length)==tagSuffix){if(openingTagsFound==0){this.setSelectionRange(myField,newStart,i+tagSuffix.length);
return true
}else{openingTagsFound--
}}else{if(myField.value.substring(i,i+tagPrefix.length)==tagPrefix){openingTagsFound++
}}}}return false
};
this.setSelectionRange=function(element,start,end){if(element.setSelectionRange){element.setSelectionRange(start,end)
}else{var newStart=start;
var newEnd=end;
for(var i=0;
i<start;
i++){if(element.value.charAt(i)=="\n"){newStart--;
newEnd--
}}var range=element.createTextRange();
with(range){collapse(true);
moveEnd("character",newEnd);
moveStart("character",newStart);
select()
}}};
this.cancelEdit=function(element){this.editorConfirmDeparture=false;
WikispacesCommon.track("Editor","Stop","Cancel");
this.timeTracker._recordEndTime();
this.timeTracker._track(pageTracker,undefined,"Editor");
window.location=element.href;
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 content;
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){var editorDocument=this.getEditorWindow().document;
try{this.styleTool.removeSafariSpans(editorDocument.body);
if(jQuery(editorDocument).find("span").length!=this.startingSpanCount){this.styleTool.collapseNodes(editorDocument.getElementsByTagName("span"))
}this.styleTool.mergeNodes(editorDocument.getElementsByTagName("span"))
}catch(e){}this.rteSync(this.areaId);
content=document.getElementById("hdn"+this.areaId).value
}else{content=this.getContent()
}jQuery.ajax({async:false,cache:false,data:{content:content,mode:this.editor.mode},dataType:"xml",global:false,error:function(XMLHttpRequest,textStatus,errorThrown){reloadSession(function(){me.showPreview()
},3000,function(){jQuery("#toolbarPopup_table_content_spinner").remove();
me.hidePreview();
me.editor.sessionReloadFailed()
})
},success:function(data,textStatus){log("showPreviewResponse",data);
reloadSessionSuccess();
if(data.getElementsByTagName("preview").length>0){var previewDataBlock=data.getElementsByTagName("preview")[0];
var previewData="";
if(previewDataBlock&&previewDataBlock.childNodes.length>0){for(var i=0;
i<previewDataBlock.childNodes.length;
i++){previewData+=previewDataBlock.childNodes[i].nodeValue
}}jQuery("#previewBox").html(previewData);
fixEmbedLayers();
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 id="close" class="btn"><span><span>Continue Editing</span></span></button> <button id="save" class="btn primary" name="update_preview"><span><span>Save</span></span></button></td>');
jQuery("#toolbarPopup_table_content_preview #close").click(function(){me.hidePreview()
});
jQuery("#toolbarPopup_table_content_preview #save").click(function(){document.rte.update.click()
})
}else{if(data.getElementsByTagName("error").length>0){jQuery("#toolbarPopup_table_content_spinner").remove();
me.hidePreview();
var error=data.getElementsByTagName("error")[0].getAttribute("message");
alert(error)
}else{jQuery("#toolbarPopup_table_content_spinner").remove();
me.hidePreview();
alert("An unexpected error occurred.")
}}},type:"POST",url:"/page/preview/"+encodeURIComponent(wikispaces_page)})
};
this.getEditorWindow=function(rte){if(!rte){rte=this.areaId
}return document.getElementById(rte).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 zIndex=jQuery("#"+this.areaId).parents(".dialog").css("z-index");
if(!zIndex){zIndex=0
}return zIndex
};
this.autosaveDiscardDraft=function(contentStorageId){WikispacesCommon.track("Editor","Autosave","Discard");
var url="/page/discardautosave/"+encodeURIComponent(wikispaces_page);
jQuery.ajax({url:url,type:"GET",global:false,cache:false});
this.customEditorStartSecondary(contentStorageId)
};
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)
}WikispacesEditorArea.prototype.AUTOSAVE_INTERVAL=60000;
WikispacesEditorArea.prototype.editorHeight=null;
WikispacesEditorArea.prototype.editorWidth=null;
WikispacesEditorArea.prototype.editorMinWidth=null;
WikispacesEditorArea.prototype.editorMaxWidth=null;
WikispacesEditorArea.prototype.concurrentEditors=new Array();
WikispacesEditorArea.prototype.concurrentEditorPopup=null;
WikispacesEditorArea.prototype.autosaveEnabled=true;
WikispacesEditorArea.prototype.autosaveLoop=function(){var A=this;
try{this.autosave()
}catch(B){}finally{setTimeout(function(){A.autosaveLoop()
},this.AUTOSAVE_INTERVAL)
}};
WikispacesEditorArea.prototype.autosave=function(B){log("autosave",B);
var E=this;
jQuery("#saveDraftButton").attr("disabled",true).val("Saving...");
if(this.editor.mode==this.editor.VISUAL){var D=this.getEditorWindow().document;
try{this.styleTool.removeSafariSpans(D.body);
if(jQuery(D).find("span").length!=this.startingSpanCount){this.styleTool.collapseNodes(D.getElementsByTagName("span"))
}this.styleTool.mergeNodes(D.getElementsByTagName("span"))
}catch(G){}}if(typeof B=="undefined"){B=true
}if(this.autosaveEnabled){var A="/page/autosave/"+encodeURIComponent(wikispaces_page)+"/"+this.version+"?mode="+this.editor.mode;
var C=this.getContent();
if(this.editor.mode==this.editor.VISUAL){C=this.referenceTool.pushInReferences(C)
}var F="content="+encodeURIComponent(C);
jQuery.ajax({async:B,url:A,type:"POST",data:F,dataType:"xml",global:false,cache:false,error:function(H,J,I){reloadSession(function(){E.autosave()
},3000,function(){E.editor.sessionReloadFailed()
})
},success:function(H){E.autosaveProcessResponse(H);
reloadSessionSuccess()
}});
log("autosave finished")
}};
WikispacesEditorArea.prototype.autosaveProcessResponse=function(E){log("autosaveProcessResponse",E);
if(E.getElementsByTagName("autosave")[0].getElementsByTagName("save").length>0){this.setAutosaveTime(E.getElementsByTagName("autosave")[0].getElementsByTagName("save")[0].firstChild.nodeValue)
}else{if(E.getElementsByTagName("autosave")[0].getElementsByTagName("error").length>0){var H=E.getElementsByTagName("autosave")[0].getElementsByTagName("error")[0].getAttribute("message");
var G=jQuery("#autosaveStatus");
G.html(H).css("color","red");
G.fadeIn("slow")
}}if(E.getElementsByTagName("status").length>0&&E.getElementsByTagName("status")[0].getAttribute("type")=="changed"){var M=E.getElementsByTagName("status")[0].getElementsByTagName("revision");
for(i=0;
i<M.length;
i++){var D=M[i].getElementsByTagName("user")[0].firstChild.nodeValue;
var C=M[i].getElementsByTagName("date")[0].firstChild.nodeValue;
var A=M[i].getAttribute("id");
this.addSavedVersionDetected(A,D,C)
}}var J=Array();
var L=this.concurrentEditors.length>0;
if(E.getElementsByTagName("concurrent").length>0){var F=E.getElementsByTagName("concurrent")[0].getElementsByTagName("editor");
for(i=0;
i<F.length;
i++){var D=F[i].getElementsByTagName("user")[0].firstChild.nodeValue;
var C=F[i].getElementsByTagName("date")[0].firstChild.nodeValue;
this.addConcurrentEditor(D,C);
J[D]=1
}if(!L){WikispacesCommon.track("Editor","Concurrent Editing","Start")
}}for(var D in this.concurrentEditors){if(J[D]!=1){this.removeConcurrentEditor(D)
}}if(L&&this.concurrentEditors.length==0){WikispacesCommon.track("Editor","Concurrent Editing","End")
}if(this.concurrentEditors.length){WikispacesCommon.track("Editor","Concurrent Editing","Editor Count",this.concurrentEditors.length)
}if(E.getElementsByTagName("autosave")[0].getElementsByTagName("merge").length>0){var I=E.getElementsByTagName("autosave")[0].getElementsByTagName("merge")[0];
if(I.getElementsByTagName("mergeStatus").length>0&&I.getElementsByTagName("mergeStatus")[0].firstChild){var B=I.getElementsByTagName("mergeStatus")[0].firstChild.nodeValue;
document.getElementById("mergeStatus").innerHTML=B
}if(I.getElementsByTagName("mergeResult").length>0&&I.getElementsByTagName("mergeResult")[0].firstChild){var K="";
for(i=0;
i<I.getElementsByTagName("mergeResult")[0].childNodes.length;
i++){K+=I.getElementsByTagName("mergeResult")[0].childNodes[i].nodeValue
}if(this.editor.mode==this.editor.PLAIN){jQuery("#mergeResult").val(K)
}else{jQuery("#mergeResult").html(K)
}}}jQuery("#saveDraftButton").attr("disabled",false).val("Save Draft")
};
WikispacesEditorArea.prototype.setAutosaveTime=function(B){var A=jQuery("#autosaveStatus");
A.html("Draft Saved at "+B);
A.css("color","");
A.fadeIn("slow")
};
WikispacesEditorArea.prototype.removeLock=function(){var A="/page/removepagelock/"+encodeURIComponent(wikispaces_page);
jQuery.ajax({url:A,type:"GET",global:false,cache:false})
};
WikispacesEditorArea.prototype.addConcurrentEditor=function(C,D){this.showConcurrentEditorPopup();
jQuery("#concurrentEditor_otherEditor_heading").show();
this.concurrentEditors[C]=D;
var A="concurrentEditor_otherEditor_"+C;
var B=jQuery("#"+A);
if(!B.length){jQuery("#concurrentEditor_otherEditors").append('<li id="'+A+'"><img src="/user/pic/'+C+'-sm.jpg" height="16" width="16" style="vertical-align: text-top"/> '+C+" started editing this page at "+D+"</li>");
jQuery("#concurrentEditor_noEditors").hide();
jQuery("#"+A).effect("highlight",{color:"#FFA"},2000)
}};
WikispacesEditorArea.prototype.removeConcurrentEditor=function(C){var B="concurrentEditor_otherEditor_"+C;
var A=jQuery("#"+B);
if(A.length){A.slideUp();
A.remove();
var D=jQuery("#concurrentEditor_otherEditors li");
if(D.length==1){jQuery("#concurrentEditor_noEditors").show().effect("highlight",{color:"#FFA"},2000)
}}};
WikispacesEditorArea.prototype.addSavedVersionDetected=function(A,D,F){this.anotherEditDetected=true;
this.showConcurrentEditorPopup();
jQuery("#concurrentEditor_savedVersion_heading").show();
var B="concurrentEditor_savedVersion_"+A;
var C=jQuery("#"+B);
if(!C.length){jQuery("#concurrentEditor_savedVersion_viewChanges").html('<a href="/page/diff/'+encodeURIComponent(wikispaces_page)+"?v1="+this.version+"&v2="+A+'" target="_new">View all changes since I started editing</a>');
jQuery("#concurrentEditor_savedVersions").append('<li id="'+B+'"><img src="/user/pic/'+D+'-sm.jpg" height="16" width="16" style="vertical-align: text-top;"/> '+D+" saved a new version at "+F+'.  <a href="/page/diff/'+encodeURIComponent(wikispaces_page)+"/"+A+'" target="_new">View the changes</a></li>');
var E=jQuery("#concurrentEditor_savedVersions li");
if(E.length>1){jQuery("#concurrentEditor_savedVersion_viewChanges").show()
}jQuery("#"+B).effect("highlight",{color:"#FFA"},2000);
this.removeConcurrentEditor(D)
}};
WikispacesEditorArea.prototype.showConcurrentEditorPopup=function(){var A=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(A.concurrentEditorPopup,false)
})
}else{this.concurrentEditorPopup.element.style.position="fixed"
}}this.concurrentEditorPopup.element.style.left="0px";
this.concurrentEditorPopup.show();
this.concurrentEditorPopup.toFront();
this.updateConcurrentEditorPopup()
};
WikispacesEditorArea.prototype.updateConcurrentEditorPopup=function(){this.concurrentEditorPopup.updateWidth();
this.concurrentEditorPopup.updateHeight();
if(jQuery.browser.msie){var A=document.documentElement.clientHeight+document.documentElement.scrollTop-jQuery(this.concurrentEditorPopup.element).height()+"px";
if(A<this.concurrentEditorPopup.element.style.top){this.concurrentEditorPopup.element.style.top=A
}}else{this.concurrentEditorPopup.element.style.top=document.documentElement.clientHeight-jQuery(this.concurrentEditorPopup.element).height()+"px"
}};
jQuery.fn.farbtastic=function(A){jQuery.farbtastic(this,A);
return this
};
jQuery.farbtastic=function(A,B){var A=jQuery(A).get(0);
return A.farbtastic||(A.farbtastic=new jQuery._farbtastic(A,B))
};
jQuery._farbtastic=function(A,D){var B=this;
jQuery(A).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",A);
B.wheel=jQuery(".wheel",A).get(0);
B.radius=84;
B.square=100;
B.width=194;
B.firstClick=true;
if(navigator.appVersion.match(/MSIE [0-6]\./)){jQuery("*",C).each(function(){if(this.currentStyle.backgroundImage!="none"){var E=this.currentStyle.backgroundImage;
E=this.currentStyle.backgroundImage.substring(5,E.length-2);
jQuery(this).css({backgroundImage:"none",filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+E+"')"})
}})
}B.linkTo=function(E){if(typeof B.callback=="object"){jQuery(B.callback).unbind("keyup",B.updateValue)
}B.color=null;
if(typeof E=="function"){B.callback=E
}else{if(typeof E=="object"||typeof E=="string"){B.callback=jQuery(E);
B.callback.bind("keyup",B.updateValue);
if(B.callback.get(0).value){B.setColor(B.callback.get(0).value)
}}}return this
};
B.updateValue=function(E){if(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(E){if(!B.validColor.exec(E)){return this
}var F=B.unpack(E);
if(F){B.color=E;
B.rgb=F;
B.hsl=B.RGBToHSL(B.rgb);
B.updateDisplay()
}return this
};
B.setHSL=function(E){B.hsl=E;
B.rgb=B.HSLToRGB(E);
B.color=B.pack(B.rgb);
B.updateDisplay();
return this
};
B.widgetCoords=function(H){var F,L;
var G=H.target||H.srcElement;
var E=B.wheel;
if(typeof H.offsetX!="undefined"){var K={x:H.offsetX,y:H.offsetY};
var I=G;
while(I){I.mouseX=K.x;
I.mouseY=K.y;
K.x+=I.offsetLeft;
K.y+=I.offsetTop;
I=I.offsetParent
}var I=E;
var J={x:0,y:0};
while(I){if(typeof I.mouseX!="undefined"){F=I.mouseX-J.x;
L=I.mouseY-J.y;
break
}J.x+=I.offsetLeft;
J.y+=I.offsetTop;
I=I.offsetParent
}I=G;
while(I){I.mouseX=undefined;
I.mouseY=undefined;
I=I.offsetParent
}}else{var K=B.absolutePosition(E);
F=(H.pageX||0*(H.clientX+jQuery("html").get(0).scrollLeft))-K.x;
L=(H.pageY||0*(H.clientY+jQuery("html").get(0).scrollTop))-K.y
}return{x:F-B.width/2,y:L-B.width/2}
};
B.mousedown=function(E){if(!document.dragging){jQuery(document).bind("mousemove",B.mousemove).bind("mouseup",B.mouseup);
document.dragging=true
}var F=B.widgetCoords(E);
B.circleDrag=Math.max(Math.abs(F.x),Math.abs(F.y))*2>B.square;
B.mousemove(E);
return false
};
B.mousemove=function(H){var I=B.widgetCoords(H);
if(B.circleDrag){var G=Math.atan2(I.x,-I.y)/6.28;
if(G<0){G+=1
}if(B.firstClick&&(B.hsl[2]==0||B.hsl[2]==1)){B.firstClick=false;
B.setHSL([G,1,0.5])
}else{B.setHSL([G,B.hsl[1],B.hsl[2]])
}}else{var F=Math.max(0,Math.min(1,-(I.x/B.square)+0.5));
var E=Math.max(0,Math.min(1,-(I.y/B.square)+0.5));
B.setHSL([B.hsl[0],F,E])
}return false
};
B.mouseup=function(){jQuery(document).unbind("mousemove",B.mousemove);
jQuery(document).unbind("mouseup",B.mouseup);
document.dragging=false
};
B.updateDisplay=function(){var E=B.hsl[0]*6.28;
jQuery(".h-marker",C).css({left:Math.round(Math.sin(E)*B.radius+B.width/2)+"px",top:Math.round(-Math.cos(E)*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{if(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){var E=B.absolutePosition(F.offsetParent);
G.x+=E.x;
G.y+=E.y
}return G
};
B.pack=function(F){var H=Math.round(F[0]*255);
var G=Math.round(F[1]*255);
var E=Math.round(F[2]*255);
return"#"+(H<16?"0":"")+H.toString(16)+(G<16?"0":"")+G.toString(16)+(E<16?"0":"")+E.toString(16)
};
B.unpack=function(E){if(E.length==7){return[parseInt("0x"+E.substring(1,3))/255,parseInt("0x"+E.substring(3,5))/255,parseInt("0x"+E.substring(5,7))/255]
}else{if(E.length==4){return[parseInt("0x"+E.substring(1,2))/15,parseInt("0x"+E.substring(2,3))/15,parseInt("0x"+E.substring(3,4))/15]
}}};
B.HSLToRGB=function(J){var L,K,E,H,I;
var G=J[0],M=J[1],F=J[2];
K=(F<=0.5)?F*(M+1):F+M-F*M;
L=F*2-K;
return[this.hueToRGB(L,K,G+0.33333),this.hueToRGB(L,K,G),this.hueToRGB(L,K,G-0.33333)]
};
B.hueToRGB=function(F,E,G){G=(G<0)?G+1:((G>1)?G-1:G);
if(G*6<1){return F+(E-F)*G*6
}if(G*2<1){return E
}if(G*3<2){return F+(E-F)*(0.66666-G)*6
}return F
};
B.RGBToHSL=function(J){var G,L,M,H,N,F;
var E=J[0],I=J[1],K=J[2];
G=Math.min(E,Math.min(I,K));
L=Math.max(E,Math.max(I,K));
M=L-G;
F=(G+L)/2;
N=0;
if(F>0&&F<1){N=M/(F<0.5?(2*F):(2-2*F))
}H=0;
if(M>0){if(L==E&&L!=I){H+=(I-K)/M
}if(L==I&&L!=K){H+=(2+(K-E)/M)
}if(L==K&&L!=E){H+=(4+(E-I)/M)
}H/=6
}return[H,N,F]
};
jQuery("*",C).mousedown(B.mousedown);
B.setColor("#000000");
if(D){B.linkTo(D)
}};
function WikispacesImageTool(B){this.area=B;
var A=this;
this.currentPage=1;
this.currentTagPage=1;
this.selectedImage;
this.newImageIdCounter=0;
this.pageCount=1;
this.tagPageCount=1;
this.findCenteringElement=function(C){while(C){if(C.tagName&&(C.tagName.toUpperCase()=="CENTER"||(C.tagName.toUpperCase()=="DIV"&&(C.style.textAlign=="center"||C.align=="center")))){return C
}if(C.parentNode){C=C.parentNode
}else{return null
}}return null
};
this.getImageAlignment=function(D){var C=this.findCenteringElement(D);
if(C){return"center"
}return D.align
};
this.updateImageCaption=function(C){if(this.selectedImage){this.selectedImage.alt=C
}};
this.unSelectImage=function(){if(this.selectedImage){this.selectedImage=null
}this.area.editor.toolbar.imageToolbar.hideImagePropertiesPopup()
};
this.selectImage=function(C){this.unSelectImage();
this.selectedImage=C;
if(jQuery(C).is(".WikiFile")){return 
}this.area.editor.toolbar.imageToolbar.showImagePropertiesPopup();
if(this.area.editor.toolbar.imageToolbar.currentMode=="files"){this.area.editor.toolbar.imageToolbar.setListMode("images")
}this.area.editor.toolbar.imageToolbar.setImageAlignment(this.getImageAlignment(C));
this.area.editor.toolbar.imageToolbar.setImageCaption(C.alt);
if(C.parentNode.nodeName=="A"&&C.parentNode.href){this.area.editor.toolbar.imageToolbar.setImageLink(C.parentNode.href)
}else{this.area.editor.toolbar.imageToolbar.unsetImageLink()
}if(jQuery(C).is(".WikiMediaFile")){jQuery("#imageProperties .imageLink, #imageProperties .imageCaption").hide()
}else{jQuery("#imageProperties .imageLink, #imageProperties .imageCaption").show()
}};
this.setImageAlignment=function(G){if(this.selectedImage){if(G=="center"){if(this.findCenteringElement(this.selectedImage)){return 
}else{this.selectedImage.align="";
var D=this.area.getEditorWindow().document;
var C=D.createElement("div");
C.style.textAlign="center";
var F=this.selectedImage;
if(F.parentNode.nodeName=="A"){F=this.selectedImage.parentNode
}F.parentNode.appendChild(C);
F.parentNode.replaceChild(C,F);
C.appendChild(F)
}}else{var E=this.findCenteringElement(this.selectedImage);
if(E){for(i=0;
i<E.childNodes.length;
i++){E.parentNode.insertBefore(E.childNodes.item(i),E)
}E.parentNode.removeChild(E)
}this.selectedImage.align=G
}this.area.editor.toolbar.imageToolbar.showImagePropertiesPopup();
this.area.detectedChange()
}};
this.insertImageInEditor=function(D,C){if(C=="image"){WikispacesCommon.track("Editor","Add Image",D);
var E;
if(D.substring(0,"http://".length)=="http://"||D.substring(0,"https://".length)=="https://"||D.substring(0,"ftp://".length)=="ftp://"){E=D
}else{E="/file/view/"+encodeURIComponent(D)
}var F=new Image();
F.src=E;
if(this.area.editor.mode==this.area.editor.VISUAL){jQuery(F).load(function(){A.area.lookForHeightChange()
})
}jQuery(F).ready(function(){A.area.insertImageInEditorCallback(D,C,F)
})
}else{WikispacesCommon.track("Editor","Add File",D);
this.area.insertImageInEditorCallback(D,C,null)
}};
this.adjustImageSize=function(F,E,D){if(this.selectedImage){var C=jQuery(this.selectedImage);
var G=new Image();
if(G.height>0||G.width>0){this.adjustImageSizeCallback(C,G,F,E,D)
}else{jQuery(G).load(function(){A.adjustImageSizeCallback(C,G,F,E,D)
});
G.src=C.attr("src")
}}return false
};
this.adjustImageSizeCallback=function(H,J,K,F,I){var E=H.height()/J.height;
var C=H.width()/J.width;
var D;
var G;
if(F){D=J.height;
G=J.width
}else{if(I){if(J.width>800){G=800;
D=Math.round((800/J.width)*J.height)
}else{G=J.width;
D=J.height
}}else{if(K!=0){D=Math.floor(J.height*(E+K));
G=Math.floor(J.width*(C+K))
}}}if(D>0&&G>0&&D>=Math.floor(J.height*0.05)&&G>=Math.floor(J.width*0.05)){H.height(D);
H.width(G);
if(this.area.editor.mode==this.area.editor.VISUAL){this.area.lookForHeightChange()
}}if(F){jQuery(H).css("height","").css("width","");
if(H.removeAttribute){H.removeAttribute("height");
H.removeAttribute("width")
}else{H.height=undefined;
H.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(B){this.toolbar=B;
this.MAX_PER_ROW=8;
this.MAX_ROWS=8;
this.PER_PAGE=6;
this.TAG_PER_PAGE=7;
this.IMAGE_SIZE=32;
this.imageListPopupWindow;
this.imagePropertiesPopupWindow;
this.uploadPosition=0;
this.externalPosition=0;
this.currentMode="all";
this.isTagStateSet=false;
this.positionMap={};
this.reloadedSession=false;
var A=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");
A.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,true);
this.showTagPage(1)
}WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);
this.imageListPopupWindow.toFront();
this.imageListPopupWindow.showCenter();
this.positionMap={}
};
this.addPage=function(D){var C=document.createElement("a");
C.href="#";
jQuery(C).click(function(){WikispacesCommon.track("Editor","Show File Page",D);
A.showPage(D);
return false
});
jQuery(C).html(D);
jQuery(C).addClass("pageNumber");
jQuery("#imagePages").append(C).append("&nbsp;")
};
this.showPage=function(F,I){this.showFileSpinner();
var H=(F-1)*this.PER_PAGE;
var G=this.PER_PAGE;
var D="";
if(document.imageToolForm.filename.value!=document.imageToolForm.filename.title){D=document.imageToolForm.filename.value
}var C=this.getTags();
var E="/file/listjson/"+encodeURIComponent(this.currentMode)+"?offset="+encodeURIComponent(H)+"&pageLimit="+encodeURIComponent(G)+"&filename="+encodeURIComponent(D)+"&tag="+encodeURIComponent(C);
jQuery.ajaxq("imageList");
jQuery.ajaxq("imageList",{url:E,type:"GET",dataType:"json",global:false,cache:false,error:function(J,L,K){reloadSession(function(){A.showPage(F)
},3000,function(){A.toolbar.editor.sessionReloadFailed()
})
},success:function(J){reloadSessionSuccess();
A.loadFileData(J);
if(I&&J.files.length==0){A.switchToUpload()
}WikispacesToolbar.setPopupSize(A.imageListPopupWindow,true);
A.imageListPopupWindow.showCenter()
}})
};
this.showFileSpinner=function(){jQuery("#fileSpinner").show()
};
this.hideFileSpinner=function(){jQuery("#fileSpinner").hide()
};
this.startSpinner=function(){jQuery("#uploadSpinner").show()
};
this.stopSpinner=function(){jQuery("#uploadSpinner").hide()
};
this.setListMode=function(D){if(D==this.currentMode){return 
}var C=jQuery(document.forms.imageToolForm.listMode);
C.val(D);
this.currentMode=D;
this.showPage(1);
this.showTagPage(1)
};
this.getCell=function(D,C){return jQuery("#"+D+" tr").eq(Math.floor(C/this.MAX_PER_ROW)).find("td").get(C%this.MAX_PER_ROW)
};
this.addNewFile=function(D,C){WikispacesCommon.track("Editor","Upload File",D);
this.addFileCell("uploadTable",D,C,this.uploadPosition++);
this.switchToUpload()
};
this.addRow=function(C){var D=document.createElement("tr");
for(j=0;
j<this.MAX_PER_ROW;
j++){D.appendChild(document.createElement("td"))
}jQuery("#"+C).append(D)
};
this.addFileRow=function(G,I,H,E){var F;
var D=I;
if(H=="image"||this.isImage(H)){F="image";
if(E){D=E
}}else{if(this.isAudio(H)){F="audio"
}else{if(this.isVideo(H)){F="video"
}else{F="file"
}}}li1=jQuery("<li>").attr("title",I).addClass("active").click(function(){A.toolbar.editor.getCurrentArea().imageTool.insertImageInEditor(D,F);
A.imageListPopupWindow.close()
});
var C=document.createElement("img");
if(F=="image"){if(E){C.src=E;
if(C.height>C.width){C.width=C.width/C.height*A.IMAGE_SIZE;
C.height=A.IMAGE_SIZE
}else{C.height=C.height/C.width*A.IMAGE_SIZE;
C.width=A.IMAGE_SIZE
}}else{C.src="/file/thumbnail/"+encodeURIComponent(I)+"?size="+A.IMAGE_SIZE;
C.width=A.IMAGE_SIZE;
C.height=A.IMAGE_SIZE
}}else{this.loadMimeImage(C,H)
}C.onmousedown=function(){return false
};
jQuery(li1).append(C).append(I);
jQuery(document.insertFile).find(".fileList ul").append(li1)
};
this.addFileCell=function(G,J,E,L,D,K){var F=G+"-file-"+L;
var O=this.getCell(G,L);
if(!O){this.addRow(G);
WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);
O=this.getCell(G,L)
}var M;
var I=J;
if(E=="image"||this.isImage(E)){M="image";
if(D){I=D
}}else{if(this.isAudio(E)){M="audio"
}else{if(this.isVideo(E)){M="video"
}else{M="file"
}}}var H=document.createElement("td");
H.style.textAlign="center";
H.style.padding="5px;";
H.title=J;
jQuery(H).dblclick(function(){A.toolbar.editor.getCurrentArea().imageTool.insertImageInEditor(I,M);
A.imageListPopupWindow.close()
});
if(!K){K=document.createElement("img")
}if(M=="image"){if(D){K.src=D;
if(K.height>K.width){K.width=K.width/K.height*A.IMAGE_SIZE;
K.height=A.IMAGE_SIZE
}else{K.height=K.height/K.width*A.IMAGE_SIZE;
K.width=A.IMAGE_SIZE
}}else{K.src="/file/thumbnail/"+encodeURIComponent(J)+"?size="+A.IMAGE_SIZE;
K.width=A.IMAGE_SIZE;
K.height=A.IMAGE_SIZE
}}else{this.loadMimeImage(K,E)
}K.onmousedown=function(){return false
};
var C=document.createElement("div");
C.className="WikiUploadFileEditor";
C.appendChild(K);
H.appendChild(C);
var N=jQuery("<span>").attr("id",F).text(WikispacesCommon.truncate(J,10));
jQuery(C).append("<br/>").append(N);
O.parentNode.replaceChild(H,O)
};
this.addMultiUploadFileCell=function(F,G,D,K){var E=G.id;
var J=G.name;
var M=this.getCell(F,K);
if(!M){this.addRow(F);
WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);
M=this.getCell(F,K)
}A.positionMap[E]=K;
var L;
var I=J;
if(D=="image"||this.isImage(D)){L="image"
}else{if(this.isAudio(D)){L="audio"
}else{if(this.isVideo(D)){L="video"
}else{L="file"
}}}var H=document.createElement("td");
H.style.textAlign="center";
H.style.padding="5px;";
H.title=J;
jQuery(H).dblclick(function(){A.toolbar.editor.getCurrentArea().imageTool.insertImageInEditor(I,L);
A.imageListPopupWindow.close()
});
img=document.createElement("img");
img.width=A.IMAGE_SIZE;
img.height=A.IMAGE_SIZE;
img.id="swfu_file_"+E+"_"+K;
img.onmousedown=function(){return false
};
var C=document.createElement("div");
C.className="WikiUploadFileEditor";
C.appendChild(img);
H.appendChild(C);
jQuery(C).append('<br/><span id="'+E+'">'+WikispacesCommon.truncate(J,10)+'</span><div class="shortProgressContainer"><div class="progressBar" id="'+E+'progress"></div></div>');
M.parentNode.replaceChild(H,M)
};
this.addFileError=function(C){alert(C)
};
this.resetPages=function(){var I=7;
var J=1;
jQuery("#imagePages").empty();
var G=1;
var E=this.pageCount;
if(this.pageCount>I){G=this.currentPage-J;
if(G<1){G=1
}E=G+J;
if(E>this.pageCount){E=this.pageCount
}}var H=1+E-G+(E==this.pageCount?0:1)+(G==1?0:1);
var F=0;
while(H<I&&(G!=1||E!=this.pageCount)){if(F%2){G--;
if(G<1){G=1
}}else{E++;
if(E>this.pageCount){E=this.pageCount
}}F++;
H=1+E-G+(E==this.pageCount?0:1)+(G==1?0:1)
}if(this.pageCount>1){if(this.currentPage==1){jQuery("#imagePages").append('<span class="pageFirst inactive">&laquo; Previous</span>')
}else{var D=jQuery('<a href="#" class="pageFirst">&laquo; Previous</a>').click(function(){A.showPage(A.currentPage-1)
});
jQuery("#imagePages").append(D)
}if(G>1){this.addPage(1);
if(G>2){jQuery("#imagePages").append(" ... ")
}}for(F=G;
F<=E;
F++){this.addPage(F)
}if(this.pageCount>E){if(E+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{var C=jQuery('<a href="#">Next &raquo;</a>').click(function(){A.showPage(A.currentPage+1)
});
jQuery("#imagePages").append(C)
}}};
this.loadFileData=function(F){jQuery(document.imageToolForm).find(".fileList ul").empty();
var E=0;
jQuery.each(F.files,function(G,H){A.addFileRow("imageTable",H.f_name,H.r_mime_type);
E++
});
if(!E){var D=jQuery("<li>").text("No files found").addClass("nodata");
jQuery(document.insertFile).find(".fileList ul").append(D);
E++
}while(E<this.PER_PAGE){var D=document.createElement("li");
var C=document.createElement("img");
C.src="/i/c.gif";
C.height=A.IMAGE_SIZE;
C.width=A.IMAGE_SIZE;
D.appendChild(C);
D.appendChild(document.createTextNode(" "));
jQuery(document.insertFile).find(".fileList ul").append(D);
E++
}this.pageCount=F.pagedata.numpages;
this.currentPage=F.pagedata.current;
this.resetPages();
this.highlightPage(this.currentPage);
this.hideFileSpinner()
};
this.highlightPage=function(D){var C=jQuery("#imagePages a.pageNumber").each(function(){if(jQuery(this).html()==D){jQuery(this).addClass("pageCurrent")
}else{jQuery(this).removeClass("pageCurrent")
}})
};
this.showLastPage=function(){this.showPage(this.pageCount)
};
this.externalImageOnloadCallback=function(E){if(E.height==0){alert("The external image could not be found.");
return 
}var C=E.src;
var D=C.match(/.*\/([^\/\?]+)/);
if(D.length==2){var F=D[1];
this.addFileCell("externalTable",F,"image",this.externalPosition++,C,E)
}};
this.showExternalImage=function(){var C=document.getElementById("externalImageUrl").value;
if(!C){alert("Please enter the address of an external image.");
return 
}var D=new Image();
jQuery(D).one("load",function(){A.externalImageOnloadCallback(D)
});
jQuery(D).one("error",function(){alert("The external image could not be found.")
});
D.src=C
};
this.loadMimeImage=function(C,E){var D=new Image();
D.src="/i/mime/"+A.IMAGE_SIZE+"/"+E+".png";
if(D.height>0){C.src=D.src
}else{C.src="/i/mime/"+A.IMAGE_SIZE+"/empty.png"
}C.width=A.IMAGE_SIZE;
C.height=A.IMAGE_SIZE
};
this.showTagPage=function(E){this.showFileSpinner();
var G=(E-1)*this.TAG_PER_PAGE;
var F=this.TAG_PER_PAGE;
var C=this.getTags();
var D="/tag/listjson/"+encodeURIComponent(this.currentMode)+"?offset="+encodeURIComponent(G)+"&pageLimit="+encodeURIComponent(F)+"&tag="+encodeURIComponent(C);
jQuery.ajaxq("tagList");
jQuery.ajaxq("tagList",{url:D,type:"GET",dataType:"json",global:false,cache:false,error:function(H,J,I){reloadSession(function(){A.showPage(E)
},3000,function(){A.toolbar.editor.sessionReloadFailed()
})
},success:function(H){reloadSessionSuccess();
A.loadTagData(H);
WikispacesToolbar.setPopupSize(A.imageListPopupWindow,true);
A.imageListPopupWindow.showCenter()
}})
};
this.addTag=function(D){var C=jQuery("<li>");
C.attr("title",D).html(WikispacesCommon.truncate(D,25)+'<a class="closebutton" href="#"></a>').addClass("bit-box");
C.find("a").click(function(){A.removeTag(this)
});
jQuery("#tagFilterActive").show().append(C);
A.showTagPage(1);
A.showPage(1)
};
this.removeTag=function(C){jQuery(C).parent().remove();
A.showTagPage(1);
A.showPage(1);
if(!jQuery("#tagFilterActive li").length){jQuery("#tagFilterActive").hide()
}};
this.getTags=function(){var C="";
jQuery("#tagFilterActive li").each(function(){C+=","+jQuery(this).attr("title")
});
C=C.substring(1);
return C
};
this.loadTagData=function(D){if(D.tags.length){if(!A.isTagStateSet){jQuery("#imageDivTable .filterTagSection").show()
}jQuery("#tagFilterList").empty().show()
}else{if(!A.isTagStateSet){jQuery("#imageDivTable .filterTagSection").hide()
}else{jQuery("#tagFilterList").empty().hide()
}}A.isTagStateSet=true;
jQuery.each(D.tags,function(F,G){var E=jQuery("<li>");
E.attr("title",G.t_name).html(WikispacesCommon.truncate(G.t_name,25)+" ("+G.t_number+")").click(function(){A.addTag(G.t_name)
});
jQuery("#tagFilterList").append(E)
});
this.tagPageCount=D.pagedata.numpages;
this.currentTagPage=D.pagedata.current;
if(this.currentTagPage!=1){var C=jQuery('<li class="upTagPageLink"></li>');
C.click(function(){A.showTagPage(A.currentTagPage-1)
});
jQuery("#tagFilterList").prepend(C)
}if(this.currentTagPage!=this.tagPageCount){var C=jQuery('<li class="downTagPageLink"></li>');
C.click(function(){A.showTagPage(A.currentTagPage+1)
});
jQuery("#tagFilterList").append(C)
}this.hideFileSpinner()
};
this.setup=function(){for(i=0;
i<this.MAX_ROWS;
i++){this.addRow("uploadTable");
this.addRow("externalTable")
}WIKISPACES.common.setInputDefaults(jQuery("#imageDivTable .fileNameField"),"searchDefault");
jQuery(document.imageToolForm.listMode).change(function(){A.setListMode(jQuery(this).val())
});
if(!wikispaces_isUserLoggedIn){jQuery("#imageUploadDiv").html("<p>You must sign in to upload files.</p>")
}else{jQuery("#imageUploadDiv form").submit(function(){A.startSpinner()
})
}jQuery("#externalImageDiv form").submit(function(){A.showExternalImage();
return false
});
jQuery("#imageDiv .tabs .tab").each(function(F,G){switch(F%3){case 0:jQuery(this).click(function(){A.switchToFile();
return false
});
break;
case 1:jQuery(this).click(function(){A.switchToUpload();
return false
});
break;
case 2:jQuery(this).click(function(){A.switchToExternal();
return false
});
break
}});
jQuery(document.imageToolForm).submit(function(F){F.preventDefault()
});
jQuery(document.imageToolForm.filename).keyup(function(){A.showPage(1);
A.showTagPage(1)
});
jQuery(document.imageToolForm.tag).keypress(function(F){if(F.keyCode==13){A.showPage(1);
A.showTagPage(1)
}});
WikispacesAutocomplete.initAutocomplete(jQuery("#imageDiv").get(0));
jQuery("#imageDiv").find(".autocompleteSpace, .autocompleteTag, .autocompletePage").each(function(){WikispacesAutocomplete.initAutocomplete(this);
if(jQuery(this).is(".autocompleteTag")){var F=this.autocompleter.options.onItemSelect;
this.autocompleter.options.onItemSelect=function(H,G){F.call(this,H,G);
A.addTag(jQuery(G).find(".autocompleteId").html());
jQuery(H.input).val("")
}
}});
if(-1!=navigator.platform.indexOf("Mac")){jQuery("#ctrlKeyName").html("&#8984;")
}jQuery("#cancelQueueBtn").attr("disabled",true);
try{var D=new WikispacesCommon.swfUpload(this.toolbar.editor.uploadUrl,this.toolbar.editor.maxFileSize);
D.swfu.queueSettings.user_upload_complete_handler=function(F){this.requireRefresh=true;
var G=jQuery("<iframe>").hide().load(function(){var H=F.name;
if(A.isImageFilename(F.name)){H=F.name.replace(/\s/g,"_")
}jQuery("#swfu_file_"+F.id+"_"+A.positionMap[F.id]).attr("src","/file/thumbnail/"+encodeURIComponent(H)+"?size="+A.IMAGE_SIZE);
jQuery("#"+F.id+".fileUploading").removeClass("fileUploading").addClass("uploadCompleted").attr("id","");
jQuery("#"+F.id+"progress").fadeOut().attr("id","");
A.showPage(1,false)
});
jQuery("body").append(G);
G.attr("src",this.customSettings.confirmUploadUrl);
return true
};
D.swfu.settings.file_queued_handler=function(F){var H="application/octet-stream";
var G=F.name;
if(A.isImageFilename(F.name)){H="image";
F.name=F.name.replace(/\s/g,"_")
}A.addMultiUploadFileCell("uploadTable",F,H,A.uploadPosition++);
jQuery("#cancelQueueBtn").attr("disabled",false)
};
D.swfu.settings.queue_complete_handler=function(F){jQuery("#cancelQueueBtn").attr("disabled",true)
};
var C=D.swfu.settings.swfupload_load_failed_handler;
D.swfu.settings.swfupload_load_failed_handler=function(){jQuery("#switchToSingleUpload").hide();
C.call(this)
};
jQuery("#cancelQueueBtn").click(function(){D.swfu.cancelQueue();
jQuery(this).attr("disabled",true)
});
jQuery("#switchToSingleUpload").click(function(F){D.hideSWFUploadUI();
jQuery(this).hide();
F.preventDefault()
})
}catch(E){}};
this.switchToFile=function(){WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);
jQuery("#imageDiv .styleFile").show();
jQuery("#imageDiv .styleExternal").hide();
jQuery("#imageDiv .styleUpload").hide()
};
this.switchToExternal=function(){WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);
jQuery("#imageDiv .styleFile").hide();
jQuery("#imageDiv .styleExternal").show();
jQuery("#imageDiv .styleUpload").hide()
};
this.switchToUpload=function(){WikispacesToolbar.setPopupSize(this.imageListPopupWindow,true);
jQuery("#imageDiv .styleFile").hide();
jQuery("#imageDiv .styleExternal").hide();
jQuery("#imageDiv .styleUpload").show();
if(!this.reloadedSession){reloadSessionAt(0);
this.reloadedSession=true
}};
this.isImage=function(C){if(C=="image/png"||C=="image/x-png"||C=="image/jpeg"||C=="image/gif"||C=="image/jpg"||C=="image/pjpeg"){return true
}else{return false
}};
this.isImageFilename=function(C){return C.match(/.*\.(?:gif|jpg|jpeg|png)$/i)
};
this.isMedia=function(C){return this.isAudio(C)||this.isVideo(C)
};
this.isAudio=function(C){switch(C){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;
break
}return false
};
this.isVideo=function(C){switch(C){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;
break
}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 C=jQuery(this.toolbar.editor.getCurrentArea().imageTool.selectedImage);
var D=new Image();
D.src=C.attr("src");
if(D.height>0||D.width>0){this.toggleFitImage(C);
this.adjustImagePropertiesPopup()
}else{jQuery(D).load(function(){A.toggleFitImage(C);
A.adjustImagePropertiesPopup()
})
}};
this.adjustImagePropertiesPopup=function(){WikispacesToolbar.setPopupSize(this.imagePropertiesPopupWindow);
var C=this.toolbar.getPositionWith(this.imagePropertiesPopupWindow.element,this.toolbar.editor.getCurrentArea().imageTool.selectedImage);
this.imagePropertiesPopupWindow.setLocation(C.top-10,C.left-10)
};
this.setupProperties=function(){jQuery("#imageAlign").click(function(){A.toolbar.editor.getCurrentArea().imageTool.setImageAlignment(jQuery(this).val())
});
jQuery("#changeLink").click(function(){A.toolbar.linkToolbar.openLinkPopup();
return false
});
jQuery("#removeLink").click(function(){var C=A.toolbar.editor.getCurrentArea().imageTool.selectedImage;
jQuery(C).parent("a").replaceWith(jQuery(C).parent("a").contents());
A.toolbar.editor.getCurrentArea().imageTool.selectImage(C);
return false
});
jQuery("#addLink").click(function(){A.toolbar.linkToolbar.openLinkPopup();
return false
});
jQuery("#imageSizeDown").click(function(){A.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(-0.1);
return false
});
jQuery("#imageSizeUp").click(function(){A.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(0.1);
return false
});
jQuery("#imageSizeOriginal").click(function(){A.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(0,true);
return false
});
jQuery("#imageSizeFit").click(function(){A.toolbar.editor.getCurrentArea().imageTool.adjustImageSize(0,false,true);
return false
});
jQuery("#imageCaptionInput").keyup(function(){A.toolbar.editor.getCurrentArea().imageTool.updateImageCaption(this.value)
});
jQuery("#imageCaptionInput").change(function(){A.toolbar.editor.getCurrentArea().imageTool.updateImageCaption(this.value)
});
jQuery("#imageRemoveLink").click(function(){A.toolbar.editor.getCurrentArea().imageTool.removeImage();
return false
})
};
this.toggleFitImage=function(C){if(C.width>800){jQuery("#imageSizeFit").show()
}else{jQuery("#imageSizeFit").hide()
}};
this.hideImagePropertiesPopup=function(){if(this.imagePropertiesPopupWindow){this.imagePropertiesPopupWindow.hide()
}};
this.setImageLink=function(C){jQuery("#imageLink").html(C).attr("title",C);
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(C){jQuery("#imageCaptionInput").val(C)
};
this.setImageAlignment=function(C){jQuery("#imageAlign").val(C)
}
}function WikispacesInlineEditor(A,E,B,F){this.stylesheetUrl=A;
this.cancelUrl=E;
this.uploadUrl=B;
this.maxFileSize=F;
this.autosaveDetected=false;
this.checkoutStatus="";
this.checkoutUser="";
this.checkoutMessage="";
var D=this;
var C;
this.disableEditButton=function(G){if(G.className=="WikiPageMenuEditButton"){G.className="WikiPageMenuEditButtonDisabled"
}jQuery(G).unbind("click",C);
G.style.cursor="default";
G.href="#";
return true
};
this.enableEditButton=function(G,H){log("enabledEditButton",G,H);
if(G.className=="WikiPageMenuEditButtonDisabled"){G.className="WikiPageMenuEditButton"
}G.style.cursor="pointer";
G.href="/page/edit/"+encodeURIComponent(wikispaces_page);
C=function(K){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")
}D.disableEditButton(G);
var J=new WikispacesEditor("visual",D.stylesheetUrl,D.cancelUrl,D.uploadUrl,D.maxFileSize);
var I=J.createArea(H);
I.autosaveEnabled=wikispaces_isUserLoggedIn;
D.editorEnable(I);
K.preventDefault()
}catch(L){log(L);
G.href="/page/edit/"+encodeURIComponent(wikispaces_page);
D.redirectToEditPage(false);
return true
}};
jQuery(G).click(C)
};
this.editorEnable=function(I){log("editorEnable",I);
if(jQuery.browser.opera){this.redirectToEditPage(true);
return 
}try{var G="/page/dump/"+encodeURIComponent(wikispaces_page)+"?format=Wikispaces2";
var H=this;
jQuery.ajax({url:G,type:"GET",timeout:2000,global:false,error:function(M,L,K){H.redirectToEditPageCallback(M,L,K)
},success:function(K){H.editorEnableCallback(I,K)
}})
}catch(J){this.redirectToEditPage(false)
}};
this.redirectToEditPageCallback=function(I,H,G){log("redirectToEditPageCallback",H,G);
this.redirectToEditPage(false)
};
this.redirectToEditPage=function(G){log("redirectToEditPage");
document.location="/page/edit/"+encodeURIComponent(wikispaces_page)+(G?"?texteditor=1":"")
};
this.editorEnableCallback=function(H,G){log("editorEnableCallback");
if(this.loadXMLData(H,G)){if(this.checkoutStatus=="locked"&&(!wikispaces_isUserLoggedIn||this.checkoutUser!=wikispaces_username)){alert(this.checkoutMessage);
this.enableEditButton(document.getElementById("editButton"));
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,M){log("loadXMLData");
try{var J=M.getElementsByTagName("dump")[0].getElementsByTagName("content")[0];
var G="";
if(J){for(var L=0;
L<J.childNodes.length;
L++){G+=J.childNodes[L].nodeValue
}}else{return false
}var Q=M.getElementsByTagName("dump")[0].getElementsByTagName("version")[0];
if(Q&&Q.firstChild){H.version=Q.firstChild.nodeValue
}var T=M.getElementsByTagName("dump")[0].getElementsByTagName("editorCleanup")[0];
if(T&&T.firstChild){H.editorCleanup=T.firstChild.nodeValue
}if(G){document.getElementById("WikispacesEditorContentHidden").innerHTML=G
}this.checkoutStatus=M.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutStatus")[0].firstChild.nodeValue;
if(this.checkoutStatus=="locked"){this.checkoutUser=M.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutUser")[0].firstChild.nodeValue;
var I=M.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutDate")[0].firstChild.nodeValue;
var P=M.getElementsByTagName("checkout")[0].getElementsByTagName("checkoutRefreshDate")[0].firstChild.nodeValue;
this.checkoutMessage="This page was locked for editing by "+this.checkoutUser+" on "+I+".  The page will be available for editing after the changes have been saved."
}if(M.getElementsByTagName("dump")[0].getElementsByTagName("autosave").length>0){var K=M.getElementsByTagName("dump")[0].getElementsByTagName("autosave")[0];
var S=K.getElementsByTagName("autosaveContent")[0];
var O="";
if(S&&S.childNodes.length>0){for(var L=0;
L<S.childNodes.length;
L++){O+=S.childNodes[L].nodeValue
}}var R=K.getElementsByTagName("autosaveDate")[0].firstChild.nodeValue;
H.autosaveVersion=K.getElementsByTagName("autosaveVersion")[0].firstChild.nodeValue;
H.autosaveCleanup=K.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 '+R+".</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(O);
this.autosaveDetected=true
}return true
}catch(N){log(N);
return false
}}
}WikispacesInlineEditor.libsLoaded=false;
function WikispacesLinkTool(B){this.area=B;
var A=this;
this.addLink=function(L){var P=document.linkForm["linkText"+L].value;
if(L=="Anchor"){if(P.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@@'+P+'" title="Anchor: '+P+'"/>');
jQuery(this.area.getEditorWindow().document.body).find("#wikitext@@anchor@@"+P).ready(function(){A.area.lookForHeightChange()
})
}else{this.area.insertInEditor("[[#"+P+"]]")
}WikispacesCommon.track("Editor","Add Anchor",G);
return true
}else{alert("Please correct the anchor name error before continuing");
return false
}}var G=document.linkForm.url.value;
var D=document.linkForm.space.value;
var J=document.linkForm.anchor.value;
var H=document.linkForm.pageName.value;
var O=document.linkForm["newWindow"+L].checked;
if(L=="Wiki"){var Q="";
Q=H;
if(D==""||Q==""){alert("Please enter a wiki and page name");
return false
}if(J!=""){J="#"+J
}if(D==wikispaces_spaceName){G="/"+encodeURIComponent(Q)+J
}else{G="http://"+D+"."+wikispaces_domain+"/"+encodeURIComponent(Q)+J
}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(G==""){alert("Please enter a URL");
return false
}else{if(!G.match(/^(?:[a-zA-Z0-9.+-]+:\/\/|mailto:)/)){if(G.indexOf("@")>0){G="mailto:"+G
}else{G="http://"+G
}}}}if(this.linkTextFailure){alert("Please correct the link text error before continuing");
return false
}var C=this.area.imageTool.selectedImage;
if(C&&C.parentNode&&C.src){var I=this.area.getEditorWindow();
if(C.parentNode.nodeName=="A"){C.parentNode.setAttribute("href",G);
if(O){C.parentNode.setAttribute("target","_blank")
}else{C.parentNode.removeAttribute("target")
}}else{newA=I.document.createElement("a");
newA.setAttribute("href",G);
if(O){newA.setAttribute("target","_blank")
}C.parentNode.appendChild(newA);
C.parentNode.replaceChild(newA,C);
newA.appendChild(C)
}this.area.imageTool.selectImage(C);
WikispacesCommon.track("Editor","Add Link",G)
}else{var F="";
if(jQuery.trim(P)==""){alert("Please enter text for the link");
return false
}while(P.charAt(P.length-1)==" "){P=P.slice(0,P.length-1);
F+=" "
}if(this.area.editor.mode==this.area.editor.VISUAL){var M="wiki_link";
if(L=="External"){M="wiki_link_ext"
}if(jQuery.browser.msie||jQuery.browser.safari){var E="";
if(O){E=' target="_blank"'
}var K='<a href="'+G+'" class="'+M+'"'+E+">"+P+"</a>"+F;
if(jQuery.browser.safari){K+=" "
}this.area.insertInEditor(K);
WikispacesCommon.track("Editor","Add Link",G)
}else{var I=this.area.getEditorWindow();
a=I.document.createElement("a");
a.setAttribute("href",G);
a.setAttribute("class",M);
if(O){a.setAttribute("target","_blank")
}t1=I.document.createTextNode(P);
a.appendChild(t1);
this.area.insertNodeAtSelection(I,a);
if(""!=F){t2=I.document.createTextNode(F);
this.area.insertNodeAtSelection(I,t2)
}WikispacesCommon.track("Editor","Add Link",G);
I.focus()
}this.area.attachDoubleClickEventHandlers(document.getElementById("WikispacesEditorContent").contentWindow.document)
}else{var E="";
if(O){E="@"
}if(L=="Wiki"){var N=(D==wikispaces_spaceName?"":D+":")+Q;
this.area.insertInEditor("[["+E+N+(J?J:"")+(P==N?"":"|"+P)+"]] ");
WikispacesCommon.track("Editor","Add Link",D+":"+N)
}else{this.area.insertInEditor("[["+E+G+(G==P?"":"|"+P)+"]] ");
WikispacesCommon.track("Editor","Add Link",G)
}}}return true
}
}function WikispacesLinkToolbar(B){this.toolbar=B;
var A=this;
this.tabClicked=false;
this.linkTextChanged=false;
this.anchorFailure=false;
this.pageNameFailure=false;
this.linkTextFailure=false;
this.linkType="Wiki";
this.tooManyPages=false;
this.linkPopupWindow;
this.openLinkPopup=function(){WikispacesCommon.track("Editor","Open Link Tool");
var L=false;
this.toolbar.editor.getCurrentArea().saveCursor();
WindowUtilities.disableScreen("wikispaces","overlay_modal",0);
if(!this.linkPopupWindow){L=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");
A.toolbar.editor.getCurrentArea().restoreCursor();
A.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 S="";
var E="";
var J="";
var K="";
var M="";
var R=false;
this.linkTextChanged=false;
this.anchorFailure=false;
this.pageNameFailure=false;
this.linkTextFailure=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();
if(!this.tooManyPages){this.switchToSelect()
}jQuery("#linkDiv div.linkToolInputError").hide();
var W=this.toolbar.editor.getCurrentArea();
W.saveCursor();
jQuery("#linkDiv #removeExistingLink").hide();
if(this.toolbar.editor.mode==this.toolbar.editor.VISUAL){var N=W.selectParent("A");
var P=this.toolbar.editor.getCurrentArea().imageTool.selectedImage;
if(!(P&&P.parentNode&&P.src)){S=W.getSelectedText()
}if(N){var F=N.getAttribute("href",2)+"";
F=F.replace(/^(..\/)+/,"/");
var C=new RegExp("");
C.compile("^http[s]?://([a-z0-9-]+).("+wikispaces_domain.replace(".",".")+")/([^#/]+)(#(.+)){0,1}$","gi");
var V=new RegExp("");
V.compile("^http[s]?://("+location.hostname.replace(".",".")+")/([^#/]+)(#(.+)){0,1}$","gi");
var G=new RegExp("");
G.compile("^/([^#]+)(#(.+)){0,1}$","i");
var I=new RegExp("");
I.compile("^(?:[a-zA-Z0-9.+-]+://|mailto:).*","i");
var D=C.exec(F);
var Q=V.exec(F);
var T=G.exec(F);
var O=I.exec(F);
if(D){E=D[1];
J=D[3];
K=(D[5])?D[5]:""
}else{if(Q){E="";
J=Q[2];
K=(Q[4])?Q[5]:""
}else{if(T){E="";
J=T[1];
K=(T[3])?T[3]:""
}else{if(O){M=O[0]
}}}}if(N.target){R=true
}if(J){J=decodeURIComponent(J);
J=J.replace(/\+/g," ")
}if(K){K=decodeURIComponent(K);
K=K.replace(/\+/g," ")
}jQuery("#linkDiv #removeExistingLink").show()
}}else{var H;
var U=W.getSelectedText();
if(U){if(H=U.match(/^\[\[(@)?((?:[a-zA-Z0-9.+-]+:\/\/|mailto:).*?)(?:\|(.*))?\]\]$/i)){if(H[1]){R=H[1]
}if(H[2]){M=H[2]
}if(H[3]){S=H[3]
}jQuery("#linkDiv #removeExistingLink").show()
}else{if(H=U.match(/\[\[(@)?(?:([a-z0-9-]+):)?([^:|\/\[\]\{\}\$#@\\]+)(?:\#([A-Za-z][-A-Za-z0-9_ ]*))?(?:\|([^\[\]\xff]+))?\]\]/)){if(H[1]){R=H[1]
}if(H[2]){E=H[2]
}if(H[3]){J=H[3]
}if(H[4]){K=H[4]
}if(H[5]){S=H[5]
}if(!S){if(E&&E!=wikispaces_spaceName){S=E+" : "+J
}else{S=J
}}jQuery("#linkDiv #removeExistingLink").show()
}else{S=U
}}}}var P=this.toolbar.editor.getCurrentArea().imageTool.selectedImage;
if(P&&P.parentNode&&P.src){jQuery("#linkDiv .trText").hide()
}else{jQuery("#linkDiv .trText").show()
}this.setupForms(S,M,E,J,K,R);
if(L==true){this.loadPages(S,M,E,J,K,R)
}WikispacesToolbar.setPopupSize(this.linkPopupWindow,true);
this.linkPopupWindow.toFront();
this.linkPopupWindow.showCenter()
};
this.openAnchor=function(C){this.openLinkPopup();
var D=C.id.match(/wikitext@@anchor@@(.*)/);
if(D&&D[1]){jQuery("#linkTextAnchor").val(D[1]);
this.clickAnchorLink()
}};
this.changeSpaceName=function(D){var C=jQuery("input#pageName").get(0).autocompleter;
C.setExtraParams({space:D});
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(H,G,D,C,E,F){jQuery.ajax({async:true,cache:true,dataType:"xml",global:false,error:function(I,K,J){log("load page list ajax error",I,K,J);
reloadSession(function(){A.loadPages(H,G,D,C,E,F)
},3000,function(){A.disableSelect();
A.setupForms(H,G,D,C,E,F);
A.toolbar.editor.sessionReloadFailed()
})
},success:function(L,N){log("load page list ajax success",L);
reloadSessionSuccess();
if(L.getElementsByTagName("tooMany")[0]){A.disableSelect()
}else{A.switchToSelect();
var K=L.getElementsByTagName("page");
var M="";
for(var J=0;
J<K.length;
J++){var I=K[J].childNodes[0].nodeValue;
M+='<option value="'+I+'">'+WikispacesCommon.truncate(I,40)+"</option>"
}jQuery("#pageNameSelect").append(M)
}A.setupForms(H,G,D,C,E,F)
},type:"GET",url:"/space/pagelistajax/"})
};
this.disableSelect=function(){this.tooManyPages=true;
jQuery("#switchToPage").hide();
this.switchToAutocomplete()
};
this.setupForms=function(H,G,D,C,E,F){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(H){document.linkForm.linkTextWiki.value=H;
document.linkForm.linkTextExternal.value=H;
jQuery(document.linkForm.linkTextWiki).change();
if(H.indexOf("@")>0||H.match(/^(?:[a-zA-Z0-9.+-]+:\/\/|mailto:|www.)/)){this.clickExternalLink(true);
document.linkForm.url.value=jQuery.trim(H)
}else{document.linkForm.pageName.value=jQuery.trim(H);
jQuery(document.linkForm.pageNameSelect).val(jQuery.trim(H));
if(jQuery(document.linkForm.pageNameSelect).val()==jQuery.trim(H)){this.switchToSelect()
}else{this.switchToAutocomplete()
}}this.linkTextChanged=true
}document.linkForm.newWindowWiki.checked=F;
document.linkForm.newWindowExternal.checked=F;
if(""!=C){if(""==D){document.linkForm.space.value=wikispaces_spaceName
}else{document.linkForm.space.value=D
}document.linkForm.pageName.value=C;
jQuery(document.linkForm.pageNameSelect).val(C);
if(jQuery(document.linkForm.pageNameSelect).val()==C){this.switchToSelect()
}else{this.switchToAutocomplete()
}if(""!=E){document.linkForm.anchor.value=E;
jQuery(document.linkForm.anchor).change();
this.showAnchor()
}this.clickWikiLink(true)
}else{if(G!=""){document.linkForm.url.value=G;
this.clickExternalLink(true)
}}if(document.linkForm.pageName.value){setTimeout(function(){document.linkForm.pageName.autocompleter.findValue()
},10)
}};
this.checkPageName=function(F){var D=document.getElementById("pageNameError");
var C=F.value;
this.pageNameFailure=/^\.\.?\s*$/.test(C);
if(this.pageNameFailure){D.innerHTML="Wiki page names cannot be . or ..";
D.style.display="block";
return this.pageNameFailure
}var E=/[\[\]:|\/{}$\"#@+]/;
this.pageNameFailure=E.test(C);
if(this.pageNameFailure){D.innerHTML='Wiki page names cannot contain: [ ] : | / { } $ + " # @';
D.style.display="block";
return this.pageNameFailure
}if(C.length>255){this.pageNameFailure=true;
D.innerHTML="Wiki page name cannot be more than 255 characters";
D.style.display="block";
return this.pageNameFailure
}D.innerHTML="";
D.style.display="none";
return this.pageNameFailure
};
this.checkLinkText=function(D){var C=jQuery("#linkDiv div.linkTextError");
var E=new RegExp();
E.compile("]]|]$");
this.linkTextFailure=E.test(D.value);
if(this.linkTextFailure){C.each(function(){this.innerHTML="Link text must not end with ] or contain ]]"
});
C.show()
}else{C.each(function(){this.innerHTML=""
});
C.show()
}};
this.checkAnchor=function(G){var E=jQuery(G).nextAll(".linkToolInputError:first");
var C=document.getElementById("anchorError");
var D=new RegExp();
D.compile("^[^a-zA-Z]");
this.anchorFailure=D.test(G.value);
if(this.anchorFailure){E.html("Anchor text must start with a letter").show();
return 
}var F=/[\[\]:|\/{}$\"#@+]/;
this.anchorFailure=F.test(G.value);
if(this.anchorFailure){E.html('Anchors cannot contain: [ ] : | / { } $ + " # @').show();
return 
}E.html("").hide()
};
this.clickWikiLink=function(C){if(this.tabClicked&&C){return 
}if(!C){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();
if(jQuery("#linkTextExternal").val()){jQuery("#linkTextWiki").val(jQuery("#linkTextExternal").val())
}document.linkForm.newWindowWiki.checked=document.linkForm.newWindowExternal.checked;
jQuery("#linkTextWiki").focus()
};
this.clickExternalLink=function(C){if(this.tabClicked&&C){return 
}if(!C){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();
if(jQuery("#linkTextWiki").val()){jQuery("#linkTextExternal").val(jQuery("#linkTextWiki").val())
}document.linkForm.newWindowExternal.checked=document.linkForm.newWindowWiki.checked;
jQuery("#url").focus()
};
this.clickAnchorLink=function(C){if(this.tabClicked&&C){return 
}if(!C){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();
if(!document.linkForm.anchor.disabled){document.linkForm.anchor.focus()
}};
this.syncLinkText=function(C){if(!this.checkPageName(C)&&!this.linkTextChanged){jQuery(document.linkForm.linkTextWiki).val(jQuery(C).val());
jQuery(document.linkForm.linkTextExternal).val(jQuery(C).val())
}};
this.setup=function(){jQuery("#linkDiv").find(".autocompleteSpace, .autocompleteTag, .autocompletePage").each(function(){WikispacesAutocomplete.initAutocomplete(this)
});
jQuery("#pageNameSelect").change(function(){if(jQuery(this).val()=="@@"){A.switchToAutocomplete()
}else{jQuery(document.linkForm.pageName).val(jQuery(this).val()).change()
}});
var C=function(){A.syncLinkText(this)
};
jQuery("#pageName").change(C).keyup(C);
var E=document.linkForm.pageName.autocompleter;
var G=E.options.onItemSelect;
E.options.onItemSelect=function(I,H){G(I,H);
jQuery(document.linkForm.pageName).change()
};
jQuery("#url").change(function(){var H=/[\]\[{}|]/g;
jQuery(this).val(jQuery(this).val().replace(H,encodeURIComponent))
});
jQuery("#switchToWiki").click(function(){A.clickWikiLink();
return false
});
jQuery("#switchToExternal").click(function(){A.clickExternalLink();
return false
});
jQuery("#switchToAnchor").click(function(){A.clickAnchorLink();
return false
});
jQuery("#linkTextWiki").keydown(function(){A.linkTextChanged=true
});
jQuery("#linkTextExternal").keydown(function(){A.linkTextChanged=true
});
var D=function(){A.checkLinkText(this)
};
jQuery("#linkTextWiki").change(D).keyup(D);
jQuery("#linkTextExternal").change(D).keyup(D);
jQuery("#switchToSpace").change(function(){A.changeSpaceName(this.value)
});
jQuery("#switchToPage").click(function(){A.switchToSelect();
return false
});
jQuery("#wikiAnchor").click(function(){A.showAnchor();
return false
});
var F=function(){A.checkAnchor(this)
};
jQuery("#anchor").change(F).keyup(F);
jQuery("#linkTextAnchor").change(F).keyup(F);
jQuery("#removeExistingLink").click(function(){A.toolbar.editor.getCurrentArea().editorRemoveLink();
A.linkPopupWindow.close()
});
jQuery("#submitLink").click(function(H){if(A.toolbar.editor.getCurrentArea().linkTool.addLink(A.linkType)){A.linkPopupWindow.close()
}H.preventDefault()
});
jQuery("#cancelLink").click(function(){A.linkPopupWindow.close();
return false
})
}
}function WikispacesMediaTool(B){this.area=B;
var A=this;
this.selectedMedia;
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(C){this.unSelectMedia();
this.selectedMedia=C;
if(jQuery(C).is(".WikiReference, .WikiAnchor")){return 
}jQuery(C).css("opacity","0.75");
this.area.editor.toolbar.mediaToolbar.showMediaPropertiesPopup();
if(jQuery(C).is(".WikiMediaRss, .WikiMediaInclude, .WikiMediaToc, .WikiMediaTocFlat")){this.area.editor.toolbar.mediaToolbar.hideAlignmentAndSize()
}else{this.area.editor.toolbar.mediaToolbar.setMediaAlignment(this.getMediaAlignment(C));
this.area.editor.toolbar.mediaToolbar.showAlignmentAndSize()
}if(jQuery(C).is(".WikiMediaToc, .WikiMediaTocFlat")){jQuery("#mediaProperties #mediaEditLink").attr("disabled",true)
}else{jQuery("#mediaProperties #mediaEditLink").attr("disabled",false)
}};
this.insertMediaEmbedInEditor=function(E,C){WikispacesCommon.track("Editor","Add Media",C);
this.area.insertInEditor(E);
if(this.area.editor.mode==this.area.editor.VISUAL){var D=this.area.getEditorWindow().document;
this.area.attachDoubleClickEventHandlers(D)
}this.area.editor.toolbar.mediaToolbar.hideMediaTool()
};
this.insertToc=function(C){if(this.area.editor.mode==this.area.editor.VISUAL){if(C){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(){A.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(){A.area.lookForHeightChange()
})
}}else{if(C){this.area.insertInEditor("\n[[toc|flat]]")
}else{this.area.insertInEditor("\n[[toc]]")
}}this.area.editor.toolbar.mediaToolbar.hideMediaTool()
};
this.insertReferences=function(){if(this.area.editor.mode==this.area.editor.VISUAL){this.area.insertInEditor("\n&lt;references/&gt;")
}else{this.area.insertInEditor("\n<references/>")
}this.area.editor.toolbar.mediaToolbar.hideMediaTool()
};
this.findCenteringElement=function(C){while(C){if(C.tagName&&(C.tagName.toUpperCase()=="CENTER"||(C.tagName.toUpperCase()=="DIV"&&(C.style.textAlign=="center"||C.align=="center")))){return C
}if(C.parentNode){C=C.parentNode
}else{return null
}}return null
};
this.getMediaAlignment=function(D){var C=this.findCenteringElement(D);
if(C){return"center"
}return D.align
};
this.setMediaAlignment=function(G){if(this.selectedMedia){if(G=="center"){if(this.findCenteringElement(this.selectedMedia)){return 
}else{this.selectedMedia.align="";
var E=this.area.getEditorWindow().document;
var D=E.createElement("div");
D.style.textAlign="center";
var C=this.selectedMedia;
if(C.parentNode.nodeName=="A"){C=this.selectedMedia.parentNode
}C.parentNode.appendChild(D);
C.parentNode.replaceChild(D,C);
D.appendChild(C)
}}else{var F=this.findCenteringElement(this.selectedMedia);
if(F){for(i=0;
i<F.childNodes.length;
i++){F.parentNode.insertBefore(F.childNodes.item(i),F)
}F.parentNode.removeChild(F)
}this.selectedMedia.align=G
}this.area.detectedChange()
}};
this.adjustMediaSize=function(F,E,D){if(this.selectedMedia){var C=jQuery(this.selectedMedia);
var G=new Image();
jQuery(G).load(function(){A.adjustMediaSizeCallback(C,G,F,E,D)
});
G.src=C.attr("src");
if(G.height>0||G.width>0){this.adjustMediaSizeCallback(C,G,F,E,D)
}}return false
};
this.adjustMediaSizeCallback=function(H,J,K,F,I){var E=H.height()/J.height;
var C=H.width()/J.width;
var D;
var G;
if(F){D=J.height;
G=J.width
}else{if(I){if(J.width>800){G=800;
D=Math.round((800/J.width)*J.height)
}else{G=J.width;
D=J.height
}}else{if(K!=0){D=Math.floor(J.height*(E+K));
G=Math.floor(J.width*(C+K))
}}}if(D>0&&G>0&&D>=Math.floor(J.height*0.05)&&G>=Math.floor(J.width*0.05)){H.height(D);
H.width(G);
if(this.area.editor.mode==this.area.editor.VISUAL){this.area.lookForHeightChange()
}}if(F){jQuery(H).css("height","").css("width","");
if(H.removeAttribute){H.removeAttribute("height");
H.removeAttribute("width")
}else{H.height=undefined;
H.width=undefined
}}};
this.removeMedia=function(){if(this.selectedMedia){jQuery(this.selectedMedia).remove();
this.unSelectMedia()
}return false
}
}function WikispacesMediaToolbar(B){this.toolbar=B;
this.previousSection="wikispaces";
this.currentMenu="wikispaces";
this.mediaPopupWindow;
this.mediaPreviewPopupWindow;
this.mediaPropertiesPopupWindow;
this.currentSection="wikispaces";
var A=this;
this.showMediaTool=function(){WikispacesCommon.track("Editor","Open Media Tool");
this.toolbar.editor.getCurrentArea().saveCursor();
WindowUtilities.disableScreen("wikispaces","overlay_modal",0);
var C=this;
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");
A.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");
if(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 C=jQuery(this.toolbar.editor.getCurrentArea().mediaTool.selectedMedia);
var D=new Image();
D.src=C.attr("src");
if(D.height>0||D.width>0){this.adjustMediaPropertiesPopup()
}else{jQuery(D).ready(function(){A.adjustMediaPropertiesPopup()
})
}};
this.hideMediaPropertiesPopup=function(){if(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(){A.toolbar.editor.getCurrentArea().mediaTool.setMediaAlignment(jQuery(this).val())
});
jQuery("#mediaSizeDown").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(-0.1);
return false
});
jQuery("#mediaSizeUp").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(0.1);
return false
});
jQuery("#mediaSizeOriginal").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(0,true);
return false
});
jQuery("#mediaSizeFit").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.adjustMediaSize(0,false,true);
return false
});
jQuery("#mediaEditLink").click(function(){A.toolbar.editor.getCurrentArea().editorEmbedMedia();
return false
});
jQuery("#mediaRemoveLink").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.removeMedia();
return false
})
};
this.adjustMediaPropertiesPopup=function(){WikispacesToolbar.setPopupSize(this.mediaPropertiesPopupWindow);
var C=this.toolbar.getPositionWith(this.mediaPropertiesPopupWindow.element,this.toolbar.editor.getCurrentArea().mediaTool.selectedMedia);
this.mediaPropertiesPopupWindow.setLocation(C.top-10,C.left-10)
};
this.setMediaError=function(C){jQuery("#mediaError").show().html(C)
};
this.setMediaPreview=function(C){this.showMediaPreview();
jQuery("#mediaPreviewArea").html(C)
};
this.resetMediaForms=function(){jQuery("#mediaContent .mediaForm").each(function(){this.reset()
});
jQuery("#mediaContent .autocompletePage").val(wikispaces_page)
};
this.loadMedia=function(C){this.startMediaSpinner();
document.genericMediaForm.media.value=C;
document.genericMediaForm.submit();
return 
};
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("#"+A.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 C=document.getElementById("mediaError");
C.style.display="none";
C.innerHTML=""
};
this.stopMediaSpinner=function(){jQuery("#mediaContent").removeClass("mediaContentSpinner");
this.setMediaMenu(this.previousSection)
};
this.setMediaAlignment=function(C){jQuery("#mediaAlign").val(C)
};
this.setMediaMenu=function(C){log("setMediaMenu",C);
var D=false;
if(jQuery("#"+C+"MediaMenuEntry").parents("#mediaMenu").length==1){jQuery("#"+this.currentMenu+"MediaMenuEntry").removeClass("activeMediaMenuEntry");
jQuery("#"+C+"MediaMenuEntry").addClass("activeMediaMenuEntry");
this.currentMenu=C;
D=true
}if(C=="showcustom"){C="custom"
}if(!document.getElementById(C+"MediaMenu")){C="wikispaces"
}jQuery("#"+C+"MediaMenu").find("input.autocompletePage").each(function(){var E=this.autocompleter;
setTimeout(function(){E.findValue()
},1)
});
jQuery("#"+C+"MediaMenu").find("input.autocompleteTag").each(function(){var E=this.autocompleter;
setTimeout(function(){E.findValue()
},1)
});
jQuery("#"+this.currentSection+"MediaMenu").hide();
jQuery("#"+C+"MediaMenu").show();
this.currentSection=C;
if((D&&C!="custom")||C=="wikispaces"||C=="spinner"||C=="flickr"||C=="gabbly"||C=="yackpack"||C=="bittybrowser"||C=="toc"||C=="reference"||C.substring(0,7)=="include"||jQuery("#"+C+"MediaMenu").is(".hideTextMediaInstructions")){jQuery(document.otherMediaForm).hide()
}else{jQuery(document.otherMediaForm).show()
}if(C!="spinner"){document.otherMediaForm.mediaType.value=C;
WikispacesToolbar.setPopupSize(this.mediaPopupWindow,true);
WikispacesToolbar.snapPopupToScreen(this.mediaPopupWindow)
}};
this.submitYackpack=function(){var D=document.yackpackMediaForm.channel.value;
var C="http://www.yackpack.com/walkietalkie/?"+encodeURIComponent(D);
document.otherMediaForm.embedText.value=C;
document.otherMediaForm.save.click()
};
this.submitBittyBrowser=function(){var C=document.bittybrowserMediaForm.url.value;
document.otherMediaForm.embedText.value='bitty browser\nwebsite: "'+C+'"';
document.otherMediaForm.save.click()
};
this.embedGabbly=function(){var C=location.protocol+"//"+location.host+"/"+wikispaces_page;
document.otherMediaForm.embedText.value="<iframe src='http://cw.gabbly.com/gabbly/cw.jsp?e=1&t="+encodeURIComponent(C)+"' scrolling='no' style='width:300px; height:250px;' frameborder='0'></iframe>";
document.otherMediaForm.save.click()
};
this.setupPreview=function(){jQuery("#closePreviewButton").click(function(){A.mediaPreviewPopupWindow.close()
})
};
this.setup=function(){jQuery("#mediaDiv ul li").live("click",function(){var L=this.id;
var K=L.substring(0,L.indexOf("MediaMenuEntry"));
if(A.currentMenu!="spinner"){A.setMediaMenu(K)
}return false
});
jQuery("#tocMediaForm #tocSubmitButton").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.insertToc();
return false
});
jQuery("#tocMediaForm #flatSubmitButton").click(function(){A.toolbar.editor.getCurrentArea().mediaTool.insertToc(true);
return false
});
jQuery("#referenceMediaForm").submit(function(K){A.toolbar.editor.getCurrentArea().referenceTool.insertReference();
A.hideMediaTool();
K.preventDefault();
K.stopPropagation();
return false
});
jQuery("#referencesMediaForm").submit(function(K){A.toolbar.editor.getCurrentArea().mediaTool.insertReferences();
K.preventDefault();
K.stopPropagation();
return false
});
jQuery("#mediaDiv .mediaForm").submit(function(){A.startMediaSpinner()
});
jQuery("#bittybrowserMediaForm").submit(function(){A.submitBittyBrowser()
});
jQuery("#gabblyMediaForm").submit(function(K){A.embedGabbly();
K.preventDefault();
K.stopPropagation();
return false
});
jQuery("yackpackMediaForm").submit(function(K){A.submitYackpack();
K.preventDefault();
K.stopPropagation();
return false
});
jQuery("#mediaDiv form").each(function(){jQuery(this).attr("action","/page/embedmedia/"+encodeURIComponent(wikispaces_page)+"?mode="+encodeURIComponent(A.toolbar.editor.mode))
});
jQuery("#mediaDiv .cancelMediaLink").click(function(){A.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 G=0;
G<this.toolbar.editor.plugins.length;
G++){var H=this.toolbar.editor.plugins[G];
if(H.options.type=="media"){var E=jQuery("<img>").attr("title",H.options.name).attr("alt",H.options.name).attr("src",H.options.logo);
var D=jQuery("<a>").attr("href","#widget-"+H.options.id).append(E);
var C=jQuery("<li>").attr("id",H.options.id+"MediaMenuEntry").addClass("mediaMenuEntry").append(D);
jQuery("#"+H.options.category+"MediaMenu ul li:last").before(C);
var I=document.location.protocol+"//"+document.location.host+"/site/editorplugin";
var F=H.options.url+(H.options.url.indexOf("?")>0?"&":"?")+encodeURIComponent(WikispacesEditorPlugin.COMMAND_URL_PARAM)+"="+encodeURIComponent(I);
var J=jQuery("<div>").attr("id",H.options.id+"MediaMenu").addClass("hideTextMediaInstructions").addClass("mediaInstructions").hide().html('<iframe class="pluginIframe" frameborder="0" src="'+F+'" id="'+H.options.id+'-pluginIframe" name="'+H.options.id+'-pluginIframe"></iframe>');
jQuery("#mediaContent").find(".mediaInstructions:last").after(J)
}}}
}function WikispacesEditorPlugin(A){this.options=A
}WikispacesEditorPlugin.COMMAND_URL_PARAM="wikispacesCommandUrl";
WikispacesEditorPlugin.runCommand=function(C,A){var B=WikispacesEditor.getEditor();
switch(C){case"cancel":B.toolbar.mediaToolbar.hideMediaTool();
break;
case"preview":jQuery("#otherMediaForm #embedText").val(A.content);
jQuery("#otherMediaForm").get(0)["preview"].click();
break;
case"submit":jQuery("#otherMediaForm #embedText").val(A.content);
jQuery("#otherMediaForm").get(0)["save"].click();
break;
default:alert("The plugin requested an invalid operation.");
break
}};
Function.prototype.extend=function(A,C){var D=this,B=function(){D.apply(this,arguments);
A.apply(this,arguments)
};
B.prototype=new D();
B.implement(C);
return B
};
Function.prototype.implement=function(B){for(var A in B){this.prototype[A]=B[A]
}};
function AbstractRange(){this.fatal=false;
this.startContainer=null;
this.startOffset=null;
this.endContainer=null;
this.endOffset=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(A,B){},setEnd:function(A,B){},setStartBefore:function(A){},setStartAfter:function(A){},setEndBefore:function(A){},setEndAfter:function(A){},collapse:function(A){},selectNode:function(A){},selectNodeContents:function(A){},insertNode:function(A){},surroundContents:function(A){},toString:function(){},compareBoundaryPoints:function(A,B){},deleteContents:function(){},extractContents:function(){},cloneContents:function(){},cloneRange:function(){},detach:function(){}};
InternetExplorerRange=AbstractRange.extend(function(A){this.win=A;
this.className="InternetExplorerRange"
},{setStart:function(A,C){try{if(A.nodeType==3&&(C>A.data.length||C<0)){throw ('Exception... "Index or size is negative or greater than the allowed amount" 1 '+C)
}if(A.nodeType==1&&C>0&&(C>A.childNodes.length-1||A.childNodes.length==0)){log("START NODE IS AN ELEMENT"+A.tagName);
throw ('Exception... "Index or size is negative or greater than the allowed amount" 2 '+C)
}this.startContainer=A;
this.startOffset=C;
if(this.endContainer==null&&this.endOffset==null){this.endContainer=A;
this.endOffset=C
}this.collapsed=this._collapsed()
}catch(B){this.fatal=true;
log("setStart exception "+B.name+" - "+B.message,B)
}},setEnd:function(A,C){try{if(A.nodeType==3&&(C>A.data.length||C<0)){throw ('Exception... "Index or size is negative or greater than the allowed amount" 3 '+C+" "+A.data)
}if(A.nodeType==1&&C>0&&(C>A.childNodes.length-1||A.childNodes.length==0)){log("END NODE IS AN ELEMENT"+A.tagName);
throw ('Exception... "Index or size is negative or greater than the allowed amount" 4 '+C)
}this.endContainer=A;
this.endOffset=C;
if(this.startContainer==null&&this.startOffset==null){this.startContainer=A;
this.startOffset=C
}this.collapsed=this._collapsed()
}catch(B){this.fatal=true;
log("setEnd exception "+B.name+" - "+B.message,B)
}},collapse:function(A){},_collapsed:function(){return(this.startContainer==this.endContainer&&this.startOffset==this.endOffset)
},insertNode:function(B){var C=this.win.document.selection.createRange();
var A=this.win.document.createElement("div");
A.appendChild(B);
C.collapse(false);
C.pasteHTML(A.innerHTML)
},surroundContents:function(C){var B=this.win.document.selection.createRange();
var A=this.win.document.createElement("div");
A.appendChild(C);
C.innerHTML+=B.htmlText;
B.pasteHTML(A.innerHTML)
},selectNode:function(A){var B=this.win.document.selection.createRange();
B.moveToElementText(A);
try{B.select()
}catch(C){if(C.number!=-2146827682){throw C
}}},selectNodeContents:function(A){var B=this.win.document.selection.createRange();
B.moveToElementText(A);
B.select()
},deleteContents:function(){var A=this.win.document.selection.createRange();
A.pasteHTML("")
}});
InternetExplorerRange.prototype.toString=function(){var A=this.win.document.selection.createRange();
return A.text
};
W3Range=AbstractRange.extend(function(A){this.win=A;
this.className="W3Range";
this.range=this.win.document.createRange()
},{setStart:function(A,B){this.range.setStart(A,B)
},setEnd:function(A,B){this.range.setEnd(A,B)
},selectNode:function(A){this.range.selectNode(A)
},selectNodeContents:function(A){this.range.selectNodeContents(A)
},insertNode:function(A){this.range.insertNode(A)
},deleteContents:function(){this.range.deleteContents()
}});
W3Range.prototype.toString=function(){return this.range.toString()
};
function Range(A){if(jQuery.browser.msie){return new InternetExplorerRange(A)
}else{return new W3Range(A)
}}function Selection(A){if(jQuery.browser.msie){return new InternetExplorerSelection(A)
}else{return new W3Selection(A)
}}function W3Selection(A){this.win=A;
this.className="W3Selection";
this.ranges=[]
}W3Selection.prototype={addRange:function(A){this.ranges[this.ranges.length]=A;
this.win.getSelection().addRange(A.range)
},removeRange:function(B){for(var A in this.ranges){if(this.ranges[A]==B){delete this.ranges[A]
}}},removeAllRanges:function(){this.ranges.length=0;
this.win.getSelection().removeAllRanges()
},getRangeAt:function(A){return this.win.getSelection().getRangeAt(A)
}};
function InternetExplorerSelection(A){this.win=A;
this.className="InternetExplorerSelection";
this.ranges=[]
}InternetExplorerSelection.prototype={addRange:function(A){this.ranges[this.ranges.length]=A;
if(this.ranges.length==1){this._addRange()
}},setRangeAt:function(A,B){this.ranges[B]=A;
if(this.ranges.length==1){this._addRange()
}},removeRange:function(B){for(var A in this.ranges){if(this.ranges[A]==B){delete this.ranges[A]
}}},removeAllRanges:function(){this.ranges.length=0
},getRangeAt:function(J){var A=this.win.document.selection.createRange();
var D=new Range(this.win);
var N=A.duplicate();
var P=A.duplicate();
N.collapse(true);
N.move("Character",1);
N.move("Character",-1);
N.pasteHTML("<b id='_range_decomposition_left_temporary'>L</b>");
P.collapse(false);
P.pasteHTML("<b id='_range_decomposition_right_temporary'>R</b>");
var O=false;
var I=false;
var M=this.win.document.getElementById("_range_decomposition_left_temporary");
var C=0;
var E;
if(M.nextSibling&&M.nextSibling.id=="_range_decomposition_right_temporary"){O=true;
log("getRangeAt: zero length range detected")
}var F=this.win.document.getElementsByTagName("b");
for(var G=0;
G<F.length;
G++){if(F[G].id=="_range_decomposition_left_temporary"){break
}else{if(F[G].id=="_range_decomposition_right_temporary"){log("getRangeAt: right before left detected");
O=true;
I=true
}}}log("Getting left position");
var H=this._getObjectAndOffset(M,O,I,true);
var L=H[0];
var C=H[1];
M=this.win.document.getElementById("_range_decomposition_right_temporary");
var B;
var K;
if(O){B=L;
K=C;
M.parentNode.removeChild(M)
}else{log("getting right position");
var Q=this._getObjectAndOffset(M,O,I,false);
B=Q[0];
K=Q[1]
}log("getRangeAt: setting range endpoints",L,B,C,K);
D.setStart(L,C);
D.setEnd(B,K);
this.setRangeAt(D,J);
return D
},_getObjectAndOffset:function(J,K,G,B){if((J.nextSibling&&J.nextSibling.nodeType==3||J.previousSibling&&J.previousSibling.nodeType==3)){log("mode 1: something touched a text block");
if(J.previousSibling&&J.nextSibling&&J.previousSibling.nodeType==3&&J.nextSibling.nodeType==3){leftOffset=J.previousSibling.data.length;
nextNode=J.previousSibling;
if(B){nextNode.data=nextNode.data+J.nextSibling.data;
J.nextSibling.parentNode.removeChild(J.nextSibling)
}}else{if(!J.previousSibling||J.previousSibling.nodeType==1){leftOffset=0;
nextNode=J.nextSibling
}else{if(!J.nextSibling||J.nextSibling.nodeType==1){leftOffset=J.previousSibling.data.length;
nextNode=J.previousSibling
}}}J.parentNode.removeChild(J)
}else{if(!J.previousSibling||(J.previousSibling&&J.previousSibling.nodeType==1)){log("mode 3: no text nodes, either the previous is empty, or it is an element");
leftOffset=0;
if(G){if(J.nextSibling){nextNode=J.nextSibling
}else{if(J.previousSibling&&J.previousSibling.id=="_range_decomposition_right_temporary"&&J.previousSibling.previousSibling){nextNode=J.previousSibling.previousSibling
}else{nextNode=J.parentNode
}}}else{if(K){if(J.nextSibling.nextSibling){nextNode=J.nextSibling.nextSibling
}else{nextNode=J.parentNode
}}else{if(J.nextSibling){nextNode=J.nextSibling
}else{if(J.previousSibling){nextNode=J.previousSibling;
if(nextNode.nodeType==3){leftOffset=nextNode.length
}}else{var F=this.win.document.createTextNode("\u00a0");
jQuery(J).after(F);
nextNode=F
}}}}J.parentNode.removeChild(J);
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(!J.nextSibling){log("mode 4: the next is empty");
nextNode=J.previousSibling;
J.parentNode.removeChild(J);
if(nextNode.nodeType==3){leftOffset=nextNode.data.length
}else{if(nextNode.nodeType==1){leftOffset=nextNode.parentNode.childNodes.length
}else{log("unknown node type")
}}}else{log("FAILURE CASE NOT HANDLED",J.previousSibling,J.nextSibling);
J.parentNode.removeChild(J)
}}}log("found a preliminary endpoint",nextNode,leftOffset);
if(nextNode.nodeType==1){var H=nextNode.childNodes.item(leftOffset);
var C=false;
var E=false;
var A=false;
var I=B;
log("Looking for a text node at the "+(I?"start":"end")+" of current node",H);
while(!C){if(H.nodeType==3){nextNode=H;
leftOffset=(I?0:nextNode.length);
C=true;
log("found a text node to use",nextNode,leftOffset)
}else{if(H.nodeType==1&&H.tagName=="BR"){var F=this.win.document.createTextNode("\u00a0");
jQuery(H).before(F);
nextNode=F;
leftOffset=0;
C=true
}else{if(H.id!="_range_decomposition_right_temporary"&&H.id!="_range_decomposition_left_temporary"&&H.childNodes.length>0){H=H.childNodes.item((I?0:H.childNodes.length-1));
log("Still looking, now checking",H)
}else{if(!E&&nextNode.childNodes.item(leftOffset).previousSibling){E=true;
I=false;
if(nextNode.childNodes.item(leftOffset).previousSibling&&nextNode.childNodes.item(leftOffset).previousSibling.id!="_range_decomposition_right_temporary"){H=nextNode.childNodes.item(leftOffset).previousSibling;
log("ran out of nodes, looking at the previous",H)
}else{H=nextNode.childNodes.item(leftOffset).previousSibling.previousSibling.previousSibling;
log("came across a BAD right temporary in before",H)
}}else{if(!A&&nextNode.childNodes.item(leftOffset).nextSibling){A=true;
I=true;
if(nextNode.childNodes.item(leftOffset).nextSibling&&nextNode.childNodes.item(leftOffset).nextSibling.id!="_range_decomposition_right_temporary"){H=nextNode.childNodes.item(leftOffset).nextSibling;
log("ran out of nodes, looking at the next",H)
}else{H=nextNode.childNodes.item(leftOffset).nextSibling.nextSibling;
log("came across a BAD right temporary in after",H)
}}else{C=true;
var F=this.win.document.createTextNode("\u00a0");
if(B){jQuery(nextNode.childNodes.item(leftOffset)).before(F);
nextNode=F;
leftOffset=0
}else{jQuery(nextNode.childNodes.item(leftOffset)).after(F);
nextNode=F;
leftOffset=0
}log("Ran out of places to look, giving up and adding a new text node",nextNode,leftOffset)
}}}}}}}var D=new Array();
D[0]=nextNode;
D[1]=leftOffset;
return D
},_addRange:function(){var C=this.ranges[this.ranges.length-1];
if(C.fatal){return 
}var A=this._selectStart(C);
var B=this._selectEnd(C);
A.setEndPoint("EndToStart",B);
A.select();
this.win.document.selection._selectedRange=C
},_selectStart:function(E){var B=this.win.document.body.createTextRange();
var H=E.startContainer;
var G=E.startOffset;
var C=H;
if(H.nodeType==3){log("looking for a spot to move to",H);
var D=G;
var A=null,F=true;
while(C.previousSibling){switch(C.previousSibling.nodeType){case 1:A=C.previousSibling;
F=false;
break;
case 3:D+=C.previousSibling.data.length;
break
}if(A!=null){break
}C=C.previousSibling
}if(A==null){A=H.parentNode;
F=true
}log("Calling moveToElementText",A,D);
B.moveToElementText(A);
B.collapse(F);
B.move("Character",D);
return B
}else{if(H.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 B
},_selectEnd:function(C){var A=this.win.document.body.createTextRange();
var E=C.endContainer,D=E;
var F=C.endOffset;
if(E.nodeType==3){var I=E.data.length-F;
var B=null,H=false;
while(D.nextSibling){switch(D.nextSibling.nodeType){case 1:B=D.nextSibling;
H=true;
break;
case 3:I+=D.nextSibling.data.length;
break
}if(B!=null){break
}D=D.nextSibling
}if(B==null){B=E.parentNode;
H=false
}switch(B.nodeName.toLowerCase()){case"p":case"div":case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":I++
}A.moveToElementText(B);
A.collapse(H);
A.move("Character",-I)
}else{if(E.nodeType==1){switch(C.endContainer.childNodes.item(C.endOffset).nodeType){case 3:var F=0;
var G=C.endContainer.childNodes.item(C.endOffset);
C.setEnd(G,F);
return this._selectEnd(C);
break;
default:log("error invalid node type in selectEnd")
}}}return A
},_getElementIndex:function(B){var C=B.parentNode.childNodes;
for(var A=0;
A<C.length;
A++){if(C[A]==B){return A
}}return null
}};
function WikispacesReferenceTool(B){this.area=B;
this.referencePopups=new Array();
var A=this;
this.openReferencePopup=function(C){log("openReferencePopup",C,this.referencePopups[C]);
this.area.saveCursor();
this.referencePopups[C].showCenter();
this.referencePopups[C].toFront();
jQuery("#"+C).ready(function(){setTimeout(function(){A.area.editor.getArea(C).initialRteCommands()
},10)
});
WikispacesToolbar.setPopupSize(this.referencePopups[C],true);
WikispacesToolbar.snapPopupToScreen(this.referencePopups[C])
};
this.addReferencePopup=function(F,D){if(!this.referencePopups[F]){this.referencePopups[F]=new Window("referencePopup-"+F,{minWidth:300,title:"Edit Reference",resizable:false,maximizable:false,minimizable:false,closable:false,className:"wikispaces",onClose:function(){A.area.restoreCursor()
},showEffect:Element.show,hideEffect:Element.hide,onMove:function(G){A.onMoveHandler(G)
}});
this.referencePopups[F].setHTMLContent('<div id="referenceDiv" class="editorPopup"><div id="referenceDivIframe"><iframe id="'+F+'" name="'+F+'" frameborder="0" src="/s/blank.html" scrolling="no"></iframe></div><button class="btn primary" id="'+F+'-close" name="save" value="Save"><span><span>Save</span></span></button> <button class="btn primary" id="'+F+'-remove" name="remove" value="Remove"><span><span>Remove</span></span></button> </div>',true,true);
var C=this.area.editor.createArea(F);
C.autosaveEnabled=false;
C.mainEditor=false;
C.referenceEditor=true;
C.customEditorStart(F,false);
var E=C.lookForHeightChange;
C.lookForHeightChange=function(){E.call(C);
if(A.referencePopups[F].isVisible()){WikispacesToolbar.setPopupSize(A.referencePopups[F]);
WikispacesToolbar.snapPopupToScreen(A.referencePopups[F])
}};
if(!D){D="Type your reference here.";
C.highlightContent=true
}setTimeout(function(){jQuery(C.getEditorWindow().document).find("#"+F).find("body").get(0).innerHTML=D;
jQuery("#"+F+"-close").click(function(){A.referencePopups[F].hide()
});
jQuery("#"+F+"-remove").click(function(){A.referencePopups[F].close();
var G=F.substring(0,F.length-5);
jQuery(A.area.editor.getMainArea().getEditorWindow().document.body).find("img#"+G).remove()
})
},1)
}else{log("reusing existing reference popup",F)
}};
this.insertReference=function(){if(this.area.editor.mode==this.area.editor.PLAIN){this.area.insertInEditor("<ref></ref>")
}else{var C=new Date().getTime();
this.addReferencePopup("reference-"+C+"-Area","");
this.openReferencePopup("reference-"+C+"-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-'+C+'"/> ');
jQuery(this.area.getEditorWindow().document.body).find("#reference-"+C).ready(function(){A.area.lookForHeightChange()
});
jQuery(this.area.getEditorWindow().document).find("#reference-"+C).dblclick(function(){A.openReferencePopup(this.id+"-Area")
})
}};
this.pullOutReferences=function(G){log("pullOutReferences",G);
var F=jQuery("#"+G).html();
var H=1;
var C=true;
var E=/&lt;ref(?:&gt;|>)((?:.|\n)*?)&lt;\/ref(?:&gt;|>)/;
while(C){C=F.match(E);
if(C){var D=C[1];
F=F.replace(E,'<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-'+H+'"/> ');
this.addReferencePopup("reference-"+H+"-Area",D);
H++
}}jQuery("#"+G).html(F)
};
this.pushInReferences=function(C){log("pushInReferences");
var D=document.createElement("div");
D.innerHTML=C;
jQuery(D).find(".WikiReference").each(function(){var E=jQuery(A.area.editor.getArea(this.id+"-Area").getEditorWindow().document).find("body").html();
jQuery(this).replaceWith("&lt;ref&gt;"+E+"&lt;/ref&gt;")
});
return D.innerHTML
};
this.onMoveHandler=function(C){var E=this.area.editor.getArea(jQuery(C.content).find("iframe").attr("id"));
if(E.tableTool.selectedTableCell){jQuery("#tableProperties").hide();
if(E.editor.toolbar.tableToolbar.tablePropertiesShown){this.area.editor.toolbar.tableToolbar.showTablePropertiesPopup()
}else{this.area.editor.toolbar.tableToolbar.showTablePropertiesMenuHandle()
}}if(E.imageTool.selectedImage){var D=this.area.editor.toolbar.getPositionWith(this.area.editor.toolbar.imageToolbar.imagePropertiesPopupWindow.element,E.imageTool.selectedImage);
this.area.editor.toolbar.imageToolbar.imagePropertiesPopupWindow.setLocation(D.top,D.left);
this.area.editor.toolbar.imageToolbar.imagePropertiesPopupWindow.toFront()
}};
this.closeReferences=function(){for(var C in this.referencePopups){if(typeof (this.referencePopups[C])=="object"){this.referencePopups[C].close()
}}}
}function RGBColor(G){this.ok=false;
if(G.charAt(0)=="#"){G=G.substr(1,6)
}G=G.replace(/ /g,"");
G=G.toLowerCase();
var A={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 C in A){if(G==C){G=A[C]
}}var H=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(I){return[parseInt(I[1]),parseInt(I[2]),parseInt(I[3])]
}},{re:/^(\w{2})(\w{2})(\w{2})$/,example:["#00ff00","336699"],process:function(I){return[parseInt(I[1],16),parseInt(I[2],16),parseInt(I[3],16)]
}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(I){return[parseInt(I[1]+I[1],16),parseInt(I[2]+I[2],16),parseInt(I[3]+I[3],16)]
}}];
for(var B=0;
B<H.length;
B++){var E=H[B].re;
var D=H[B].process;
var F=E.exec(G);
if(F){channels=D(F);
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 K=this.r.toString(16);
var J=this.g.toString(16);
var I=this.b.toString(16);
if(K.length==1){K="0"+K
}if(J.length==1){J="0"+J
}if(I.length==1){I="0"+I
}return"#"+K+J+I
};
this.getHelpXML=function(){var K=new Array();
for(var M=0;
M<H.length;
M++){var J=H[M].example;
for(var L=0;
L<J.length;
L++){K[K.length]=J[L]
}}for(var R in A){K[K.length]=R
}var N=document.createElement("ul");
N.setAttribute("id","rgbcolor-examples");
for(var M=0;
M<K.length;
M++){try{var O=document.createElement("li");
var Q=new RGBColor(K[M]);
var S=document.createElement("div");
S.style.cssText="margin: 3px; border: 1px solid black; background:"+Q.toHex()+"; color:"+Q.toHex();
S.appendChild(document.createTextNode("test"));
var I=document.createTextNode(" "+K[M]+" -> "+Q.toRGB()+" -> "+Q.toHex());
O.appendChild(S);
O.appendChild(I);
N.appendChild(O)
}catch(P){}}return N
}
}function WikispacesStyleTool(B){this.area=B;
var A=this;
this.selectedSpans;
this.mergeNodeHandle;
this.applyStyle=function(){WikispacesCommon.track("Editor","Apply Style");
if(this.area.editor.mode==this.area.editor.PLAIN){return this.applyStyleTextEditor()
}else{return this.applyStyleVisualEditor()
}};
this.cleanupEmptySpans=function(C){log("cleanupEmptySpans");
jQuery(C).find("span").each(function(){if(A.selectedSpans&&this==A.selectedSpans[0]){return 
}var D=jQuery(this);
if(!D.attr("style")&&!D.attr("class")){D.replaceWith(D.contents())
}});
if(jQuery(C).find(":last").is("span")||(jQuery(C).find(":last").is("br")&&jQuery(C).find(":last").prev().is("span"))){jQuery(C).append("&nbsp;")
}};
this.applyStyleTextEditor=function(){var F=jQuery.trim(document.styleForm.styleText.value);
if(F.length>0){var C=F.replace(/\n/gmi,"; ");
var G=this.area.getSelectedText();
var D=G.match(/^<span [\s\S]*?>([\s\S]*)<\/span>$/i);
if(D&&D.length==2){G=D[1]
}var E=document.getElementById("textEditor");
E.focus();
this.area.insertInEditor('<span style="'+C+'">'+G+"</span>")
}else{this.removeStyle()
}return false
};
this.applyStyleVisualEditor=function(){try{var G=this.area.getEditorWindow();
if(!this.selectedSpans){return false
}var M=jQuery.trim(document.styleForm.styleText.value);
if(M.length>0){var N=M.replace(/;/gi,"\n").split("\n");
var L=new Selection(G);
log("exising span",this.selectedSpans);
jQuery(this.selectedSpans).attr("style","");
for(var I=0;
I<N.length;
I++){var H=N[I].split(":");
var F=H[0].camelize();
var K=jQuery.trim(H[1]);
log("setting attribute",F,K,this.selectedSpans);
jQuery(this.selectedSpans).css(F,K)
}}else{this.removeStyle()
}this.flattenNodes(this.selectedSpans);
if(jQuery.browser.msie){var D=G.document.body.createTextRange();
D.moveToElementText(this.selectedSpans[0]);
D.select()
}else{var E=new Selection(G);
var C=new Range(G);
C.selectNodeContents(this.selectedSpans[0]);
E.addRange(C)
}G.focus();
return false
}catch(J){log(J.message,J);
throw J;
return false
}};
this.removeStyle=function(){WikispacesCommon.track("Editor","Remove Style");
if(this.area.editor.mode==this.area.editor.VISUAL){return this.removeStyleVisualEditor()
}else{return this.removeStyleTextEditor()
}};
this.removeStyleTextEditor=function(){this.area.saveCursor();
var D=this.area.getSelectedText();
var C=D.match(/^<span [\s\S]*?>([\s\S]*)<\/span>$/i);
if(C&&C.length==2){this.area.insertInEditor(C[1])
}};
this.removeStyleVisualEditor=function(){if(this.selectedSpans){jQuery(this.selectedSpans).each(function(){jQuery(this).replaceWith(jQuery(this).html())
})
}};
this.getSelectedSpans=function(){var D=this.area.getEditorWindow();
D.focus();
var K=new Array;
var C=this.area.setRange(this.area.areaId);
if(C.startContainer.nodeType==3&&C.endContainer.nodeType==3&&C.startOffset==0&&C.endOffset==C.endContainer.length){if(C.startContainer==C.endContainer&&C.startContainer.parentNode.tagName=="SPAN"){var N=this.area.selectParent("SPAN");
log("SPAN (1) ",N,C);
K[0]=N;
return K
}}else{if(C.startContainer.nodeType==1&&C.startContainer==C.endContainer&&C.startContainer.tagName=="SPAN"){var N=C.startContainer;
log("SPAN (2) ",N,C);
K[0]=N;
return K
}else{if(C.startContainer.nodeType==1&&C.startOffset==0&&C.endOffset==1&&C.startContainer.childNodes.length==1&&C.startContainer.childNodes[0].tagName=="SPAN"){var N=C.startContainer.childNodes[0];
log("SPAN (3) ",N,C);
K[0]=N;
return K
}else{if(C.startContainer.nodeType==1&&C.startContainer==C.endContainer&&C.startContainer.childNodes&&C.endContainer.childNodes&&C.startContainer.childNodes[C.startOffset]&&C.endContainer.childNodes[C.endOffset]&&C.startContainer.childNodes[C.startOffset]==C.endContainer.childNodes[C.endOffset]&&C.startContainer.childNodes[C.startOffset].nodeType==1&&C.startContainer.childNodes[C.startOffset].tagName=="SPAN"){var N=C.startContainer.childNodes[C.startOffset];
log("SPAN (4) ",N,C);
K[0]=N;
return K
}else{if(C.startContainer.nodeType==1&&C.startContainer==C.endContainer&&C.startOffset+1==C.endOffset&&C.startContainer.childNodes&&C.endContainer.childNodes&&C.startContainer.childNodes[C.startOffset].nodeType==1&&C.startContainer.childNodes[C.startOffset].tagName=="SPAN"&&C.endContainer.childNodes[C.endOffset].nodeType==3){var N=C.startContainer.childNodes[C.startOffset];
log("SPAN (5) ",N,C);
K[0]=N;
return K
}}}}}if(C.startContainer==C.endContainer&&C.startOffset==C.endOffset){var N=this.area.selectParent("SPAN");
if(N){C.setStart(N,0);
C.setEnd(N,N.childNodes.length-1);
log("SPAN (6) ",N,C);
K[0]=N;
return K
}}var J=Array();
var L=false;
var F=C.startContainer;
while(!L){if(F.nodeType==1&&F.tagName=="SPAN"){J[J.length]=F
}if(F.childNodes.length>0&&F.childNodes[0].nodeType==1){F=F.childNodes[0]
}else{L=true
}}var O=Array();
var M=false;
var E=C.endContainer;
while(!M){if(E.nodeType==1&&E.tagName=="SPAN"){O[O.length]=E
}if(E.childNodes.length>0&&E.childNodes[E.childNodes.length-1].nodeType==1){E=E.childNodes[E.childNodes.length-1]
}else{M=true
}}for(var I=0;
I<J.length;
I++){for(var H=0;
H<O.length;
H++){if(J[I]==O[H]){log("SPAN (7) ",J[I],C);
K[0]=J[I];
return K
}}}log("could not find span, creating a new one");
if(C.collapsed){var G=this.insertSpan(D,C,"insert","span");
K[0]=G;
return K
}else{log("converting font to span");
this.area.rteCommand(this.area.areaId,"useCSS",true);
this.area.rteCommand(this.area.areaId,"forecolor","#100010");
jQuery(D.document.body).find("pre font[color='#100010']").each(function(Q){jQuery(this).replaceWith(jQuery(this).html())
});
var P=new Array();
jQuery(D.document.body).find("font[color='#100010'], span[style]").each(function(R){if(jQuery(this).attr("color")=="#100010"||jQuery(this).css("color")=="#100010"||jQuery(this).css("color")=="rgb(16, 0, 16)"){var Q=D.document.createElement("span");
jQuery(Q).html(jQuery(this).html());
jQuery(this).replaceWith(Q);
P[P.length]=Q
}});
log("new spans",P);
return this.collapseNodes(P)
}};
this.insertSpan=function(F,D,I,J){if(jQuery.browser.msie){log("adding new "+J);
D=document.selection.createRange();
D.pasteHTML("<"+J+' id="798798769876">&#8203;</'+J+">");
var K=F.document.getElementById("798798769876");
K.id="";
var C=F.document.selection.createRange();
C.moveToElementText(K);
C.select();
if(J=="div"){jQuery(K).css("display","inline")
}return K
}else{log("adding new "+J);
var G=F.document.createElement(J);
if(jQuery.browser.safari){var H=F.document.createTextNode(" ");
G.appendChild(H)
}if(I=="surround"){D.surroundContents(G)
}else{D.insertNode(G)
}D.selectNodeContents(G);
var E=F.getSelection();
E.removeAllRanges();
E.addRange(D);
if(J=="div"){jQuery(G).css("display","inline")
}return G
}};
this.getStyleArray=function(G){var F={};
if(G.style.length){for(var E=0;
E<G.style.length;
E++){var C=G.style[E];
var H=G.style[C.camelize()];
if(typeof (H)=="function"){continue
}var D=WikispacesStyleTool.normalizeCssSelector(C);
if(D=="cssText"){continue
}if(H&&H.length>0){F[D]=H
}}}else{for(var C in G.style){var H=G.style[C];
if(typeof (H)=="function"){continue
}var D=WikispacesStyleTool.normalizeCssSelector(C);
if(D=="cssText"){continue
}if(H&&H.length>0){F[D]=H
}}}return F
};
WikispacesStyleTool.normalizeCssSelector=function(C){if(C==C.toUpperCase()){C=C.toLowerCase()
}return C.camelize()
};
this.mergeStyles=function(F,D){var E={};
for(var C in F){if(typeof (F[C])!="function"){E[C]=F[C]
}}for(var C in D){if(typeof (D[C])!="function"){E[C]=this.mergeCss(F[C],C,D[C])
}}return E
};
this.collapseNodes=function(E){log("collapseNodes");
var F=Array();
for(var D=E.length-1;
D>=0;
D--){if(jQuery(E[D]).parents("body").length>0){var C=this.collapseNodeDown(E[D]);
F[F.length]=C
}}return F
};
this.flattenNodes=function(L){log("flattenNodes",L);
for(var F=L.length-1;
F>=0;
F--){var E=[jQuery(L[F])];
var M;
while(M=E.pop()){var D=M.parent();
if(!D.is("span")){continue
}log("flattening",M.get(0),M.html());
var H=D.contents();
var I=H.index(M);
var G=D.clone().empty().append(H.slice(I+1));
jQuery(D).after(G).after(M);
var C=this.mergeStyles(this.getStyleArray(D.get(0)),this.getStyleArray(M.get(0)));
for(var K in C){if(typeof (C[K])!="function"){try{M.css(K,C[K])
}catch(J){}}}if(jQuery.trim(D.html())==""){D.remove()
}if(jQuery.trim(G.html())==""){G.remove()
}else{E.push(G)
}E.push(M)
}}};
this.collapseNodeDown=function(K){while(jQuery(K).parent().is("span")&&jQuery(K).parent().attr("class")==jQuery(K).attr("class")&&jQuery(K).parent().children().length==1){var E=true;
for(var F=0;
F<K.parentNode.childNodes.length;
F++){if(K.parentNode.childNodes[F].nodeType==3&&!jQuery.trim(K.parentNode.childNodes[F].nodeValue)==""){E=false;
break
}}if(!E){break
}K=K.parentNode
}var M="";
var D="";
var C=this.getStyleArray(K);
var L=K;
while(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 I=true;
var E=true;
for(var F=0;
F<L.childNodes.length;
F++){if(L.childNodes[F].nodeType==1){I=false
}else{if(L.childNodes[F].nodeType==3&&jQuery.trim(L.childNodes[F].nodeValue)==""){if(I){M+=L.childNodes[F].nodeValue
}else{D+=L.childNodes[F].nodeValue
}}else{E=false;
break
}}}if(!E){break
}L=jQuery(L).children().get(0);
C=this.mergeStyles(C,this.getStyleArray(L))
}if(L&&L!=K){jQuery(L).prepend(M);
jQuery(L).append(D);
var J=jQuery(L).html();
jQuery(K).empty();
jQuery(K).html(J);
for(var H in C){if(typeof (C[H])!="function"){try{jQuery(K).css(H,C[H])
}catch(G){}}}}return K
};
this.mergeNodes=function(D){log("mergeNodes",D);
if(!D||D.length==0){return 
}var G=this.area.getEditorWindow().document;
var F=D[0].tagName;
var C=true;
while(C){C=false;
jQuery(G.body).find(F+" + br").each(function(){if(this.previousSibling.nodeType==1){C=true;
jQuery(this).prev().append("<br/>");
jQuery(this).remove()
}})
}jQuery(G.body).find(F).each(function(){var H=this.nextSibling;
if(H&&H.nodeType==3&&jQuery.trim(H.nodeValue)==""&&H.nextSibling&&H.nextSibling.nodeType==1&&H.nextSibling.tagName==F.toUpperCase()&&jQuery(H.nextSibling).attr("style")==jQuery(this).attr("style")&&jQuery(H.nextSibling).attr("class")==jQuery(this).attr("class")){jQuery(this).append(H.nodeValue);
H.parentNode.removeChild(H)
}});
for(var E=D.length-1;
E>=0;
E--){if(jQuery(D[E]).parents("body").length>0){this.mergeNode(D[E])
}}C=true;
while(C){C=false;
jQuery(G.body).find(F+" br:last-child").each(function(){if(!this.nextSibling){C=true;
jQuery(this).parent().after("<br/>");
jQuery(this).remove()
}})
}log("end mergeNodes",D)
};
this.mergeNode=function(D){var C=jQuery(D);
if(D.previousSibling&&D.previousSibling.tagName==D.tagName&&C.prev().attr("class")==C.attr("class")&&C.prev().attr("style")==C.attr("style")){var E=C.prev();
E.html(E.html()+C.html());
C.remove()
}};
this.mergeNodeKeypressHandlerDelayed=function(){if(typeof this.mergeNodeHandle=="number"){clearTimeout(this.mergeNodeHandle)
}this.mergeNodeHandle=setTimeout(function(){var C=A.area.getEditorWindow().document;
A.area.mergeNodes(C.getElementsByTagName("span"))
},50)
};
this.mergeCss=function(I,E,H){if(!I||E!="fontSize"){return H
}var G=I.substr(0,I.length-2);
var D=I.substr(I.length-2,2);
if(D[1]=="%"){D="%";
G=I.substr(0,I.length-1)
}var F=H.substr(H.length-2,2);
var C=H.substr(0,H.length-2);
if(F[1]=="%"){F="%";
C=H.substr(0,H.length-1)
}if(F=="em"||F=="ex"){F="%";
C=C*100
}if(D=="em"||D=="ex"){D="%";
G=G*100
}if(F=="%"){var J=Math.round(G*C*100)/(100*100);
return J+D
}else{return H
}};
this.removeSafariSpans=function(E){log("removeSafariSpans");
var D=this.area.getEditorWindow().document;
var C=jQuery(E).find("span").removeClass("Apple-tab-span");
var C=jQuery(E).find("span").removeClass("Apple-style-span");
this.cleanupEmptySpans(E)
};
this.getPreviousColors=function(){var D=new Array();
if(this.area.editor.mode==this.area.editor.VISUAL){jQuery(this.area.getEditorWindow().document.body).find("span").each(function(){var J=jQuery(this);
if(J.css("color")&&J.css("color")!="transparent"){D[D.length]=new RGBColor(J.css("color")).toHex().toUpperCase()
}if(J.css("backgroundColor")&&J.css("backgroundColor")!="transparent"){D[D.length]=new RGBColor(J.css("backgroundColor")).toHex().toUpperCase()
}})
}else{var G=this.area.getContent();
var I=G.match(/style=\"[^\"]*?color:\s*.*?[;\"]/gi);
if(I){for(var E=0;
E<I.length;
E++){var C=I[E].match(/color:\s*(.*?)[;\"]/i);
D[D.length]=new RGBColor(C[1]).toHex().toUpperCase()
}}}D.sort();
var H=new Array();
var F=null;
for(var E=0;
E<D.length;
E++){if(D[E]!=F){H[H.length]=D[E]
}F=D[E]
}return H
};
this.cleanup=function(H,E){log("cleanup",E);
var C=new Array();
if(E=="none"){return 
}if(E){C=E.split(",")
}if(C.length>0){this.area.editor.toolbar.styleToolbar.openCleanupPopup();
var G=new Date().getTime();
if(C.indexOf("safari")!=-1){this.removeSafariSpans(H)
}if(C.indexOf("collapse")!=-1){this.collapseNodes(H.getElementsByTagName("span"))
}if(C.indexOf("merge")!=-1){this.mergeNodes(H.getElementsByTagName("span"))
}if(C.indexOf("flatten")!=-1){this.flattenNodes(H.getElementsByTagName("span"))
}var D=3000;
var F=new Date().getTime();
var I=D-F-G;
if(I<=10){I=11
}setTimeout(function(){A.area.editor.toolbar.styleToolbar.closeCleanupPopup()
},I)
}}
}function WikispacesStyleToolbar(B){this.toolbar=B;
this.stylePopup;
this.cleanupPopup;
this.currentColorInput;
var A=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 G=A.toolbar.editor.getCurrentArea();
if(A.toolbar.editor.mode==A.toolbar.editor.VISUAL){G.styleTool.cleanupEmptySpans(G.getEditorWindow().document.body)
}if(G.styleTool.selectedSpans){G.styleTool.selectedSpans=null
}else{A.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 C=this.getStyleColors();
jQuery("#styleColors").empty();
var E={"float":"left",margin:"3px",width:"20px",height:"15px",cursor:"crosshair",border:"1px black solid"};
for(var D=0;
D<C.length;
D++){var F=document.createElement("div");
E["background-color"]=C[D];
jQuery(F).css(E);
jQuery(F).attr("title",C[D]);
jQuery(F).click(function(G){A.chooseStyleColor(jQuery(this).css("backgroundColor"));
G.preventDefault()
});
jQuery("#styleColors").append(F)
}this.updatePreviewStyle();
jQuery("#styleColors").hide();
jQuery("#colorpickerColor").hide();
jQuery("#colorpickerBackgroundColor").hide()
};
this.updatePreviewStyle=function(){if(jQuery(".styleBasic").css("display")!="none"){this.mergeBasicStyleToAdvanced()
}var C=jQuery.trim(document.styleForm.styleText.value).replace(/\n/gmi,"; ");
jQuery("#stylePreviewApplied").attr("style",C)
};
this.chooseStyleColor=function(C){var C=new RGBColor(C).toHex().toUpperCase();
if(!C){return 
}var D=this.currentColorInput.name;
jQuery.farbtastic("#colorpicker"+D.substring(5)).setColor(C);
document.styleForm[D].focus()
};
this.openCleanupPopup=function(){A.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");
A.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(){this.cleanupPopup.close();
this.toolbar.editor.getCurrentArea().getEditorWindow().focus()
};
this.mergeBasicStyleToAdvanced=function(){var H=jQuery(document.styleForm.styleText).val();
var G=jQuery(document.styleForm.styleSize).val();
var F=jQuery(document.styleForm.styleFont).val();
var E=jQuery(document.styleForm.styleColor).val();
var D=jQuery(document.styleForm.styleBackgroundColor).val();
var J=jQuery(document.styleForm.styleAlignment).val();
var C=jQuery(document.styleForm.styleVertical).val();
var I=jQuery(document.styleForm.styleStrike).attr("checked");
if(G&&G!="100%"){if(H.match(/^\s*font-size:\s*.*$/gmi)){H=H.replace(/^\s*font-size:\s*.*$/gmi,"font-size: "+G)
}else{H=H+"\nfont-size: "+G
}}else{H=H.replace(/^\s*font-size:\s*.*$/gmi,"")
}if(F){if(H.match(/^\s*font-family:\s*.*$/gmi)){H=H.replace(/^\s*font-family:\s*.*$/gmi,"font-family: "+F)
}else{H=H+"\nfont-family: "+F
}}else{H=H.replace(/^\s*font-family:\s*.*$/gmi,"")
}if(E){if(H.match(/^\s*color:\s*.*$/gmi)){H=H.replace(/^\s*color:\s*.*$/gmi,"color: "+E)
}else{H=H+"\ncolor: "+E
}}else{H=H.replace(/^\s*color:\s*.*$/gmi,"")
}if(D){if(H.match(/^\s*background-color:\s*.*$/gmi)){H=H.replace(/^\s*background-color:\s*.*$/gmi,"background-color: "+D)
}else{H=H+"\nbackground-color: "+D
}}else{H=H.replace(/^\s*background-color:\s*.*$/gmi,"")
}if(J){if(H.match(/^\s*text-align:\s*.*$/gmi)){H=H.replace(/^\s*text-align:\s*.*$/gmi,"text-align: "+J)
}else{H=H+"\ntext-align: "+J
}if(!H.match(/^\s*display:\s*block\s*$/gmi)){H=H+"\ndisplay: block"
}}else{H=H.replace(/^\s*text-align:\s*.*$/gmi,"");
H=H.replace(/^\s*display:\s*block\s*$/gmi,"")
}if(C){if(H.match(/^\s*vertical-align:\s*.*$/gmi)){H=H.replace(/^\s*vertical-align:\s*.*$/gmi,"vertical-align: "+C)
}else{H=H+"\nvertical-align: "+C
}}else{H=H.replace(/^\s*vertical-align:\s*.*$/gmi,"")
}if(I){if(H.match(/^\s*text-decoration:\s*.*$/gmi)){H=H.replace(/^\s*text-decoration:\s*.*$/gmi,"text-decoration: line-through")
}else{H=H+"\ntext-decoration: line-through"
}}else{H=H.replace(/^\s*text-decoration:\s*.*$/gmi,"")
}jQuery(document.styleForm.styleText).val(jQuery.trim(H))
};
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(J){this.resetSpanText();
var H=J.match(/^<span\s+.*?style="([\s\S]*?)"[\s\S]*<\/span>$/i);
if(H&&H.length==2){var I=H[1];
var D=I.split(";");
for(var E=0;
E<D.length;
E++){var C=D[E].split(":");
var F=jQuery.trim(C[0]);
var G=jQuery.trim(C[1]);
if(F&&G){this.setSpanTextValue(F,G);
document.styleForm.removeStyleButton.disabled=false
}}}this.mergeBasicStyleToAdvanced()
};
this.setSpanTextVisualEditor=function(D){this.resetSpanText();
if(D&&jQuery(D).attr("style")){document.styleForm.removeStyleButton.disabled=false;
if(D.style.length){for(var C=0;
C<D.style.length;
C++){this.setSpanTextValue(D.style[C],D.style[D.style[C].camelize()])
}}else{for(var F in D.style){var E=D.style[F];
if(typeof (E)!="function"){if(E&&E.length>0){this.setSpanTextValue(F,E)
}}}}}this.mergeBasicStyleToAdvanced()
};
this.mergeAdvancedStyleToBasic=function(){var D=jQuery(document.styleForm.styleText).val();
var C;
if(C=D.match(/^\s*font-size:\s*(.+?)\s*$/mi)){this.setSpanTextValue("font-size",C[1])
}if(C=D.match(/^\s*font-family:\s*(.+?)\s*$/mi)){this.setSpanTextValue("font-family",C[1])
}if(C=D.match(/^\s*color:\s*(.+?)\s*$/mi)){this.setSpanTextValue("color",C[1])
}if(C=D.match(/^\s*background-color:\s*(.+?)\s*$/mi)){this.setSpanTextValue("background-color",C[1])
}if(C=D.match(/^\s*text-align:\s*(.+?)\s*$/mi)){this.setSpanTextValue("text-align",C[1])
}if(C=D.match(/^\s*vertical-align:\s*(.+?)\s*$/mi)){this.setSpanTextValue("vertical-align",C[1])
}if(C=D.match(/^\s*text-deocration:\s*(.+?)\s*$/mi)){this.setSpanTextValue("text-decoration",C[1])
}};
this.setSpanTextValue=function(H,G){var E=WikispacesStyleTool.normalizeCssSelector(H);
log("setting "+H+" as "+E+" with "+G);
switch(E){case"fontSize":jQuery(document.styleForm.styleSize).val(G);
break;
case"fontFamily":var C=G.replace(/,.*/gi,"").replace(/\'/gi,"");
jQuery(document.styleForm.styleFont).val(C);
break;
case"color":var F=new RGBColor(G).toHex().toUpperCase();
jQuery(document.styleForm.styleColor).val(F);
jQuery.farbtastic("#colorpickerColor").setColor(F);
break;
case"backgroundColor":var F=new RGBColor(G).toHex().toUpperCase();
jQuery(document.styleForm.styleBackgroundColor).val(F);
jQuery.farbtastic("#colorpickerBackgroundColor").setColor(F);
break;
case"textAlign":jQuery(document.styleForm.styleAlignment).val(G);
break;
case"verticalAlign":jQuery(document.styleForm.styleVertical).val(G);
if(jQuery(document.styleForm.styleVertical).val()!=G){var D=jQuery("<option>").val(G).html(G);
jQuery(document.styleForm.styleVertical).append(D);
jQuery(document.styleForm.styleVertical).val(G)
}break;
case"textDecoration":if(G=="line-through"||G=="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()+H+": "+G)
}};
this.farbtasticCallback=function(C,D){jQuery(D).css({backgroundColor:C,color:this.hsl[2]>0.5?"#000":"#fff"});
jQuery(D).each(function(){this.value=C
})
};
this.getBasicColors=function(){return["#000000","#404040","#808080","#C0C0C0","#FFFFFF","#FF0000","#00FF00","#0000FF","#FFFF00","#00FFFF","#FF00FF","#800000","#008000","#000080","#808000","#008080","#800080"]
};
this.getStyleColors=function(){var C=this.getBasicColors();
var H=this.toolbar.editor.getCurrentArea().styleTool.getPreviousColors();
var G=C;
for(var E=0;
E<H.length;
E++){var F=false;
for(var D=0;
D<C.length;
D++){if(H[E]==C[D]){F=true;
break
}}if(!F){G[G.length]=H[E]
}}return G
};
this.adjustFont=function(C){var D=jQuery(document.styleForm.styleSize).val();
if(D.match(/%\s*$/gi)){D=parseInt(D);
D+=C;
jQuery(document.styleForm.styleSize).val(D+"%")
}this.updatePreviewStyle()
};
this.hideColorPickers=function(){jQuery("#colorpickerColor").hide();
jQuery("#colorpickerBackgroundColor").hide();
jQuery("#styleColors").hide()
};
this.setup=function(){jQuery("#switchToAdvanced").click(function(){A.hideColorPickers();
A.mergeBasicStyleToAdvanced();
jQuery("#stylePopupContents .styleAdvanced").show();
jQuery("#stylePopupContents .styleBasic").hide();
return false
});
jQuery("#switchToBasic").click(function(){A.mergeAdvancedStyleToBasic();
jQuery("#stylePopupContents .styleAdvanced").hide();
jQuery("#stylePopupContents .styleBasic").show();
return false
});
jQuery("#styleAdvancedTextarea").keyup(function(){A.updatePreviewStyle()
});
jQuery("#styleAdvancedTextarea").change(function(){A.updatePreviewStyle()
});
jQuery("#styleFont").focus(function(){A.hideColorPickers()
});
jQuery("#styleFont").change(function(){A.updatePreviewStyle()
});
jQuery("#sizeDown").click(function(){A.hideColorPickers();
A.adjustFont(-10);
return false
});
jQuery("#styleSize").focus(function(){A.hideColorPickers()
});
jQuery("#styleSize").keyup(function(){A.updatePreviewStyle()
});
jQuery("#sizeUp").click(function(){A.hideColorPickers();
A.adjustFont(10);
return false
});
jQuery("#styleColor").focus(function(){A.hideColorPickers();
jQuery("#colorpickerColor").show();
jQuery("#styleColors").show();
A.currentColorInput=this
});
jQuery("#styleColor").focus(function(){A.updatePreviewStyle()
});
jQuery("#styleBackgroundColor").focus(function(){A.hideColorPickers();
jQuery("#colorpickerBackgroundColor").show();
jQuery("#styleColors").show();
A.currentColorInput=this
});
jQuery("#styleBackgroundColor").focus(function(){A.updatePreviewStyle()
});
jQuery("#styleAlignment").focus(function(){A.hideColorPickers()
});
jQuery("#styleAlignment").change(function(){A.updatePreviewStyle()
});
jQuery("#styleVertical").focus(function(){A.hideColorPickers()
});
jQuery("#styleVertical").change(function(){A.updatePreviewStyle()
});
jQuery("#styleStrike").focus(function(){A.hideColorPickers()
});
jQuery("#styleStrike").click(function(){A.updatePreviewStyle()
}).change(function(){A.updatePreviewStyle()
});
jQuery("#applyStyleButton").click(function(){if(jQuery("#stylePopupContents .styleBasic").is(":visible")){A.mergeBasicStyleToAdvanced()
}A.toolbar.editor.getCurrentArea().styleTool.applyStyle();
A.stylePopup.close();
return false
});
jQuery("#removeStyleButton").click(function(){A.toolbar.editor.getCurrentArea().styleTool.removeStyle();
A.stylePopup.close()
});
jQuery("#styleCancel").click(function(){A.stylePopup.close();
return false
});
jQuery("#colorpickerColor").farbtastic(function(C){A.farbtasticCallback.call(this,C,document.styleForm.styleColor);
A.updatePreviewStyle()
});
jQuery("#colorpickerBackgroundColor").farbtastic(function(C){A.farbtasticCallback.call(this,C,document.styleForm.styleBackgroundColor);
A.updatePreviewStyle()
})
}
}function WikispacesTableTool(B){this.area=B;
this.selectedTableCell;
var A=this;
this.selectTableCell=function(C){log("selectTableCell",C);
this.selectedTableCell=C;
this.area.editor.toolbar.tableToolbar.hideTablePropertiesPopup();
this.area.editor.toolbar.tableToolbar.showTablePropertiesMenuHandle();
this.area.editor.toolbar.tableToolbar.selectTableCell(C)
};
this.unselectTableCell=function(){if(this.selectedTableCell){this.removeHighlight();
this.selectedTableCell=null
}this.area.editor.toolbar.tableToolbar.hideTablePropertiesPopup()
};
this.highlightCell=function(C){if(this.selectedTableCell){jQuery(this.selectedTableCell).addClass(C)
}};
this.highlightCellForMerge=function(C){if(this.selectedTableCell){if(C){jQuery(this.selectedTableCell).prev("td,th").addClass("highlightTableCellForMerge")
}else{jQuery(this.selectedTableCell).next("td,th").addClass("highlightTableCellForMerge")
}}};
this.highlightCellForRowMerge=function(D){if(this.selectedTableCell){var C=this.getColumnNumber(this.selectedTableCell);
if(D){this.getColumnInPosition(jQuery(this.selectedTableCell).parent().prev("tr").children("td,th"),C).addClass("highlightTableCellForMerge")
}else{this.getColumnInPosition(jQuery(this.selectedTableCell).parent().next("tr").children("td,th"),C).addClass("highlightTableCellForMerge")
}}};
this.convertCells=function(D,C){var E=this.area.getEditorWindow().document;
jQuery(D).each(function(F){var H=parseInt(jQuery(this).attr("colspan"));
var G=E.createElement(C);
jQuery(G).attr("colspan",H);
jQuery(G).html(jQuery(this).html());
jQuery(this).replaceWith(G);
if(this==this.selectedTableCell){this.selectTableCell(G)
}})
};
this.convertCellType=function(){var C=jQuery(this.selectedTableCell).is("td")?"th":"td";
this.convertCells(this.selectedTableCell,C)
};
this.convertColType=function(){var D=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);
var C=jQuery(this.selectedTableCell).is("td")?"th":"td";
this.convertCells(D,C)
};
this.convertRowType=function(){var D=jQuery(this.selectedTableCell).parent("tr").find("td,th");
var C=jQuery(this.selectedTableCell).is("td")?"th":"td";
this.convertCells(D,C)
};
this.mergeCell=function(G){if(this.selectedTableCell){var F=this.area.getEditorWindow().document;
var C=this.selectedTableCell.innerHTML;
var J=parseInt(jQuery(this.selectedTableCell).attr("colspan")>1?jQuery(this.selectedTableCell).attr("colspan"):1);
if(G){jQuery(this.selectedTableCell).prev("td,th").remove()
}else{jQuery(this.selectedTableCell).next("td,th").remove()
}var E="td";
if(jQuery(this.selectedTableCell).is("th")){E="th"
}var I=F.createElement(E);
jQuery(I).html(jQuery(this.selectedTableCell).html());
jQuery(I).attr("colspan",J+1);
jQuery(this.selectedTableCell).replaceWith(I);
var H=jQuery(I).parent("tr").eq(0);
var D=F.createElement("tr");
jQuery(D).html(jQuery(H).html());
jQuery(H).after(D);
jQuery(H).remove();
this.unselectTableCell()
}};
this.splitCell=function(){if(this.selectedTableCell&&jQuery(this.selectedTableCell).attr("colspan")>1){var F="td";
if(jQuery(this.selectedTableCell).is("th")){F="th"
}var E="<"+F+">"+jQuery(this.selectedTableCell).html()+"</"+F+">";
var C=parseInt(jQuery(this.selectedTableCell).attr("colspan"))-1;
for(var D=0;
D<C;
D++){E+="<td>&nbsp;</td>"
}jQuery(this.selectedTableCell).replaceWith(E);
this.unselectTableCell()
}};
this.highlightTable=function(C){if(this.selectedTableCell){jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).find("td,th").each(function(D){jQuery(this).addClass(C)
})
}};
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(C){if(this.selectedTableCell){jQuery(this.selectedTableCell).parent("tr").eq(0).find("td,th").each(function(D){jQuery(this).addClass(C)
})
}};
this.getColumnNumber=function(F){var C=0;
var E=jQuery(F).prevAll("td,th");
for(var D=0;
D<E.length;
D++){C+=parseInt(jQuery(E[D]).attr("colspan")>1?jQuery(E[D]).attr("colspan"):1)
}return C
};
this.getColumnInPosition=function(E,C){for(var D=0;
D<E.length;
D++){if(this.getColumnNumber(E[D])>=C){return E[D]
}}};
this.highlightSelectedCol=function(){this.highlightCol("highlightTableCell")
};
this.highlightColForRemoval=function(){this.highlightCol("highlightTableCellForRemoval")
};
this.highlightCol=function(D){if(this.selectedTableCell){var C=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);
jQuery(C).each(function(E){jQuery(this).addClass(D)
})
}};
this.removeHighlight=function(C){if(C){jQuery(this.selectedTableCell).parents("table.wiki_table").find("."+C).each(function(D){jQuery(this).removeClass(C)
})
}else{jQuery(this.selectedTableCell).parents("table.wiki_table").find(".highlightTableCell,.highlightTableCellForRemoval,.highlightTableCellForMerge").each(function(D){jQuery(this).removeClass("highlightTableCell").removeClass("highlightTableCellForRemoval").removeClass("highlightTableCellForMerge")
})
}};
this.addNewRow=function(H,G){if(this.selectedTableCell){var F=0;
var C=jQuery(this.selectedTableCell).parent("tr").eq(0).find("td,th");
for(var E=0;
E<C.length;
E++){F+=parseInt(jQuery(C[E]).attr("colspan")>1?jQuery(C[E]).attr("colspan"):1)
}if(H){var D='<tr class="tablePreview"><td colspan="'+F+'">&nbsp;</td></tr>'
}else{var D="<tr>";
for(var E=0;
E<F;
E++){D+="<td>&nbsp;</td>"
}D+="</tr>"
}if(G){jQuery(this.selectedTableCell).parent("tr").eq(0).before(D)
}else{jQuery(this.selectedTableCell).parent("tr").eq(0).after(D)
}if(!H){this.removePreviews();
this.unselectTableCell()
}}};
this.removeRow=function(){if(this.selectedTableCell){var C=jQuery(this.selectedTableCell).parent("tr").eq(0).remove();
this.unselectTableCell()
}};
this.addNewCol=function(F,E){if(this.selectedTableCell){if(F){var H='<td class="tablePreview">&nbsp;&nbsp;&nbsp;&nbsp;</td>'
}else{var H="<td>&nbsp;</td>"
}var C=this.getColumnNumber(this.selectedTableCell);
if(!E){var G=parseInt(jQuery(this.selectedTableCell).attr("colspan")>1?jQuery(this.selectedTableCell).attr("colspan"):1);
C=C+G-1
}var D=this.getColCells(C,true);
jQuery(D).each(function(I){if(E){jQuery(this).before(H)
}else{jQuery(this).after(H)
}});
if(!F){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 C=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);
jQuery(C).each(function(D){jQuery(this).remove()
});
this.unselectTableCell()
}};
this.alignCell=function(C){if(jQuery(this.selectedTableCell).is("td")){jQuery(this.selectedTableCell).css("text-align",C)
}};
this.alignRow=function(D){var C=jQuery(this.selectedTableCell).parent("tr").eq(0).find("td,th");
jQuery(C).each(function(E){if(jQuery(this).is("td")){jQuery(this).css("text-align",D)
}})
};
this.alignCol=function(D){var C=this.getColCells(this.getColumnNumber(this.selectedTableCell),false);
jQuery(C).each(function(E){if(jQuery(this).is("td")){jQuery(this).css("text-align",D)
}})
};
this.alignTable=function(D){var C=jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).find("td,th");
jQuery(C).each(function(E){if(jQuery(this).is("td")){jQuery(this).css("text-align",D)
}})
};
this.getColCells=function(H,D){if(this.selectedTableCell){var K=jQuery(this.selectedTableCell).parents("table.wiki_table").eq(0).find("tr");
var F=new Array();
for(var G=0;
G<K.length;
G++){var E=0;
var J=jQuery(K[G]).children();
var I=0;
for(var C=0;
C<J.length;
C++){I+=parseInt(jQuery(J[C]).attr("colspan")>1?jQuery(J[C]).attr("colspan"):1);
if(I>H){F[F.length]=J[C];
break
}else{if(I>H&&D){F[F.length]=J[C-1];
break
}}}}return F
}};
this.removePreviews=function(){jQuery(this.selectedTableCell).parents("table.wiki_table").find(".tablePreview").each(function(C){jQuery(this).remove()
})
};
this.addTable=function(H,E){WikispacesCommon.track("Editor","Add Table",H+"x"+E);
if(this.area.editor.mode==this.area.editor.VISUAL){var F='<table class="wiki_table" id="__newTable__">\n';
for(var L=0;
L<H;
L++){F+="<tr>\n";
for(var G=0;
G<E;
G++){F+="<td></td>\n"
}F+="</tr>\n"
}F+="</table>\n";
this.area.insertInEditor(F);
this.area.showGuidelines("");
var J=jQuery(this.area.getEditorWindow().document.body).find("#__newTable__").attr("id","");
J.find("td,th").each(function(){if(jQuery(this).height()<20){jQuery(this).height(20)
}if(jQuery(this).width()<5){jQuery(this).width(5)
}});
var I=J.find("td:first,th:first").get(0);
var D=new Selection(this.area.getEditorWindow());
var C=D.getRangeAt(0);
C.selectNode(I);
this.area.selectElement(I);
this.area.getEditorWindow().focus()
}else{var K="";
for(var L=0;
L<H;
L++){K+="\n||";
for(G=0;
G<E;
G++){K+=" ||"
}}K+="\n";
this.area.insertInEditor(K)
}}
}function WikispacesTableToolbar(B){this.toolbar=B;
this.tablePopup;
this.tablePropertiesShown=false;
this.menuHandleLoaded=false;
var A=this;
this.openTablePopup=function(){if(this.toolbar.editor.getCurrentArea().tableTool.selectedTableCell){this.showTablePropertiesPopup();
return 
}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");
A.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 C=this.toolbar.getPositionWith(jQuery("#tablePropertiesMenuHandle").get(0),this.toolbar.editor.getCurrentArea().tableTool.selectedTableCell);
jQuery("#tablePropertiesMenuHandle").css("position","absolute").css("left",C.left+5).css("top",C.top+5).show();
var D=this.toolbar.editor.getCurrentArea().getZIndex();
jQuery("#tablePropertiesMenuHandle").css("z-index",D);
this.tablePropertiesShown=true
};
this.showTablePropertiesPopup=function(){jQuery("#tablePropertiesMenuHandle").hide();
var C=this.toolbar.getPositionWith(jQuery("#tableProperties").get(0),this.toolbar.editor.getCurrentArea().tableTool.selectedTableCell);
jQuery("#tableProperties").css("position","absolute").css("left",C.left+5).css("top",C.top+5).show();
var D=this.toolbar.editor.getCurrentArea().getZIndex();
jQuery("#tableProperties").css("z-index",D);
this.tablePropertiesShown=true
};
this.selectTableCell=function(C){if(jQuery(C).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")
}if(jQuery(C).attr("colspan")>1){jQuery("#tablePropertiesList .mergeSplit").removeClass("disabledMenu")
}else{jQuery("#tablePropertiesList .mergeSplit").addClass("disabledMenu")
}if(jQuery(C).prev("td,th").length>0){jQuery("#tablePropertiesList .mergeLeft").removeClass("disabledMenu")
}else{jQuery("#tablePropertiesList .mergeLeft").addClass("disabledMenu")
}if(jQuery(C).next("td,th").length>0){jQuery("#tablePropertiesList .mergeRight").removeClass("disabledMenu")
}else{jQuery("#tablePropertiesList .mergeRight").addClass("disabledMenu")
}};
this.tablePropertiesShow=function(D,C){if(D.is("ul")&&D.is(":visible")){D.slideUp("fast")
}if(D.is("ul")&&!D.is(":visible")){jQuery(C).slideUp("fast");
D.slideDown("fast")
}};
this.getScope=function(D){var C;
var E=jQuery(D);
if(E.is("#cellItem")||E.parents("#cellItem").length){C="Cell"
}else{if(E.is("#rowItem")||E.parents("#rowItem").length){C="Row"
}else{if(E.is("#colItem")||E.parents("#colItem").length){C="Col"
}else{if(E.is("#tableItem")||E.parents("#tableItem").length){C="Table"
}}}}return C
};
this.setup=function(){jQuery("#addTableButton").click(function(){A.toolbar.editor.getCurrentArea().tableTool.addTable(document.insertTableForm.rows.value,document.insertTableForm.cols.value);
A.tablePopup.close()
});
jQuery("#tableCancelLink").click(function(){A.tablePopup.close();
return false
})
};
this.setupMenu=function(){jQuery("#tablePropertiesList ul").hide();
jQuery("#tablePropertiesList .topmenu").click(function(C){C.stopPropagation();
A.tablePropertiesShow(jQuery(this).next(),"#tablePropertiesList li ul:visible");
return false
});
jQuery("#tablePropertiesList .submenu").click(function(C){C.stopPropagation();
A.tablePropertiesShow(jQuery(this).next(),"#tablePropertiesList li ul li ul:visible");
return false
});
jQuery("#tablePropertiesMenuHandle").click(function(C){C.stopPropagation();
jQuery("#tablePropertiesList ul").hide();
A.showTablePropertiesPopup();
return false
});
jQuery("#cellItem, #rowItem, #colItem, #tableItem").mouseover(function(){var C="highlight"+A.getScope(this);
A.toolbar.editor.getCurrentArea().tableTool[C]("highlightTableCell");
return true
});
jQuery("#cellItem, #rowItem, #colItem, #tableItem").mouseout(function(){A.toolbar.editor.getCurrentArea().tableTool.removeHighlight();
return true
});
jQuery("#tableProperties .mergeMenu li").mouseover(function(){var D;
var C;
switch(jQuery(this).attr("class")){case"mergeLeft":C=true;
D="highlight"+A.getScope(this)+"ForMerge";
break;
case"mergeRight":C=false;
D="highlight"+A.getScope(this)+"ForMerge";
break;
case"mergeUp":C=true;
D="highlight"+A.getScope(this)+"ForRowMerge";
break;
case"mergeDown":C=false;
D="highlight"+A.getScope(this)+"ForRowMerge";
break
}if(D){A.toolbar.editor.getCurrentArea().tableTool[D](C)
}return true
});
jQuery("#tableProperties .mergeMenu li").mouseout(function(){A.toolbar.editor.getCurrentArea().tableTool.removeHighlight("highlightTableCellForMerge");
return true
});
jQuery("#tableProperties .mergeMenu li").click(function(){var D;
var C;
switch(jQuery(this).attr("class")){case"mergeLeft":C=true;
D="merge"+A.getScope(this);
break;
case"mergeRight":C=false;
D="merge"+A.getScope(this);
break;
case"mergeUp":C=true;
D="mergeRow"+A.getScope(this);
break;
case"mergeDown":C=false;
D="mergeRow"+A.getScope(this);
break;
case"mergeSplit":C=A.toolbar.editor.getCurrentArea().tableTool.selectTableCell;
D="splitCell";
break
}A.toolbar.editor.getCurrentArea().tableTool[D](C);
return false
});
jQuery("#tableProperties .headerMenu").click(function(){var C=A.toolbar.editor.getCurrentArea().tableTool.selectTableCell;
var D="convert"+A.getScope(this)+"Type";
A.toolbar.editor.getCurrentArea().tableTool[D]();
return false
});
jQuery("#tableProperties .addMenu li").mouseover(function(){var D;
var C;
switch(jQuery(this).attr("class")){case"addPre":log("pre");
C=true;
D="addNew"+A.getScope(this);
break;
case"addPost":log("post");
C=false;
D="addNew"+A.getScope(this);
break
}A.toolbar.editor.getCurrentArea().tableTool[D](true,C);
return true
});
jQuery("#tableProperties .addMenu li").mouseout(function(){A.toolbar.editor.getCurrentArea().tableTool.removePreviews();
return true
});
jQuery("#tableProperties .addMenu li").click(function(){var D;
var C;
switch(jQuery(this).attr("class")){case"addPre":C=true;
D="addNew"+A.getScope(this);
break;
case"addPost":C=false;
D="addNew"+A.getScope(this);
break
}A.toolbar.editor.getCurrentArea().tableTool[D](false,C);
return false
});
jQuery("#tableProperties .alignmentMenu li").click(function(){var D="align"+A.getScope(this);
var C=jQuery(this).attr("class");
A.toolbar.editor.getCurrentArea().tableTool[D](C);
return false
});
jQuery("#tableProperties .removeMenu").mouseover(function(){var C="highlight"+A.getScope(this)+"ForRemoval";
A.toolbar.editor.getCurrentArea().tableTool[C]();
return true
});
jQuery("#tableProperties .removeMenu").mouseout(function(){A.toolbar.editor.getCurrentArea().tableTool.removeHighlight("highlightTableCellForRemoval");
return true
});
jQuery("#tableProperties .removeMenu").click(function(){var C="remove"+A.getScope(this);
A.toolbar.editor.getCurrentArea().tableTool[C]();
return false
})
}
}function WikispacesTextEditor(){this.openStylePopup=function(){this.expandSelectionToTag("<span","","</span>");
var A=this.getSelectedText();
this.editor.toolbar.styleToolbar.openStylePopup();
this.editor.toolbar.styleToolbar.setSpanTextTextEditor(A)
};
this.insertImageInEditorCallback=function(E,C,F){var D=document.forms.imageToolForm;
if("embed"==D.insertMode.value){if(C=="media"){this.insertInEditor('[[media type="file" key="'+E+'"]]')
}else{var A="";
if(C=="image"&&F.width>800){var B=Math.floor((800/F.width)*F.height);
A=' width="800" height="'+B+'"'
}this.insertInEditor("[["+C+":"+E+A+"]]")
}}else{this.insertInEditor("[[http://"+window.location.hostname+"/file/view/"+encodeURIComponent(E)+"|"+E+"]]")
}};
this.editorSubmit=function(){this.autosave(false);
var C=jQuery("#mergeStatus").html();
var B=jQuery("#mergeResult").val();
if(C=="success"){jQuery("#textEditor").val(B);
WikispacesCommon.track("Editor","Concurrent Editing","Merge Success")
}if(this.anotherEditDetected&&C!="success"&&this.editorSaving){this.showConcurrentEditorPopup();
this.editorSaving=false;
var A=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.");
if(A){jQuery("#textEditor").val(B);
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(C){var E=document.getElementById("textEditor");
E.focus();
if(document.selection){sel=document.selection.createRange();
sel.text=C;
sel.select()
}else{if(E.selectionStart||E.selectionStart=="0"){var D=E.scrollTop;
var B=E.selectionStart;
var A=E.selectionEnd;
E.value=E.value.substring(0,B)+C+E.value.substring(A,E.value.length);
if(B==A){this.setSelectionRange(E,B+C.length,B+C.length)
}else{this.setSelectionRange(E,B,B+C.length)
}E.scrollTop=D
}else{E.value+=C
}}this.detectedChange()
};
this.insertCode=function(){var A=document.codeForm.code.value;
var B=document.codeForm.format.value;
if(!B){B="text"
}WikispacesCommon.track("Editor","Add Code",B);
this.insertInEditor('\n[[code format="'+B+'"]]\n'+A+"\n[[code]]\n");
document.codeForm.reset();
Windows.close("codePopup")
};
this.addListInTextEditor=function(F){if(!this.getSelectedText()){this.expandSelectionToLine()
}var D=document.getElementById("textEditor");
this.prepareSelection(D);
var H=D.sel_text;
var A="";
var G=true;
var B=H.split("\n");
for(var C=0;
C<B.length;
C++){var E;
if(E=B[C].match(/^(\#|\*|\>)+\s(.*)$/i)){if(E[1].charAt(0)!=F){G=false
}A+="\n"+F+" "+E[2]
}else{G=false;
A+="\n"+F+" "+B[C]
}}if(D.sel_text_pre.length==0||D.sel_text_pre.charAt(D.sel_text_pre.length-1)=="\n"){A=A.substring(1,A.length)
}if(G){var H=D.sel_text;
A="";
var B=H.split("\n");
for(var C=0;
C<B.length;
C++){if(E=B[C].match(/^(\#|\*|\>)+\s(.*)$/i)){A+=E[2]+"\n"
}}if(D.sel_text.charAt(D.sel_text.length-1)!="\n"){A=A.substring(0,A.length-1)
}}this.insertInEditor(A)
};
this.wrapTextEditorSelection=function(K){var F=this.getSelectedText();
var J=F.length;
F=F.replace(/^\s+/,"");
var B=J-F.length;
F=F.replace(/\s+$/,"");
var I=J-B-F.length;
var A="";
if(F.substring(0,K.length)==K&&F.substring(F.length-K.length,F.length)==K){A=F.substring(K.length,F.length-K.length)
}else{A=K+F+K
}for(var H=0;
H<B;
H++){A=" "+A
}for(var H=0;
H<I;
H++){A=A+" "
}var G=document.getElementById("textEditor");
this.prepareSelection(G);
var D=G.cur_start;
var E=G.cur_end;
var C=A.length;
if(jQuery.browser.msie){for(var H=0;
H<=A.length;
H++){if(A.charAt(H)=="\n"){C--
}}}this.insertInEditor(A);
if(D==E){this.setSelectionRange(G,D+(C/2),D+(C/2))
}else{this.setSelectionRange(G,D,C+D)
}G.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 B=this.getSelectedText();
if(B!="[[code]]"&&!B.match(/^\[\[media /)&&!B.match(/^\[\[file /)&&!B.match(/^\[\[image /)&&!B.match(/^\[\[include /)){var A=B.match(/(\s*)\[\[([^\]]*)\]\](\s*)/);
B=A[1]+A[2]+A[3];
this.insertInEditor(B);
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 A;
this.editor.toolbar.mediaToolbar.showMediaTool();
this.editor.toolbar.mediaToolbar.setMediaMenu("main");
if(this.expandSelectionToTag("[[","media","]]")){A=this.getSelectedText().match(/\[\[media (.*)\]\]/)[1];
this.editor.toolbar.mediaToolbar.loadMedia("wikitext@@media@@"+A)
}else{if(this.expandSelectionToTag("[[","rss","]]")){A=this.getSelectedText().match(/\[\[rss (.*)\]\]/)[1];
this.editor.toolbar.mediaToolbar.loadMedia("wikitext@@rss@@"+A)
}}};
this.editorSelectFont=function(E){var B=E.options[E.selectedIndex].value;
WikispacesCommon.track("Editor","Select Font",B);
var A="";
if(B=="<h1>"){A="="
}else{if(B=="<h2>"){A="=="
}else{if(B=="<h3>"){A="==="
}else{if(B=="<h4>"){A="===="
}else{if(B=="<h5>"){A="====="
}else{if(B=="<h6>"){A="======"
}}}}}}if(A){if(this.getSelectedText()){this.insertInEditor("\n"+A+this.getSelectedText()+A+"\n")
}else{var C=document.getElementById("textEditor");
this.prepareSelection(C);
var D=C.sel_start+A.length+1;
this.insertInEditor("\n"+A+A+"\n");
this.setSelectionRange(C,D,D)
}}document.getElementById("textEditor").focus();
E.selectedIndex=3
};
this.autosaveLoadDraft=function(A){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(A);
this.detectedChangeDelayed()
};
this.customEditorStartSecondary=function(B){var A=this;
this.editor.toolbar.floatToolbar();
jQuery("#textEditor").keypress(function(){A.detectedChange()
});
WikispacesCommon.track("Editor","Start","Text");
return true
};
this.getSelectedText=function(){var A=document.getElementById("textEditor");
if(A){this.prepareSelection(A);
return(A.sel_text?A.sel_text:"")
}return""
}
}var TimeTracker=function(A){if(A){this.bucket_=A.sort(this.sortNumber)
}else{this.bucket_=TimeTracker.DEFAULT_BUCKET
}};
TimeTracker.prototype.startTime_;
TimeTracker.prototype.stopTime_;
TimeTracker.prototype.bucket_;
TimeTracker.DEFAULT_BUCKET=[100,500,1500,2500,5000];
TimeTracker.prototype._getTimeDiff=function(){return(this.stopTime_-this.startTime_)
};
TimeTracker.prototype.sortNumber=function(B,A){return(B-A)
};
TimeTracker.prototype._recordStartTime=function(A){if(A!=undefined){this.startTime_=A
}else{this.startTime_=(new Date()).getTime()
}};
TimeTracker.prototype._recordEndTime=function(A){if(A!=undefined){this.stopTime_=A
}else{this.stopTime_=(new Date()).getTime()
}};
TimeTracker.prototype._track=function(F,A,C){var E;
if(A!=undefined&&A.length!=0){E=F._createEventTracker(A)
}else{E=F._createEventTracker("TimeTracker")
}var D;
var B;
for(D=0;
D<this.bucket_.length;
D++){if((this._getTimeDiff())<this.bucket_[D]){if(D==0){B="0-"+(this.bucket_[0]);
break
}else{B=this.bucket_[D-1]+"-"+(this.bucket_[D]-1);
break
}}}if(!B){B=this.bucket_[D-1]+"+"
}E._trackEvent(B,C,this._getTimeDiff())
};
TimeTracker.prototype._setHistogramBuckets=function(A){this.bucket_=A.sort(this.sortNumber)
};
function WikispacesCodeToolbar(B){this.toolbar=B;
var A=this;
this.codePopup;
this.openCodePopup=function(){WikispacesCommon.track("Editor","Open Code Tool");
if(this.toolbar.editor.mode==this.toolbar.editor.VISUAL&&document.getElementById("rteFormatBlock").options[document.getElementById("rteFormatBlock").selectedIndex].value=="<code>"){alert("You cannot insert a code block inside another code block");
return 
}this.toolbar.editor.getCurrentArea().saveCursor();
WindowUtilities.disableScreen("wikispaces","overlay_modal",0);
if(!this.codePopup){this.codePopup=new Window("codePopup",{minWidth:640,title:"Insert Code",resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){WindowUtilities.enableScreen("overlay_modal");
A.toolbar.editor.getCurrentArea().restoreCursor()
},showEffect:Element.show,hideEffect:Element.hide});
this.codePopup.setHTMLContent(WikispacesToolbar.getContent("codePopupContents"),true,true);
this.codePopup.getContent().style.overflow="hidden";
WikispacesToolbar.setPopupSize(this.codePopup,true);
this.setup()
}this.codePopup.showCenter();
this.codePopup.toFront()
};
this.setup=function(){jQuery(document.codeForm.insert).click(function(){A.toolbar.editor.getCurrentArea().insertCode()
});
jQuery("#codeCancel").click(function(){A.codePopup.close();
document.codeForm.reset();
return false
})
}
}function WikispacesCharToolbar(B){this.toolbar=B;
this.charPopupWindow;
var A=this;
this.openCharPopup=function(){WikispacesCommon.track("Editor","Open Character Tool");
this.toolbar.editor.getCurrentArea().saveCursor();
WindowUtilities.disableScreen("wikispaces","overlay_modal",0);
if(!this.charPopupWindow){this.charPopupWindow=new Window("charPopupWindow",{title:"Insert Character",resizable:false,maximizable:false,minimizable:false,className:"wikispaces",onClose:function(){jQuery(A.charPopupWindow.getContent()).find(".hl").removeClass("hl");
WindowUtilities.enableScreen("overlay_modal");
A.toolbar.editor.getCurrentArea().restoreCursor()
},showEffect:Element.show,hideEffect:Element.hide});
this.charPopupWindow.setHTMLContent(WikispacesToolbar.getContent("charPopupContents"),true,true);
this.charPopupWindow.getContent().style.overflow="hidden";
WikispacesToolbar.setPopupSize(this.charPopupWindow,true);
this.setup()
}this.charPopupWindow.showCenter();
this.charPopupWindow.toFront()
};
this.setup=function(){jQuery("#charPopupContents td").hover(function(){jQuery(this).addClass("hl")
},function(){jQuery(this).removeClass("hl")
});
jQuery("#charPopupContents td").click(function(){WikispacesCommon.track("Editor","Add Character",jQuery(this).html());
A.toolbar.editor.getCurrentArea().insertInEditor(jQuery(this).html());
A.charPopupWindow.close()
})
}
}function WikispacesToolbar(A){this.editor=A;
this.imageToolbar=new WikispacesImageToolbar(this);
this.codeToolbar=new WikispacesCodeToolbar(this);
this.charToolbar=new WikispacesCharToolbar(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 B=this;
this.toolbarPopup;
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 C;
if(this.editor.mode==this.editor.PLAIN){C=document.getElementById("textEditor")
}else{C=document.getElementById("editor")
}var D=jQuery(C).offset()["left"]-16;
this.toolbarPopup.element.style.left=D+"px";
if(jQuery.browser.msie&&jQuery.browser.version<7){this.toolbarPopup.element.style.top=document.documentElement.scrollTop+"px";
this.registerOnScroll(function(){WikispacesToolbar.scrollWindow(B.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 D=jQuery(this.toolbarPopup.getContent());
D.find("#rteBoldBtn").click(function(){B.editor.getCurrentArea().editorBold()
});
D.find("#rteItalicBtn").click(function(){B.editor.getCurrentArea().editorItalic()
});
D.find("#rteUnderlineBtn").click(function(){B.editor.getCurrentArea().editorUnderline()
});
D.find("#rteTextColorBtn").click(function(){B.editor.getCurrentArea().openStylePopup()
});
D.find("#rteFormatBlock").change(function(){B.editor.getCurrentArea().editorSelectFont(this)
});
D.find("#rteOrderedListBtn").click(function(){B.editor.getCurrentArea().editorOL()
});
D.find("#rteUnorderedListBtn").click(function(){B.editor.getCurrentArea().editorUL()
});
D.find("#rteHRBtn").click(function(){B.editor.getCurrentArea().editorHR()
});
D.find("#rteLinkBtn").click(function(){B.editor.getCurrentArea().editorInsertLink()
});
D.find("#rteLinkRemoveBtn").click(function(){B.editor.getCurrentArea().editorRemoveLink()
});
D.find("#rteImageBtn").click(function(){B.editor.getCurrentArea().editorInsertImage()
});
D.find("#rteMediaBtn").click(function(){B.editor.getCurrentArea().editorEmbedMedia()
});
D.find("#rteTableBtn").click(function(){B.tableToolbar.openTablePopup()
});
D.find("#rteCharBtn").click(function(){B.charToolbar.openCharPopup()
});
D.find("#rteCodeBtn").click(function(){B.codeToolbar.openCodePopup()
});
var C=(this.editor.mode==this.editor.VISUAL?"Text Editor":"Visual Editor");
jQuery("#switch_to").val(C).html("<span><span>"+C+"</span></span>").attr("name","switch_to_"+(this.editor.mode==this.editor.VISUAL?this.editor.PLAIN:this.editor.VISUAL)).click(function(){B.editor.getMainArea().editorConfirmDeparture=false
});
jQuery("button#switch_top").val(C).html("<span><span>"+C+"</span></span>").click(function(E){jQuery("#switch_to").get(0).click();
E.preventDefault()
});
jQuery("a#switch_top").text(C).click(function(E){jQuery("#switch_to").get(0).click();
E.preventDefault()
});
if((jQuery.browser.safari&&jQuery.browser.version<500)||jQuery.browser.opera){jQuery("#switch_to").hide();
jQuery("#switch_top").hide()
}jQuery(document.rte.preview).click(function(E){B.editor.getMainArea().showPreview();
E.preventDefault()
});
jQuery("#preview_top").click(function(E){document.rte.preview.click();
E.preventDefault()
});
jQuery(document.rte.update).click(function(){B.editor.getMainArea().editorConfirmDeparture=false;
B.editor.getMainArea().editorSaving=true
});
jQuery("#update_top").click(function(E){document.rte.update.click();
E.preventDefault()
});
jQuery("#cancel").attr("href",this.editor.cancelUrl).click(function(E){return B.editor.getMainArea().cancelEdit(this);
E.preventDefault()
});
jQuery("#cancel_top").attr("href",this.editor.cancelUrl).click(function(E){B.editor.getMainArea().cancelEdit(this);
E.preventDefault()
});
jQuery("#saveDraftButton").click(function(E){B.editor.getMainArea().autosave();
E.preventDefault()
});
if(!wikispaces_isUserLoggedIn){jQuery("#saveDraftButton").hide()
}jQuery(document.rte).submit(function(){return B.editor.getMainArea().editorSubmit()
});
if(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.showAutosavePopup=function(D){var C=Dialog.confirm(document.getElementById("autosavePrompt").innerHTML,{title:"Draft Recovered",windowParameters:{className:"wikispaces",width:450},id:"popupDialog",ok:function(){B.editor.getCurrentArea().autosaveLoadDraft(D);
C.hide()
},cancel:function(){B.editor.getCurrentArea().autosaveDiscardDraft(D)
},okLabel:"Load Previous Draft",cancelLabel:"Discard Previous Draft",resizable:false,showEffectOptions:{duration:3}})
};
this.getPositionWith=function(L,G){L=jQuery(L);
G=jQuery(G);
Position.prepare();
var F=Position.cumulativeOffset(G.get(0));
var C=jQuery("#"+this.editor.getCurrentArea().areaId).get(0);
var E=Position.cumulativeOffset(C);
var D=F[0]+E[0]+G.outerWidth({margin:true});
var J=F[1]+E[1]+G.outerHeight({margin:true});
var K=L.outerWidth({margin:true});
var M=jQuery("body").width();
if(D+K>M){D=M-K
}var I=L.outerHeight({margin:true});
var H=jQuery("body").height();
if(J+I>H){}if(J<0){J=0
}if(D<0){D=0
}return{left:D,top:J}
};
this.registerOnScroll=function(C){this.onScrollFunctions[this.onScrollFunctions.length]=C
};
this.onScrollCallback=function(){for(i=0;
i<this.onScrollFunctions.length;
i++){this.onScrollFunctions[i]()
}};
window.onscroll=function(){B.onScrollCallback()
}
}WikispacesToolbar.setPopupSize=function(C,A){var B=jQuery(C.getContent()).children().eq(0);
jQuery(C).ready(function(){setTimeout(function(){var E=B.outerWidth({margin:true});
var D=B.outerHeight({margin:true});
if(jQuery.browser.safari){alternateWidth=B.outerWidth();
alternateHeight=B.outerHeight();
if(alternateWidth>E){E=alternateWidth
}if(alternateHeight>D){D=alternateHeight
}}B.find("table").each(function(){var F=jQuery(this).outerWidth({margin:true});
var G=jQuery(this).outerHeight({margin:true});
if(F>E){E=F
}if(G>D){D=G
}});
B.find("iframe").each(function(){var F=jQuery(this).outerWidth({margin:true})+20;
var G=jQuery(this).outerHeight({margin:true})+20;
if(F>E){E=F
}if(G>D){D=G
}});
if(D<C.options.minHeight){D=C.options.minHeight
}if(E<C.options.minWidth){E=C.options.minWidth
}if(D>jQuery(window).height()-25){D=jQuery(window).height()-25
}if(E>jQuery(window).width()-5){E=jQuery(window).width()-5
}C.setSize(E,D);
if(A){C.showCenter()
}},10)
})
};
WikispacesToolbar.scrollWindow=function(B,A){if(B){if(A){jQuery(B.element).css("top",document.documentElement.scrollTop)
}else{jQuery(B.element).css("top",document.documentElement.clientHeight+document.documentElement.scrollTop-B.element.getHeight())
}}};
WikispacesToolbar.snapPopupToScreen=function(C){var K=jQuery(C.element).width();
var H=jQuery(C.element).height();
var L=document.documentElement.scrollTop;
var B=document.documentElement.scrollLeft;
var J=document.documentElement.clientWidth+document.documentElement.scrollLeft;
var G=document.documentElement.clientHeight+document.documentElement.scrollTop;
var M=false;
var I=false;
var D=Position.positionedOffset(C.element)[0]+K;
if(D>J){M=J-K-5
}var A=Position.positionedOffset(C.element)[1]+H;
if(A>G){I=G-H-5
}var F=Position.positionedOffset(C.element)[0];
if(F<B||(M!==false&&M<B)){M=B
}var E=Position.positionedOffset(C.element)[1];
if(E<L||(I!==false&&I<L)){I=L
}if(M!==false){C.element.style.left=M+"px"
}if(I!==false){C.element.style.top=I+"px"
}};
WikispacesToolbar.getContent=function(A){if(WikispacesContent[A]){return WikispacesContent[A]
}else{throw ("Unloaded editor part: "+A)
}};
function WikispacesVisualEditor(){this.openStylePopup=function(){if(jQuery("#rteFormatBlock").val()=="<code>"){alert("You cannot apply a style inside of a code block.");
return 
}this.editor.toolbar.styleToolbar.openStylePopup();
var A=this.styleTool.getSelectedSpans();
this.styleTool.selectedSpans=A;
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(A[0])
};
this.insertImageInEditorCallback=function(I,K,L){var J=this;
var E=document.forms.imageToolForm;
if("embed"==E.insertMode.value){var F="newImage-"+this.imageTool.newImageIdCounter++;
if(K=="image"){var G="";
if(L.width>800){var B=Math.floor((800/L.width)*L.height);
G=' width="800" height="'+B+'"'
}if(I.substring(0,"http://".length)=="http://"||I.substring(0,"https://".length)=="https://"||I.substring(0,"ftp://".length)=="ftp://"){this.insertInEditor('<img id="'+F+'" src="'+I+'"'+G+"/>")
}else{this.insertInEditor('<img id="'+F+'" src="/file/view/'+encodeURIComponent(I)+'"'+G+"/>")
}var D=this.getEditorWindow().document;
var H=D.getElementById(F);
this.imageTool.selectImage(H)
}else{if(K=="audio"){var C=I.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var A="type=&quot;file&quot; key=&quot;"+C+"&quot;";
F="wikitext@@media@@"+A;
this.insertInEditor('<img src="http://www.'+wikispaces_domain+"/site/embedthumbnail/file-audio/"+encodeURIComponent(I)+'?h=20&w=240" class="WikiMedia WikiMediaFile" id="wikitext@@media@@'+A+'" title="Audio Player: '+C+'" />')
}else{if(K=="video"){var C=I.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var A="type=&quot;file&quot; key=&quot;"+C+"&quot;";
F="wikitext@@media@@"+A;
this.insertInEditor('<img src="http://www.'+wikispaces_domain+"/site/embedthumbnail/file-video/"+encodeURIComponent(I)+'?h=300&w=300" class="WikiMedia WikiMediaFile" id="wikitext@@media@@'+A+'" title="Video Player: '+C+'" />')
}else{var C=I.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
var A=C;
F="wikitext@@file@@"+A;
this.insertInEditor('<img src="http://www.'+wikispaces_domain+"/site/embedthumbnail/file/"+encodeURIComponent(I)+'?h=40&w=200" class="WikiFile" id="wikitext@@file@@'+A+'" title="File: '+C+'" />')
}}}jQuery(this.getEditorWindow().document).find("#"+F).ready(function(){J.lookForHeightChange()
})
}else{this.insertInEditor('<a href="http://'+window.location.hostname+"/file/view/"+encodeURIComponent(I)+'">'+I+"</a>")
}};
this.editorSubmit=function(){this.autosave(false);
var D=jQuery("#mergeStatus").html();
var C=jQuery("#mergeResult").html();
var B=document.getElementById("hdn"+this.areaId);
if(D=="success"){if(B.value==null){B.value=""
}B.value=C;
WikispacesCommon.track("Editor","Concurrent Editing","Merge Success");
return true
}this.rteCleanup();
if(this.anotherEditDetected&&D!="success"&&this.editorSaving){this.showConcurrentEditorPopup();
this.editorSaving=false;
var A=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.");
if(A){B.value=C;
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(A){this.insertInEditorActual(A,true)
};
this.insertInEditorActual=function(G,I){var C=this.getEditorWindow();
C.focus();
if(I){this.restoreCursor()
}C.focus();
this.moveSelectionIntoEditor(C);
if(this.imageTool.selectedImage){jQuery(this.imageTool.selectedImage).replaceWith(G);
this.imageTool.unSelectImage()
}else{if(this.mediaTool.selectedMedia){jQuery(this.mediaTool.selectedMedia).replaceWith(G);
this.mediaTool.unSelectMedia()
}else{if(jQuery.browser.msie){var A=C.document.selection.createRange();
A.pasteHTML(G);
A.collapse(false);
A.select()
}else{var D=C.getSelection();
for(var F=0;
F<D.rangeCount;
F++){D.getRangeAt(F).deleteContents()
}var E=D.getRangeAt(0);
var B=E.createContextualFragment(G);
var H=B.lastChild;
E.insertNode(B);
D.removeAllRanges();
D=C.getSelection();
D.addRange(E);
C.focus()
}}}this.detectedChangeDelayed()
};
this.insertCode=function(){var A=document.codeForm.code.value;
A=A.escapeHTML();
var B=document.codeForm.format.value;
if(!B){B="text"
}WikispacesCommon.track("Editor","Add Code",B);
this.insertInEditor('<pre class="'+B+'">'+A+"</pre>");
document.codeForm.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");
if(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");
if(this.mediaTool.selectedMedia&&this.mediaTool.selectedMedia.parentNode){this.editor.toolbar.mediaToolbar.loadMedia(this.mediaTool.selectedMedia.id)
}};
this.editorSelectFont=function(A){this.selectFont();
this.updateHierarchy()
};
this.autosaveLoadDraft=function(A){WikispacesCommon.track("Editor","Autosave","Load");
this.version=this.autosaveVersion;
document.rte.version.value=this.version;
jQuery("#"+A).html(jQuery("#autosaveContent").val());
this.editorCleanup=this.autosaveCleanup;
this.customEditorStartSecondary(A);
this.detectedChangeDelayed()
};
this.customEditorStartSecondary=function(F){var D=this;
log("customEditorStartSecondary",F);
try{var B=false;
if(""==jQuery.trim(document.getElementById(F).innerHTML)&&this.mainEditor){B=true;
document.getElementById(F).innerHTML=WikispacesToolbar.getContent("blankPageContent")
}this.styleTool.cleanup(document.getElementById(F),this.editorCleanup);
this.startingSpanCount=document.getElementById(F).getElementsByTagName("span").length;
var A=Element.getDimensions(document.getElementById(F)).height;
if(A<300){A=300
}document.getElementById(this.areaId).height=A;
if(this.mainEditor){this.referenceTool.pullOutReferences(F);
log("success with pull out references")
}this.enableDesignMode(document.getElementById(F).innerHTML,this.editor.stylesheetUrl);
var C=jQuery(document.getElementById(this.areaId)).ready;
if(jQuery.browser.msie&&parseInt(jQuery.browser.version.substring(0,jQuery.browser.version.indexOf(".")))<=7){C=jQuery(document.getElementById(this.areaId)).load
}C.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(500000);
var H=D.getEditorWindow().document;
var G=H.getElementById("editor_body").scrollHeight;
jQuery("#"+D.areaId).height(G)
}D.lookForHeightChange();
jQuery(D.getEditorWindow().document.body).find("img").load(function(){D.lookForHeightChange()
});
setTimeout(function(){D.lookForHeightChange()
},1000);
if(D.mainEditor){D.initialRteCommands()
}D.attachDoubleClickEventHandlers(D.getEditorWindow().document)
});
if(this.mainEditor){this.editor.toolbar.floatToolbar()
}this.attachEditorEventHandlers();
WikispacesCommon.track("Editor","Start","Visual")
}catch(E){log("customEditorStartSecondary ("+this.areaId+") exception: "+E.name+" - "+E.message,E);
return false
}return true
};
this.attachEditorEventHandlers=function(){var B=this;
log("attachEditorEventHandlers");
var A=this.getEditorWindow().document;
jQuery(A).keyup(function(C){B.keyEventHandler(C)
});
jQuery(A).mousedown(function(C){B.mouseEventHandler(C)
});
jQuery(A).keydown(function(C){B.handleTabs(C)
});
if(jQuery.browser.msie){jQuery(A).keydown(function(C){B.ieKeyPress(C)
})
}if(jQuery.browser.safari){jQuery(A).keypress(function(C){B.safariKeyPress(C)
})
}if(jQuery.browser.mozilla){jQuery(A).keypress(function(C){B.geckoKeyPress(C)
})
}jQuery(A.body).focus(function(){B.editor.setCurrentArea(B.areaId)
})
};
this.getSelectedText=function(){if(jQuery.browser.msie){return this.getEditorWindow().document.selection.createRange().text
}else{var A=new Selection(this.getEditorWindow());
return A.getRangeAt(0).toString()
}}
}var Window=Class.create();
Window.keepMultiModalWindow=false;
Window.hasEffectLib=(typeof Effect!="undefined");
Window.resizeEffectDuration=0.4;
Window.prototype={initialize:function(){var C;
var B=0;
if(arguments.length>0){if(typeof arguments[0]=="string"){C=arguments[0];
B=1
}else{C=arguments[0]?arguments[0].id:null
}}if(!C){C="window_"+new Date().getTime()
}if($(C)){alert("Window "+C+" 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[B]||{});
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);
if(this.options.destroyOnClose){this.destroy()
}}.bind(this)
}if(this.options.parent!=document.body){this.options.parent=$(this.options.parent)
}this.element=this._createWindow(C);
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 A=this;
[this.topbar,this.topbar.up().previous(),this.topbar.up().next()].each(function(D){D.observe("mousedown",A.eventMouseDown);
D.addClassName("top_draggable")
});
[this.bottombar.up(),this.bottombar.up().previous(),this.bottombar.up().next()].each(function(D){D.observe("mousedown",A.eventMouseDown);
D.addClassName("bottom_draggable")
})
}if(this.options.resizable){this.sizer=$(this.element.id+"_sizer");
Event.observe(this.sizer,"mousedown",this.eventMouseDown)
}this.useLeft=null;
this.useTop=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);
if(this.options.zIndex){this.setZIndex(this.options.zIndex)
}if(this.options.destroyOnClose){this.setDestroyOnClose(true)
}this._getWindowBorderSize();
this.width=this.options.width;
this.height=this.options.height;
this.visible=false;
this.constraint=false;
this.constraintPad={top:0,left:0,bottom:0,right:0};
if(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){var C=this.getContent();
var A=null;
for(var B=0;
B<C.childNodes.length;
B++){A=C.childNodes[B];
if(A.nodeType==1){break
}A=null
}if(A){this._oldParent.appendChild(A)
}this._oldParent=null
}if(this.sizer){Event.stopObserving(this.sizer,"mousedown",this.eventMouseDown)
}if(this.options.url){this.content.src=null
}if(this.iefix){Element.remove(this.iefix)
}Element.remove(this.element);
Windows.unregister(this)
},setCloseCallback:function(A){this.options.closeCallback=A
},getContent:function(){return this.content
},setContent:function(G,F,B){var A=$(G);
if(null==A){throw"Unable to find element '"+G+"' in DOM"
}this._oldParent=A.parentNode;
var E=null;
var D=null;
if(F){E=Element.getDimensions(A)
}if(B){D=Position.cumulativeOffset(A)
}var C=this.getContent();
this.setHTMLContent("");
C=this.getContent();
C.appendChild(A);
A.show();
if(F){this.setSize(E.width,E.height)
}if(B){this.setLocation(D[1]-this.heightN,D[0]-this.widthW)
}},setHTMLContent:function(A){if(this.options.url){this.content.src=null;
this.options.url=null;
var B='<div id="'+this.getId()+'_content" class="'+this.options.className+'_content"> </div>';
$(this.getId()+"_table_content").innerHTML=B;
this.content=$(this.element.id+"_content")
}this.getContent().innerHTML=A
},setAjaxContent:function(B,A,D,C){this.showFunction=D?"showCenter":"show";
this.showModal=C||false;
A=A||{};
this.setHTMLContent("");
this.onComplete=A.onComplete;
if(!this._onCompleteHandler){this._onCompleteHandler=this._setAjaxContent.bind(this)
}A.onComplete=this._onCompleteHandler;
new Ajax.Request(B,A);
A.onComplete=this.onComplete
},_setAjaxContent:function(A){Element.update(this.getContent(),A.responseText);
if(this.onComplete){this.onComplete(A)
}this.onComplete=null;
this[this.showFunction](this.showModal)
},setURL:function(A){if(this.options.url){this.content.src=null
}this.options.url=A;
var B="<iframe frameborder='0' name='"+this.getId()+"_content'  id='"+this.getId()+"_content' src='"+A+"' width='"+this.width+"' height='"+this.height+"'> </iframe>";
$(this.getId()+"_table_content").innerHTML=B;
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(B,C,M,E,A){B=B||this.element.id;
this.cookie=[B,C,M,E,A];
var K=WindowUtilities.getCookie(B);
if(K){var L=K.split(",");
var I=L[0].split(":");
var H=L[1].split(":");
var J=parseFloat(L[2]),F=parseFloat(L[3]);
var G=L[4];
var D=L[5];
this.setSize(J,F);
if(G=="true"){this.doMinimize=true
}else{if(D=="true"){this.doMaximize=true
}}this.useLeft=I[0]=="l";
this.useTop=H[0]=="t";
this.element.setStyle(this.useLeft?{left:I[1]}:{right:I[1]});
this.element.setStyle(this.useTop?{top:H[1]}:{bottom:H[1]})
}},getId:function(){return this.element.id
},setDestroyOnClose:function(){this.options.destroyOnClose=true
},setConstraint:function(A,B){this.constraint=A;
this.constraintPad=Object.extend(this.constraintPad,B||{});
if(this.useTop&&this.useLeft){this.setLocation(parseFloat(this.element.style.top),parseFloat(this.element.style.left))
}},_initDrag:function(B){if(Event.element(B)==this.sizer&&this.isMinimized()){return 
}if(Event.element(B)!=this.sizer&&this.isMaximized()){return 
}if(Prototype.Browser.IE&&this.heightN==0){this._getWindowBorderSize()
}this.pointer=[this._round(Event.pointerX(B),this.options.gridX),this._round(Event.pointerY(B),this.options.gridY)];
if(this.options.wiredDrag){this.currentDrag=this._createWiredElement()
}else{this.currentDrag=this.element
}if(Event.element(B)==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 A=$(this.getId()+"_close");
if(A&&Position.within(A,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(B)
},_round:function(B,A){return A==1?B:B=Math.floor(B/A)*A
},_updateDrag:function(B){var A=[this._round(Event.pointerX(B),this.options.gridX),this._round(Event.pointerY(B),this.options.gridY)];
var J=A[0]-this.pointer[0];
var I=A[1]-this.pointer[1];
if(this.doResize){var H=this.widthOrg+J;
var D=this.heightOrg+I;
J=this.width-this.widthOrg;
I=this.height-this.heightOrg;
if(this.useLeft){H=this._updateWidthConstraint(H)
}else{this.currentDrag.setStyle({right:(this.rightOrg-J)+"px"})
}if(this.useTop){D=this._updateHeightConstraint(D)
}else{this.currentDrag.setStyle({bottom:(this.bottomOrg-I)+"px"})
}this.setSize(H,D);
this._notify("onResize")
}else{this.pointer=A;
if(this.useLeft){var C=parseFloat(this.currentDrag.getStyle("left"))+J;
var G=this._updateLeftConstraint(C);
this.pointer[0]+=G-C;
this.currentDrag.setStyle({left:G+"px"})
}else{this.currentDrag.setStyle({right:parseFloat(this.currentDrag.getStyle("right"))-J+"px"})
}if(this.useTop){var F=parseFloat(this.currentDrag.getStyle("top"))+I;
var E=this._updateTopConstraint(F);
this.pointer[1]+=E-F;
this.currentDrag.setStyle({top:E+"px"})
}else{this.currentDrag.setStyle({bottom:parseFloat(this.currentDrag.getStyle("bottom"))-I+"px"})
}this._notify("onMove")
}if(this.iefix){this._fixIEOverlapping();
this.iefix=null
}this._removeStoreLocation();
Event.stop(B)
},_endDrag:function(A){WindowUtilities.enableScreen("__invisible__");
if(this.doResize){this._notify("onEndResize")
}else{this._notify("onEndMove")
}Event.stopObserving(document,"mouseup",this.eventMouseUp,false);
Event.stopObserving(document,"mousemove",this.eventMouseMove,false);
Event.stop(A);
this._hideWiredElement();
this._saveCookie();
document.body.ondrag=null;
document.body.onselectstart=null
},_updateLeftConstraint:function(B){if(this.constraint&&this.useLeft&&this.useTop){var A=this.options.parent==document.body?WindowUtilities.getPageSize().windowWidth:this.options.parent.getDimensions().width;
if(B<this.constraintPad.left){B=this.constraintPad.left
}if(B+this.width+this.widthE+this.widthW>A-this.constraintPad.right){B=A-this.constraintPad.right-this.width-this.widthE-this.widthW
}}return B
},_updateTopConstraint:function(C){if(this.constraint&&this.useLeft&&this.useTop){var A=this.options.parent==document.body?WindowUtilities.getPageSize().windowHeight:this.options.parent.getDimensions().height;
var B=this.height+this.heightN+this.heightS;
if(C<this.constraintPad.top){C=this.constraintPad.top
}if(C+B>A-this.constraintPad.bottom){C=A-this.constraintPad.bottom-B
}}return C
},_updateWidthConstraint:function(A){if(this.constraint&&this.useLeft&&this.useTop){var B=this.options.parent==document.body?WindowUtilities.getPageSize().windowWidth:this.options.parent.getDimensions().width;
var C=parseFloat(this.element.getStyle("left"));
if(C+A+this.widthE+this.widthW>B-this.constraintPad.right){A=B-this.constraintPad.right-C-this.widthE-this.widthW
}}return A
},_updateHeightConstraint:function(B){if(this.constraint&&this.useLeft&&this.useTop){var A=this.options.parent==document.body?WindowUtilities.getPageSize().windowHeight:this.options.parent.getDimensions().height;
var C=parseFloat(this.element.getStyle("top"));
if(C+B+this.heightN+this.heightS>A-this.constraintPad.bottom){B=A-this.constraintPad.bottom-C-this.heightN-this.heightS
}}return B
},_createWindow:function(A){var F=this.options.className;
var D=document.createElement("div");
D.setAttribute("id",A);
D.className="dialog";
var E;
if(this.options.url){E='<iframe frameborder="0" name="'+A+'_content"  id="'+A+'_content" src="'+this.options.url+'"> </iframe>'
}else{E='<div id="'+A+'_content" class="'+F+'_content"> </div>'
}var G=this.options.closable?"<div class='"+F+"_close' id='"+A+"_close' onclick='Windows.close(\""+A+"\", event)'> </div>":"";
var H=this.options.minimizable?"<div class='"+F+"_minimize' id='"+A+"_minimize' onclick='Windows.minimize(\""+A+"\", event)'> </div>":"";
var I=this.options.maximizable?"<div class='"+F+"_maximize' id='"+A+"_maximize' onclick='Windows.maximize(\""+A+"\", event)'> </div>":"";
var C=this.options.resizable?"class='"+F+"_sizer' id='"+A+"_sizer'":"class='"+F+"_se'";
var B="../themes/default/blank.gif";
D.innerHTML=G+H+I+"      <table id='"+A+"_row1' class=\"top table_window\">        <tr>          <td class='"+F+"_nw'></td>          <td class='"+F+"_n'><div id='"+A+"_top' class='"+F+"_title title_window'>"+this.options.title+"</div></td>          <td class='"+F+"_ne'></td>        </tr>      </table>      <table id='"+A+"_row2' class=\"mid table_window\">        <tr>          <td class='"+F+"_w'></td>            <td id='"+A+"_table_content' class='"+F+"_content' valign='top'>"+E+"</td>          <td class='"+F+"_e'></td>        </tr>      </table>        <table id='"+A+"_row3' class=\"bot table_window\">        <tr>          <td class='"+F+"_sw'></td>            <td class='"+F+"_s'><div id='"+A+"_bottom' class='status_bar'><span style='float:left; width:1px; height:1px'></span></div></td>            <td "+C+"></td>        </tr>      </table>    ";
Element.hide(D);
this.options.parent.insertBefore(D,this.options.parent.firstChild);
Event.observe($(A+"_content"),"load",this.options.onload);
return D
},changeClassName:function(A){var B=this.options.className;
var C=this.getId();
$A(["_close","_minimize","_maximize","_sizer","_content"]).each(function(D){this._toggleClassName($(C+D),B+D,A+D)
}.bind(this));
this._toggleClassName($(C+"_top"),B+"_title",A+"_title");
$$("#"+C+" td").each(function(D){D.className=D.className.sub(B,A)
});
this.options.className=A
},_toggleClassName:function(C,B,A){if(C){C.removeClassName(B);
C.addClassName(A)
}},setLocation:function(C,B){C=this._updateTopConstraint(C);
B=this._updateLeftConstraint(B);
var A=this.currentDrag||this.element;
if(!A){return 
}A.setStyle({top:C+"px"});
A.setStyle({left:B+"px"});
this.useLeft=true;
this.useTop=true
},getLocation:function(){var A={};
if(this.useTop){A=Object.extend(A,{top:this.element.getStyle("top")})
}else{A=Object.extend(A,{bottom:this.element.getStyle("bottom")})
}if(this.useLeft){A=Object.extend(A,{left:this.element.getStyle("left")})
}else{A=Object.extend(A,{right:this.element.getStyle("right")})
}return A
},getSize:function(){return{width:this.width,height:this.height}
},setSize:function(C,B,A){C=parseFloat(C);
B=parseFloat(B);
if(!this.minimized&&C<this.options.minWidth){C=this.options.minWidth
}if(!this.minimized&&B<this.options.minHeight){B=this.options.minHeight
}if(this.options.maxHeight&&B>this.options.maxHeight){B=this.options.maxHeight
}if(this.options.maxWidth&&C>this.options.maxWidth){C=this.options.maxWidth
}if(this.useTop&&this.useLeft&&Window.hasEffectLib&&Effect.ResizeWindow&&A){new Effect.ResizeWindow(this,null,null,C,B,{duration:Window.resizeEffectDuration})
}else{this.width=C;
this.height=B;
var E=this.currentDrag?this.currentDrag:this.element;
E.setStyle({width:C+this.widthW+this.widthE+"px"});
E.setStyle({height:B+this.heightN+this.heightS+"px"});
if(!this.currentDrag||this.currentDrag==this.element){var D=$(this.element.id+"_content");
D.setStyle({height:B+"px"});
D.setStyle({width:C+"px"})
}}},updateHeight:function(){this.setSize(this.width,this.content.scrollHeight,true)
},updateWidth:function(){this.setSize(this.content.scrollWidth,this.height,true)
},toFront:function(){if(this.element.style.zIndex<Windows.maxZIndex){this.setZIndex(Windows.maxZIndex+1)
}if(this.iefix){this._fixIEOverlapping()
}},getBounds:function(B){if(!this.width||!this.height||!this.visible){this.computeBounds()
}var A=this.width;
var C=this.height;
if(!B){A+=this.widthW+this.widthE;
C+=this.heightN+this.heightS
}var D=Object.extend(this.getLocation(),{width:A+"px",height:C+"px"});
return D
},computeBounds:function(){if(!this.width||!this.height){var A=WindowUtilities._computeSize(this.content.innerHTML,this.content.id,this.width,this.height,0,this.options.className);
if(this.height){this.width=A+5
}else{this.height=A+5
}}this.setSize(this.width,this.height);
if(this.centered){this._center(this.centerTop,this.centerLeft)
}},show:function(B){this.visible=true;
if(B){if(typeof this.overlayOpacity=="undefined"){var A=this;
setTimeout(function(){A.show(B)
},10);
return 
}Windows.addModalWindow(this);
this.modal=true;
this.setZIndex(Windows.maxZIndex+1);
Windows.unsetOverflow(this)
}else{if(!this.element.style.zIndex){this.setZIndex(Windows.maxZIndex+1)
}}if(this.oldStyle){this.getContent().setStyle({overflow:this.oldStyle})
}this.computeBounds();
this._notify("onBeforeShow");
if(this.options.showEffect!=Element.show&&this.options.showEffectOptions){this.options.showEffect(this.element,this.options.showEffectOptions)
}else{this.options.showEffect(this.element)
}this._checkIEOverlapping();
WindowUtilities.focusedWindow=this;
this._notify("onShow")
},showCenter:function(A,C,B){this.centered=true;
this.centerTop=C;
this.centerLeft=B;
this.show(A)
},isVisible:function(){return this.visible
},_center:function(C,B){var D=WindowUtilities.getWindowScroll(this.options.parent);
var A=WindowUtilities.getPageSize(this.options.parent);
if(typeof C=="undefined"){C=(A.windowHeight-(this.height+this.heightN+this.heightS))/2
}C+=D.top;
if(typeof B=="undefined"){B=(A.windowWidth-(this.width+this.widthW+this.widthE))/2
}B+=D.left;
this.setLocation(C,B)
},_recenter:function(B){if(this.centered){var A=WindowUtilities.getPageSize(this.options.parent);
var C=WindowUtilities.getWindowScroll(this.options.parent);
if(this.pageSize&&this.pageSize.windowWidth==A.windowWidth&&this.pageSize.windowHeight==A.windowHeight&&this.windowScroll.left==C.left&&this.windowScroll.top==C.top){return 
}this.pageSize=A;
this.windowScroll=C;
if($("overlay_modal")){$("overlay_modal").setStyle({height:(A.pageHeight+"px")})
}if(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);
if(this.iefix){this.iefix.hide()
}if(!this.doNotNotifyHide){this._notify("onHide")
}},close:function(){if(this.visible){if(this.options.closeCallback&&!this.options.closeCallback(this)){return 
}if(this.options.destroyOnClose){var A=this.destroy.bind(this);
if(this.options.hideEffectOptions.afterFinish){var B=this.options.hideEffectOptions.afterFinish;
this.options.hideEffectOptions.afterFinish=function(){B();
A()
}
}else{this.options.hideEffectOptions.afterFinish=function(){A()
}
}}Windows.updateFocusedWindow();
this.doNotNotifyHide=true;
this.hide();
this.doNotNotifyHide=false;
this._notify("onClose")
}},minimize:function(){if(this.resizing){return 
}var A=$(this.getId()+"_row2");
if(!this.minimized){this.minimized=true;
var D=A.getDimensions().height;
this.r2Height=D;
var C=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:C+"px"});
A.hide()
}if(!this.useTop){var B=parseFloat(this.element.getStyle("bottom"));
this.element.setStyle({bottom:(B+D)+"px"})
}}else{this.minimized=false;
var 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{var C=this.element.getHeight()+D;
this.height+=D;
this.element.setStyle({height:C+"px"});
A.show()
}if(!this.useTop){var B=parseFloat(this.element.getStyle("bottom"));
this.element.setStyle({bottom:(B-D)+"px"})
}this.toFront()
}this._notify("onMinimize");
this._saveCookie()
},maximize:function(){if(this.isMinimized()||this.resizing){return 
}if(Prototype.Browser.IE&&this.heightN==0){this._getWindowBorderSize()
}if(this.storedLocation!=null){this._restoreLocation();
if(this.iefix){this.iefix.hide()
}}else{this._storeLocation();
Windows.unsetOverflow(this);
var G=WindowUtilities.getWindowScroll(this.options.parent);
var B=WindowUtilities.getPageSize(this.options.parent);
var F=G.left;
var E=G.top;
if(this.options.parent!=document.body){G={top:0,left:0,bottom:0,right:0};
var D=this.options.parent.getDimensions();
B.windowWidth=D.width;
B.windowHeight=D.height;
E=0;
F=0
}if(this.constraint){B.windowWidth-=Math.max(0,this.constraintPad.left)+Math.max(0,this.constraintPad.right);
B.windowHeight-=Math.max(0,this.constraintPad.top)+Math.max(0,this.constraintPad.bottom);
F+=Math.max(0,this.constraintPad.left);
E+=Math.max(0,this.constraintPad.top)
}var C=B.windowWidth-this.widthW-this.widthE;
var A=B.windowHeight-this.heightN-this.heightS;
if(this.useLeft&&this.useTop&&Window.hasEffectLib&&Effect.ResizeWindow){new Effect.ResizeWindow(this,E,F,C,A,{duration:Window.resizeEffectDuration})
}else{this.setSize(C,A);
this.element.setStyle(this.useLeft?{left:F}:{right:F});
this.element.setStyle(this.useTop?{top:E}:{bottom:E})
}this.toFront();
if(this.iefix){this._fixIEOverlapping()
}}this._notify("onMaximize");
this._saveCookie()
},isMinimized:function(){return this.minimized
},isMaximized:function(){return(this.storedLocation!=null)
},setOpacity:function(A){if(Element.setOpacity){Element.setOpacity(this.element,A)
}},setZIndex:function(A){this.element.setStyle({zIndex:A});
Windows.updateZindex(A,this)
},setTitle:function(A){if(!A||A==""){A="&nbsp;"
}Element.update(this.element.id+"_top",A)
},getTitle:function(){return $(this.element.id+"_top").innerHTML
},setStatusBar:function(B){var A=$(this.getId()+"_bottom");
if(typeof (B)=="object"){if(this.bottombar.firstChild){this.bottombar.replaceChild(B,this.bottombar.firstChild)
}else{this.bottombar.appendChild(B)
}}else{this.bottombar.innerHTML=B
}},_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")
}if(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(B){var C=this._createHiddenDiv(this.options.className+"_n");
this.heightN=Element.getDimensions(C).height;
C.parentNode.removeChild(C);
var C=this._createHiddenDiv(this.options.className+"_s");
this.heightS=Element.getDimensions(C).height;
C.parentNode.removeChild(C);
var C=this._createHiddenDiv(this.options.className+"_e");
this.widthE=Element.getDimensions(C).width;
C.parentNode.removeChild(C);
var C=this._createHiddenDiv(this.options.className+"_w");
this.widthW=Element.getDimensions(C).width;
C.parentNode.removeChild(C);
var C=document.createElement("div");
C.className="overlay_"+this.options.className;
document.body.appendChild(C);
var A=this;
setTimeout(function(){A.overlayOpacity=($(C).getStyle("opacity"));
C.parentNode.removeChild(C)
},10);
if(Prototype.Browser.IE){this.heightS=$(this.getId()+"_row3").getDimensions().height;
this.heightN=$(this.getId()+"_row1").getDimensions().height
}if(Prototype.Browser.WebKit&&Prototype.Browser.WebKitVersion<420){this.setSize(this.width,this.height)
}if(this.doMaximize){this.maximize()
}if(this.doMinimize){this.minimize()
}},_createHiddenDiv:function(B){var A=document.body;
var C=document.createElement("div");
C.setAttribute("id",this.element.id+"_tmp");
C.className=B;
C.style.display="none";
C.innerHTML="";
A.insertBefore(C,A.firstChild);
return C
},_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 A="";
if(this.useLeft){A+="l:"+(this.storedLocation?this.storedLocation.left:this.element.getStyle("left"))
}else{A+="r:"+(this.storedLocation?this.storedLocation.right:this.element.getStyle("right"))
}if(this.useTop){A+=",t:"+(this.storedLocation?this.storedLocation.top:this.element.getStyle("top"))
}else{A+=",b:"+(this.storedLocation?this.storedLocation.bottom:this.element.getStyle("bottom"))
}A+=","+(this.storedLocation?this.storedLocation.width:this.width);
A+=","+(this.storedLocation?this.storedLocation.height:this.height);
A+=","+this.isMinimized();
A+=","+this.isMaximized();
WindowUtilities.setCookie(A,this.cookie)
}},_createWiredElement:function(){if(!this.wiredElement){if(Prototype.Browser.IE){this._getWindowBorderSize()
}var B=document.createElement("div");
B.className="wired_frame "+this.options.className+"_wired_frame";
B.style.position="absolute";
this.options.parent.insertBefore(B,this.options.parent.firstChild);
this.wiredElement=$(B)
}if(this.useLeft){this.wiredElement.setStyle({left:this.element.getStyle("left")})
}else{this.wiredElement.setStyle({right:this.element.getStyle("right")})
}if(this.useTop){this.wiredElement.setStyle({top:this.element.getStyle("top")})
}else{this.wiredElement.setStyle({bottom:this.element.getStyle("bottom")})
}var A=this.element.getDimensions();
this.wiredElement.setStyle({width:A.width+"px",height:A.height+"px"});
this.wiredElement.setStyle({zIndex:Windows.maxZIndex+30});
return this.wiredElement
},_hideWiredElement:function(){if(!this.wiredElement||!this.currentDrag){return 
}if(this.currentDrag==this.element){this.currentDrag=null
}else{if(this.useLeft){this.element.setStyle({left:this.currentDrag.getStyle("left")})
}else{this.element.setStyle({right:this.currentDrag.getStyle("right")})
}if(this.useTop){this.element.setStyle({top:this.currentDrag.getStyle("top")})
}else{this.element.setStyle({bottom:this.currentDrag.getStyle("bottom")})
}this.currentDrag.hide();
this.currentDrag=null;
if(this.doResize){this.setSize(this.width,this.height)
}}},_notify:function(A){if(this.options[A]){this.options[A](this)
}else{Windows.notify(A,this)
}}};
var Windows={windows:[],modalWindows:[],observers:[],focusedWindow:null,maxZIndex:200000,overlayShowEffectOptions:{duration:0.5},overlayHideEffectOptions:{duration:0.5},addObserver:function(A){this.removeObserver(A);
this.observers.push(A)
},removeObserver:function(A){this.observers=this.observers.reject(function(B){return B==A
})
},notify:function(A,B){this.observers.each(function(C){if(C[A]){C[A](A,B)
}})
},getWindow:function(A){return this.windows.detect(function(B){return B.getId()==A
})
},getFocusedWindow:function(){return this.focusedWindow
},updateFocusedWindow:function(){this.focusedWindow=this.windows.length>=2?this.windows[this.windows.length-2]:null
},register:function(A){this.windows.push(A)
},addModalWindow:function(A){if(this.modalWindows.length==0){WindowUtilities.disableScreen(A.options.className,"overlay_modal",A.overlayOpacity,A.getId(),A.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(A.getId())
}this.modalWindows.push(A)
},removeModalWindow:function(A){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(A){this.windows.push(A)
},unregister:function(A){this.windows=this.windows.reject(function(B){return B==A
})
},closeAll:function(){this.windows.each(function(A){Windows.close(A.getId())
})
},closeAllModalWindows:function(){WindowUtilities.enableScreen();
this.modalWindows.each(function(A){if(A){A.close()
}})
},minimize:function(C,A){var B=this.getWindow(C);
if(B&&B.visible){B.minimize()
}Event.stop(A)
},maximize:function(C,A){var B=this.getWindow(C);
if(B&&B.visible){B.maximize()
}Event.stop(A)
},close:function(C,A){var B=this.getWindow(C);
if(B){B.close()
}if(A){Event.stop(A)
}},blur:function(B){var A=this.getWindow(B);
if(!A){return 
}if(A.options.blurClassName){A.changeClassName(A.options.blurClassName)
}if(this.focusedWindow==A){this.focusedWindow=null
}A._notify("onBlur")
},focus:function(B){var A=this.getWindow(B);
if(!A){return 
}if(this.focusedWindow){this.blur(this.focusedWindow.getId())
}if(A.options.focusClassName){A.changeClassName(A.options.focusClassName)
}this.focusedWindow=A;
A._notify("onFocus")
},unsetOverflow:function(A){this.windows.each(function(B){B.oldOverflow=B.getContent().getStyle("overflow")||"auto";
B.getContent().setStyle({overflow:"hidden"})
});
if(A&&A.oldOverflow){A.getContent().setStyle({overflow:A.oldOverflow})
}},resetOverflow:function(){this.windows.each(function(A){if(A.oldOverflow){A.getContent().setStyle({overflow:A.oldOverflow})
}})
},updateZindex:function(A,B){if(A>this.maxZIndex){this.maxZIndex=A;
if(this.focusedWindow){this.blur(this.focusedWindow.getId())
}}this.focusedWindow=B;
if(this.focusedWindow){this.focus(this.focusedWindow.getId())
}}};
var Dialog={dialogId:null,onCompleteFunc:null,callFunc:null,parameters:null,confirm:function(D,C){if(D&&typeof D!="string"){Dialog._runAjaxRequest(D,C,Dialog.confirm);
return 
}D=D||"";
C=C||{};
var F=C.okLabel?C.okLabel:"Ok";
var A=C.cancelLabel?C.cancelLabel:"Cancel";
C=Object.extend(C,C.windowParameters||{});
C.windowParameters=C.windowParameters||{};
C.className=C.className||"alert";
var B="class ='"+(C.buttonClass?C.buttonClass+" ":"")+" ok_button'";
var E="class ='"+(C.buttonClass?C.buttonClass+" ":"")+" cancel_button'";
var D="      <div class='"+C.className+"_message'>"+D+"</div>        <div class='"+C.className+"_buttons'>          <input type='button' value='"+F+"' onclick='Dialog.okCallback()' "+B+"/>          <input type='button' value='"+A+"' onclick='Dialog.cancelCallback()' "+E+"/>        </div>    ";
return this._openDialog(D,C)
},alert:function(C,B){if(C&&typeof C!="string"){Dialog._runAjaxRequest(C,B,Dialog.alert);
return 
}C=C||"";
B=B||{};
var D=B.okLabel?B.okLabel:"Ok";
B=Object.extend(B,B.windowParameters||{});
B.windowParameters=B.windowParameters||{};
B.className=B.className||"alert";
var A="class ='"+(B.buttonClass?B.buttonClass+" ":"")+" ok_button'";
var C="      <div class='"+B.className+"_message'>"+C+"</div>        <div class='"+B.className+"_buttons'>          <input type='button' value='"+D+"' onclick='Dialog.okCallback()' "+A+"/>        </div>";
return this._openDialog(C,B)
},info:function(B,A){if(B&&typeof B!="string"){Dialog._runAjaxRequest(B,A,Dialog.info);
return 
}B=B||"";
A=A||{};
A=Object.extend(A,A.windowParameters||{});
A.windowParameters=A.windowParameters||{};
A.className=A.className||"alert";
var B="<div id='modal_dialog_message' class='"+A.className+"_message'>"+B+"</div>";
if(A.showProgress){B+="<div id='modal_dialog_progress' class='"+A.className+"_progress'>  </div>"
}A.ok=null;
A.cancel=null;
return this._openDialog(B,A)
},setInfoMessage:function(A){$("modal_dialog_message").update(A)
},closeInfo:function(){Windows.close(this.dialogId)
},_openDialog:function(E,D){var C=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{var B=new Date();
this.dialogId="modal_dialog_"+B.getTime();
D.id=this.dialogId
}if(!D.height||!D.width){var A=WindowUtilities._computeSize(E,this.dialogId,D.width,D.height,5,C);
if(D.height){D.width=A+5
}else{D.height=A+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;
var F=new Window(D);
F.getContent().innerHTML=E;
F.showCenter(true,D.top,D.left);
F.setDestroyOnClose();
F.cancelCallback=D.onCancel||D.cancel;
F.okCallback=D.onOk||D.ok;
return F
},_getAjaxContent:function(A){Dialog.callFunc(A.responseText,Dialog.parameters)
},_runAjaxRequest:function(C,B,A){if(C.options==null){C.options={}
}Dialog.onCompleteFunc=C.options.onComplete;
Dialog.parameters=B;
Dialog.callFunc=A;
C.options.onComplete=Dialog._getAjaxContent;
new Ajax.Request(C.url,C.options)
},okCallback:function(){var A=Windows.focusedWindow;
if(!A.okCallback||A.okCallback(A)){$$("#"+A.getId()+" input").each(function(B){B.onclick=null
});
A.close()
}},cancelCallback:function(){var A=Windows.focusedWindow;
$$("#"+A.getId()+" input").each(function(B){B.onclick=null
});
A.close();
if(A.cancelCallback){A.cancelCallback(A)
}}};
if(Prototype.Browser.WebKit){var array=navigator.userAgent.match(new RegExp(/AppleWebKit\/([\d\.\+]*)/));
Prototype.Browser.WebKitVersion=parseFloat(array[1])
}var WindowUtilities={getWindowScroll:function(parent){var T,L,W,H;
parent=parent||document.body;
if(parent!=document.body){T=parent.scrollTop;
L=parent.scrollLeft;
W=parent.scrollWidth;
H=parent.scrollHeight
}else{var w=window;
with(w.document){if(w.document.documentElement&&documentElement.scrollTop){T=documentElement.scrollTop;
L=documentElement.scrollLeft
}else{if(w.document.body){T=body.scrollTop;
L=body.scrollLeft
}}if(w.innerWidth){W=w.innerWidth;
H=w.innerHeight
}else{if(w.document.documentElement&&documentElement.clientWidth){W=documentElement.clientWidth;
H=documentElement.clientHeight
}else{W=body.offsetWidth;
H=body.offsetHeight
}}}}return{top:T,left:L,width:W,height:H}
},getPageSize:function(D){D=D||document.body;
var C,G;
var E,B;
if(D!=document.body){C=D.getWidth();
G=D.getHeight();
B=D.scrollWidth;
E=D.scrollHeight
}else{var F,A;
if(window.innerHeight&&window.scrollMaxY){F=document.body.scrollWidth;
A=window.innerHeight+window.scrollMaxY
}else{if(document.body.scrollHeight>document.body.offsetHeight){F=document.body.scrollWidth;
A=document.body.scrollHeight
}else{F=document.body.offsetWidth;
A=document.body.offsetHeight
}}if(self.innerHeight){C=self.innerWidth;
G=self.innerHeight
}else{if(document.documentElement&&document.documentElement.clientHeight){C=document.documentElement.clientWidth;
G=document.documentElement.clientHeight
}else{if(document.body){C=document.body.clientWidth;
G=document.body.clientHeight
}}}if(A<G){E=G
}else{E=A
}if(F<C){B=C
}else{B=F
}}return{pageWidth:B,pageHeight:E,windowWidth:C,windowHeight:G}
},disableScreen:function(C,A,D,E,B){WindowUtilities.initLightbox(A,C,function(){this._disableScreen(C,A,D,E)
}.bind(this),B||document.body)
},_disableScreen:function(C,B,E,F){var D=$(B);
var A=WindowUtilities.getPageSize(D.parentNode);
if(F&&Prototype.Browser.IE){WindowUtilities._hideSelect();
WindowUtilities._showSelect(F)
}D.style.height=(A.pageHeight+"px");
D.style.display="none";
if(B=="overlay_modal"&&Window.hasEffectLib&&Windows.overlayShowEffectOptions){D.overlayOpacity=E;
new Effect.Appear(D,Object.extend({from:0,to:E},Windows.overlayShowEffectOptions))
}else{D.style.display="block"
}},enableScreen:function(B){B=B||"overlay_modal";
var A=$(B);
if(A){if(B=="overlay_modal"&&Window.hasEffectLib&&Windows.overlayHideEffectOptions){new Effect.Fade(A,Object.extend({from:A.overlayOpacity,to:0},Windows.overlayHideEffectOptions))
}else{A.style.display="none";
A.parentNode.removeChild(A)
}if(B!="__invisible__"){WindowUtilities._showSelect()
}}},_hideSelect:function(A){if(Prototype.Browser.IE){A=A==null?"":"#"+A+" ";
$$(A+"select").each(function(B){if(!WindowUtilities.isDefined(B.oldVisibility)){B.oldVisibility=B.style.visibility?B.style.visibility:"visible";
B.style.visibility="hidden"
}})
}},_showSelect:function(A){if(Prototype.Browser.IE){A=A==null?"":"#"+A+" ";
$$(A+"select").each(function(B){if(WindowUtilities.isDefined(B.oldVisibility)){try{B.style.visibility=B.oldVisibility
}catch(C){B.style.visibility="visible"
}B.oldVisibility=null
}else{if(B.style.visibility){B.style.visibility="visible"
}}})
}},isDefined:function(A){return typeof (A)!="undefined"&&A!=null
},initLightbox:function(E,C,A,B){if($(E)){Element.setStyle(E,{zIndex:Windows.maxZIndex+1});
Windows.maxZIndex++;
A()
}else{var D=document.createElement("div");
D.setAttribute("id",E);
D.className="overlay_"+C;
D.style.display="none";
D.style.position="absolute";
D.style.top="0";
D.style.left="0";
D.style.zIndex=Windows.maxZIndex+1;
Windows.maxZIndex++;
D.style.width="100%";
B.insertBefore(D,B.firstChild);
if(Prototype.Browser.WebKit&&E=="overlay_modal"){setTimeout(function(){A()
},10)
}else{A()
}}},setCookie:function(B,A){document.cookie=A[0]+"="+escape(B)+((A[1])?"; expires="+A[1].toGMTString():"")+((A[2])?"; path="+A[2]:"")+((A[3])?"; domain="+A[3]:"")+((A[4])?"; secure":"")
},getCookie:function(C){var B=document.cookie;
var E=C+"=";
var D=B.indexOf("; "+E);
if(D==-1){D=B.indexOf(E);
if(D!=0){return null
}}else{D+=2
}var A=document.cookie.indexOf(";",D);
if(A==-1){A=B.length
}return unescape(B.substring(D+E.length,A))
},_computeSize:function(E,A,B,G,D,F){var I=document.body;
var C=document.createElement("div");
C.setAttribute("id",A);
C.className=F+"_content";
if(G){C.style.height=G+"px"
}else{C.style.width=B+"px"
}C.style.position="absolute";
C.style.top="0";
C.style.left="0";
C.style.display="none";
C.innerHTML=E;
I.insertBefore(C,I.firstChild);
var H;
if(G){H=$(C).getDimensions().width+D
}else{H=$(C).getDimensions().height+D
}I.removeChild(C);
return H
}};