Thoughtmuse.Authorization={validateGoldAccount:function(restrictedFunc){Thoughtmuse.Net.getSubscriptionType(function(response){var subscription=response.responseText;if(!(subscription==="gold"||subscription==="platinum")){alert("Illegal op, must be gold or platinum");return;}
restrictedFunc();});},validateToPlatinumAccount:function(restrictedFunc){Thoughtmuse.Net.getSubscriptionType(function(response){var subscription=response.responseText;if(!(subscription==="platinum")){alert("Illegal op, must be platinum");return;}
restrictedFunc();});},doWithSubscriptionType:function(subscriptionReceivingFunc){alert("before");Thoughtmuse.Net.getSubscriptionType(function(response){alert("after");var subscription=response.responseText;subscriptionReceivingFunc(subscription);});},validateUserCanSaveMoreMaps:function(restrictedFunc){Thoughtmuse.Net.canUserSaveMoreMaps(function(response){var result=response.responseText;if(!(result==="OK")){alert("Result");}
restrictedFunc();});}};Thoughtmuse.File={newFile:function(completionCallback){var api=Thoughtmuse.GraphAPI.Operations;Thoughtmuse.Graphics.showActivityIndicator("Loading templates, please wait...");var callAfterLoad=completionCallback;Thoughtmuse.Net.getTemplateSelectPage(function(templateSelectPage){Thoughtmuse.Graphics.hideActivityIndicator();Thoughtmuse.Widgets.showPanel("Select mindmap template","",templateSelectPage.responseText);});},loadFile:function(completionCallback){var api=Thoughtmuse.GraphAPI.Operations;Thoughtmuse.Graphics.showActivityIndicator("Loading mindmap list, please wait...");var doAfterLoad=completionCallback;api.listGraphsOnServer(function(jsonObjNameListArray){Thoughtmuse.Graphics.hideActivityIndicator();var fileList=jsonObjNameListArray.mapNames;if(fileList.length===0){Thoughtmuse.Widgets.showPanel("","","You haven't saved any files yet, nothing to load.");}
else{Thoughtmuse.Net.getFileOpenPage(function(fileOpenPage){Thoughtmuse.Widgets.showPanel("Select a mindmap","",fileOpenPage.responseText);});}});},renameFile:function(completionCallback){var api=Thoughtmuse.GraphAPI.Operations;var doAfterRename=completionCallback;api.setEditMode();var fileToRename=Thoughtmuse.GraphAPI.State.currentGraphName;var fileNameInputHtml="<input id='"+this.inputFieldId+"'></input>";var onRenameClick=function(){Thoughtmuse.GraphAPI.Operations.endEditMode();var newFileName=Thoughtmuse.File.getCurrentFileNameInput();Thoughtmuse.GraphAPI.State.setGraphName(newFileName);api.renameOnServer(fileToRename,newFileName);doAfterRename();};Thoughtmuse.Widgets.showSimpleDialog("Rename file as: ",fileNameInputHtml,"Rename","Cancel",function(){onRenameClick();},function(){Thoughtmuse.GraphAPI.Operations.endEditMode();});Thoughtmuse.Graphics.domLookup(this.inputFieldId).focus();},deleteMindmap:function(){var api=Thoughtmuse.GraphAPI.Operations;api.setEditMode();var onDeleteClick=function(){Thoughtmuse.GraphAPI.Operations.endEditMode();var fileToDelete=Thoughtmuse.GraphAPI.State.currentGraphName;api.deleteFromServer(fileToDelete);Thoughtmuse.Graphics.workspaceEffectFadeOutHide();api.clearCurrentGraph();Thoughtmuse.Graphics.clearWorkspace();};Thoughtmuse.Widgets.showSimpleDialog("Delete?","Are you sure you wish to delete this mindmap?","Delete","Cancel",function(){onDeleteClick();},function(){Thoughtmuse.GraphAPI.Operations.endEditMode();});},inputFieldId:"fileNameInput",getCurrentFileNameInput:function(){return Thoughtmuse.Graphics.domLookup(this.inputFieldId).val();},saveFileAs:function(completionCallback){var api=Thoughtmuse.GraphAPI.Operations;Thoughtmuse.GraphAPI.Operations.setEditMode();var fileNameInputHtml="<input id='"+this.inputFieldId+"'></input>";var onSaveClick=function(){Thoughtmuse.GraphAPI.Operations.endEditMode();var fileName=Thoughtmuse.File.getCurrentFileNameInput();Thoughtmuse.GraphAPI.State.setGraphName(fileName);api.saveOnServer(fileName);completionCallback();};Thoughtmuse.Widgets.showSimpleDialog("Save file as: ",fileNameInputHtml,"Save","Cancel",function(){onSaveClick();},function(){Thoughtmuse.GraphAPI.Operations.endEditMode();});Thoughtmuse.Graphics.domLookup(this.inputFieldId).focus();},saveFile:function(completionCallback){var currGraphName=Thoughtmuse.GraphAPI.State.getGraphName();if(!currGraphName){Thoughtmuse.Operations.saveFileAs(completionCallback);}
else{var api=Thoughtmuse.GraphAPI.Operations;api.saveOnServer(currGraphName);completionCallback();}},publishMindmap:function(){var api=Thoughtmuse.GraphAPI.Operations;var fileNameInputHtml="<input id='fileNameInput'></input>";Thoughtmuse.GraphAPI.Operations.setEditMode();var onPublishClick=function(){Thoughtmuse.GraphAPI.Operations.endEditMode();api.publishCurrentMindmap(function(response){Thoughtmuse.Widgets.showPanel("","",response.responseText,"750px");});};Thoughtmuse.Widgets.showSimpleDialog("Publish mindmap?","Do you wish to make this mindmap publicly available for viewing?","Ok","Cancel",function(){onPublishClick();},function(){Thoughtmuse.GraphAPI.Operations.endEditMode();});},toggleFileOpenOrTutorialIfNoFilesSaved:function(){var api=Thoughtmuse.GraphAPI.Operations;Thoughtmuse.Graphics.showActivityIndicator("Loading, please wait...");api.listGraphsOnServer(function(jsonObjNameListArray){Thoughtmuse.Graphics.hideActivityIndicator();var fileList=jsonObjNameListArray.mapNames;var noOfFilesSaved=fileList.length;if(noOfFilesSaved>0){Thoughtmuse.Operations.loadFile();}
else{Thoughtmuse.Operations.newFile();}});}};Thoughtmuse.GraphAPI={};Thoughtmuse.GraphAPI.GraphTemplate={name:null,rootNode:null,selectedNodes:null,magnification:null};Thoughtmuse.GraphAPI.NodeTemplate={id:null,text:null,editMode:false,offset:null,size:null,bold:false,italic:false,underlined:false,fontColor:null,nodeColor:null,folded:null,children:null,parent:null};Thoughtmuse.GraphAPI.State={currentActiveGraph:null,oldGraphStates:[],currentGraphName:null,storeCurrentGraphState:function(){var copy=Thoughtmuse.GraphAPI.Operations.copyGraph(this.currentActiveGraph);copy.selectedNodes=[];this.oldGraphStates.push(copy);if(this.oldGraphStates.length>30){this.oldGraphStates.shift();}},undoLastChange:function(){if(this.oldGraphStates.length>0){this.currentActiveGraph=this.oldGraphStates.pop();}
return this.currentActiveGraph;},setGraphName:function(name){this.currentGraphName=name;},getGraphName:function(){return this.currentGraphName;},clipBoard:[]};Thoughtmuse.GraphAPI.Operations={createNewGraph:function(name,xPos,yPos){var newGraph=Object.create(Thoughtmuse.GraphAPI.GraphTemplate);newGraph.name=name;newGraph.selectedNodes=[];newGraph.rootNode=this.createNewNode();newGraph.rootNode.text="New mindmap";newGraph.magnification=100;Thoughtmuse.GraphAPI.State.currentActiveGraph=newGraph;Thoughtmuse.GraphAPI.State.setGraphName(null);return newGraph;},createNewNode:function(){var newNode=Object.create(Thoughtmuse.GraphAPI.NodeTemplate);newNode.text="";newNode.id=Thoughtmuse.Util.getUniqueId();newNode.children=[];newNode.offset=[0,0];newNode.size=100;newNode.fontColor="#000000";newNode.nodeColor="#FFFFFF";newNode.folded=false;return newNode;},newChild:function(parentNode){var newChild=Thoughtmuse.GraphAPI.Operations.createNewNode();var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var parent=null;if(parentNode){parent=parentNode;}
else if(graph.selectedNodes.length>0){parent=graph.selectedNodes[graph.selectedNodes.length-1];}
else{parent=graph.rootNode;}
parent.children.push(newChild);newChild.parent=parent;this.unFoldNode(parent);this.clearNodeSelection();this.addNodeToSelection(newChild);return newChild.id;},newSibling:function(olderSiblingNode){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;if(olderSiblingNode){this.newChild(olderSiblingNode.parent);}
else if(graph.selectedNodes.length>0){var olderSibling=graph.selectedNodes[graph.selectedNodes.length-1];var newNodeId=this.newChild(olderSibling.parent);var siblingNodeIdAfterMove=this.makeNodeYoungerSiblingOfNode(newNodeId,olderSibling.id);this.clearNodeSelection();this.addNodeToSelection(this.findNode(siblingNodeIdAfterMove));}},deleteNode:function(unwantedNode){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var parent=unwantedNode.parent;if(!Thoughtmuse.GraphAPI.Operations.isNodeRoot(unwantedNode)){var indexToDeleteInChildren=jQuery.inArray(unwantedNode,parent.children);var indexToDeleteInSelected=jQuery.inArray(graph.selectedNodes,parent.children);if(indexToDeleteInChildren!==-1){parent.children.splice(indexToDeleteInChildren,1);}
if(indexToDeleteInSelected!==-1){graph.selectedNodes.splice(indexToDeleteInSelected,1);}}},eachUnfoldedGraphNode:function(nodeStartHandler,nodeEndHandler){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;this.eachNode(true,graph.rootNode,nodeStartHandler,nodeEndHandler,0);},eachGraphNode:function(nodeStartHandler,nodeEndHandler){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;this.eachNode(false,graph.rootNode,nodeStartHandler,nodeEndHandler,0);},eachNode:function(onlyDoUnfoldedOnes,node,nodeStartHandler,nodeEndHandler,nodeDebth){if(node.children===null){return;}
if(nodeStartHandler){nodeStartHandler(node,nodeDebth);}
for(var i=0;i<node.children.length;i++)
{var processChildren=true;if(onlyDoUnfoldedOnes&&node.folded){processChildren=false;}
if(processChildren){this.eachNode(onlyDoUnfoldedOnes,node.children[i],nodeStartHandler,nodeEndHandler,nodeDebth+1);}}
if(nodeEndHandler){nodeEndHandler(node,nodeDebth);}},eachSelectedNode:function(callback){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;jQuery.each(graph.selectedNodes,function(i,selectedNode){callback(selectedNode);});},findNode:function(id){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var resultNode=null;this.eachGraphNode(function(node){if(node.id===id){resultNode=node;}});return resultNode;},isNodeRoot:function(node){if(node.parent===null){return true;}
else{return false;}},isNodeDescendantOfNode:function(possibleDescendantNodeId,parentNodeId){var parentNode=this.findNode(parentNodeId);var isInBranch=false;this.eachNode(false,parentNode,function(node){if(node.id===possibleDescendantNodeId){isInBranch=true;}});return isInBranch;},copyGraph:function(graph){var copiedGraph=Object.create(graph);copiedGraph.rootNode=this.copyEachNode(graph.rootNode);copiedGraph.name=graph.name;copiedGraph.selectedNodes=[];return copiedGraph;},copyEachNode:function(node){var copiedNode=Object.create(node);copiedNode.bold=node.bold;copiedNode.italic=node.italic;copiedNode.underlined=node.underlined;copiedNode.text=node.text;copiedNode.id=Thoughtmuse.Util.getUniqueId();copiedNode.offset=Object.create(node.offset);copiedNode.size=node.size;copiedNode.fontColor=node.fontColor;copiedNode.nodeColor=node.nodeColor;copiedNode.folded=node.folded;copiedNode.children=[];for(var i=0;i<node.children.length;i++)
{copiedNode.children.push(this.copyEachNode(node.children[i]));copiedNode.children[i].parent=copiedNode;}
return copiedNode;},unFoldNode:function(node){node.folded=false;},foldNode:function(node){if(node.children.length>0){node.folded=true;}},invertNodeFold:function(node){if(node.folded===true){this.unFoldNode(node);}
else{this.foldNode(node);}},getSelectedNodes:function(){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;return graph.selectedNodes;},addNodeToSelection:function(node){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;if(!this.isNodeSelected(node)){graph.selectedNodes.push(node);}},removeNodeFromSelection:function(unwantedNode){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var indexToDelete=jQuery.inArray(unwantedNode,graph.selectedNodes);if(indexToDelete!==-1){graph.selectedNodes.splice(indexToDelete,1);}},clearNodeSelection:function(){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;graph.selectedNodes=[];},isNodeSelected:function(node){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var indexInSelected=jQuery.inArray(node,graph.selectedNodes);return(indexInSelected!==-1);},copySelection:function(){Thoughtmuse.GraphAPI.State.clipBoard=[];var alreadyAdded=[];var isAlreadyAdded=function(node){var indexFound=jQuery.inArray(node.id,alreadyAdded);return(indexFound!==-1);};jQuery.each(this.getSelectedNodes(),function(i,nodeToCopyToClipBoard){if(!isAlreadyAdded(nodeToCopyToClipBoard)){var arr=alreadyAdded;Thoughtmuse.GraphAPI.Operations.eachNode(false,nodeToCopyToClipBoard,function(node){arr.push(node.id);});var copiedNode=Thoughtmuse.GraphAPI.Operations.copyEachNode(nodeToCopyToClipBoard);Thoughtmuse.GraphAPI.State.clipBoard.push(copiedNode);}});},cutSelection:function(){this.copySelection();this.deleteSelectedNodesFromGraph();},makeNodeChildOfNode:function(childNodeId,parentNodeId){var movedNode=this.findNode(childNodeId);var newParent=this.findNode(parentNodeId);var movedNodeCopy=this.copyEachNode(movedNode);Thoughtmuse.GraphAPI.Operations.deleteNode(movedNode);movedNodeCopy.parent=newParent;newParent.children.push(movedNodeCopy);Thoughtmuse.GraphAPI.Operations.deleteNode(movedNode);},makeNodeOlderSiblingOfNode:function(movedNodeId,targetNodeId){var movedNode=this.findNode(movedNodeId);var youngerSiblingNode=this.findNode(targetNodeId);var commonParent=this.findNode(targetNodeId).parent;var movedNodeCopy=this.copyEachNode(movedNode);movedNodeCopy.parent=commonParent;Thoughtmuse.GraphAPI.Operations.deleteNode(movedNode);var indexOfYoungerSibling=jQuery.inArray(youngerSiblingNode,commonParent.children);var siblings=commonParent.children;var tmpArr=[];var i;for(i=0;i<indexOfYoungerSibling;i++){tmpArr[i]=siblings[i];}
tmpArr[indexOfYoungerSibling]=movedNodeCopy;for(i=indexOfYoungerSibling;i<siblings.length;i++){tmpArr[i+1]=siblings[i];}
commonParent.children=tmpArr;},makeNodeYoungerSiblingOfNode:function(movedNodeId,targetNodeId){var movedNode=this.findNode(movedNodeId);var olderSiblingNode=this.findNode(targetNodeId);var commonParent=this.findNode(targetNodeId).parent;var movedNodeCopy=this.copyEachNode(movedNode);movedNodeCopy.parent=commonParent;Thoughtmuse.GraphAPI.Operations.deleteNode(movedNode);var indexOfOlderSibling=jQuery.inArray(olderSiblingNode,commonParent.children);var siblings=commonParent.children;var tmpArr=[];var i;for(i=0;i<=indexOfOlderSibling;i++){tmpArr[i]=siblings[i];}
tmpArr[indexOfOlderSibling+1]=movedNodeCopy;for(i=indexOfOlderSibling+1;i<siblings.length;i++){tmpArr[i+1]=siblings[i];}
commonParent.children=tmpArr;return movedNodeCopy.id;},makeSelectionChildOfNode:function(parentNodeId){var targetNode=this.findNode(parentNodeId);this.cutSelection();this.addNodeToSelection(targetNode);this.pasteClipboardIntoSelection();},makeSelectionOlderSiblingsOfNode:function(targetNodeId){var selection=this.getSelectedNodes();for(var x=0;x<selection.length;x++){this.makeNodeOlderSiblingOfNode(selection[x].id,targetNodeId);}
this.deleteSelectedNodesFromGraph();},makeSelectionYoungerSiblingsOfNode:function(targetNodeId){var selection=this.getSelectedNodes();for(var x=0;x<selection.length;x++){this.makeNodeYoungerSiblingOfNode(selection[x].id,targetNodeId);}
this.deleteSelectedNodesFromGraph();},pasteClipboardIntoSelection:function(){if(!this.getSelectedNodes()||this.getSelectedNodes().length===0){return;}
var pasteTargetNode=this.getSelectedNodes()[0];jQuery.each(Thoughtmuse.GraphAPI.State.clipBoard,function(i,nodeToPasteIntoSelection){var copiedNode=Thoughtmuse.GraphAPI.Operations.copyEachNode(nodeToPasteIntoSelection);copiedNode.parent=pasteTargetNode;pasteTargetNode.children.push(copiedNode);});},magnifyByGraphZoomPercentage:function(sizeVar){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;return((sizeVar*graph.magnification)/100);},clearCurrentGraph:function(){Thoughtmuse.GraphAPI.State.currentActiveGraph=null;Thoughtmuse.GraphAPI.State.currentGraphName=null;},isAnyGraphLoaded:function(){return(Thoughtmuse.GraphAPI.State.currentActiveGraph!==null);},adjustGraphZoom:function(deltaPercent){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var currentMagnification=graph.magnification;if((currentMagnification+deltaPercent)<10||(currentMagnification+deltaPercent)>500){return;}
graph.magnification=currentMagnification+deltaPercent;},adjustGraphLocation:function(deltaX,deltaY){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;if(graph){graph.rootNode.offset[0]+=deltaX;graph.rootNode.offset[1]+=deltaY;}},adjustNodeSize:function(node,deltaPercent){var currentSize=node.size;if((currentSize+deltaPercent)<10||(currentSize+deltaPercent)>500){return;}
node.size+=deltaPercent;},deleteSelectedNodesFromGraph:function(){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;jQuery.each(graph.selectedNodes,function(i,nodeToDelete){if(nodeToDelete.parent){Thoughtmuse.GraphAPI.Operations.deleteNode(nodeToDelete);}});graph.selectedNodes=[];},listGraphsOnServer:function(jsonObjHandlerFunc){Thoughtmuse.Net.getMapList(function(response){var resultObject=Thoughtmuse.Net.parseJSONMapData(response.responseText);jsonObjHandlerFunc(resultObject);});},listTemplatesOnServer:function(jsonObjHandlerFunc){Thoughtmuse.Net.getTemplateList(function(response){var resultObject=Thoughtmuse.Net.parseJSONMapData(response.responseText);jsonObjHandlerFunc(resultObject);});},loadFromServer:function(graphName,jsonObjHandlerFunc){Thoughtmuse.Net.getMap(graphName,function(response){var resultObject=Thoughtmuse.Net.parseJSONMapData(response.responseText);var graph=Thoughtmuse.GraphAPI.Operations.initLoadedGraph(resultObject,graphName);jsonObjHandlerFunc(graph);});},loadPublishedFromServer:function(graphName,owner,jsonObjHandlerFunc){Thoughtmuse.Net.getPublishedMap(graphName,owner,function(response){var resultObject=Thoughtmuse.Net.parseJSONMapData(response.responseText);var graph=Thoughtmuse.GraphAPI.Operations.initLoadedGraph(resultObject,graphName);jsonObjHandlerFunc(graph);});},loadTemplateFromServer:function(graphName,jsonObjHandlerFunc){Thoughtmuse.Net.getTemplate(graphName,function(response){var resultObject=Thoughtmuse.Net.parseJSONMapData(response.responseText);var graph=Thoughtmuse.GraphAPI.Operations.initLoadedGraph(resultObject,null);jsonObjHandlerFunc(graph);});},initLoadedGraph:function(loadedGraph,graphName){Thoughtmuse.GraphAPI.State.currentActiveGraph=loadedGraph;var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;Thoughtmuse.GraphAPI.State.setGraphName(graphName);Thoughtmuse.GraphAPI.State.oldGraphStates=[];graph.magnification=80;graph.rootNode.parent=null;graph.rootNode.editMode=false;graph.rootNode.offset=[0,0];Thoughtmuse.GraphAPI.Operations.eachGraphNode(function(node){var parent=node;jQuery.each(node.children,function(i,child){child.parent=parent;});});Thoughtmuse.GraphAPI.Operations.eachGraphNode(function(node){node.editMode=false;node.offset=[0,0];node.id=Thoughtmuse.Util.getUniqueId();});graph.selectedNodes=[graph.rootNode];return graph;},saveOnServer:function(graphName){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;Thoughtmuse.Net.saveOrUpdateMap(graphName,graph);},renameOnServer:function(oldName,newName){Thoughtmuse.Net.renameMap(oldName,newName);},deleteFromServer:function(graphName){Thoughtmuse.Net.deleteMap(graphName);},publishCurrentMindmap:function(completionCallback){var graphName=Thoughtmuse.GraphAPI.State.getGraphName();Thoughtmuse.Net.publishMap(graphName,completionCallback);},DIRECTION_UP:1,DIRECTION_DOWN:2,DIRECTION_LEFT:3,DIRECTION_RIGHT:4,navigate:function(direction,addToSelection){var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var node=null;if(graph.selectedNodes.length>0){node=graph.selectedNodes[graph.selectedNodes.length-1];}
else{node=graph.rootNode;}
switch(direction){case this.DIRECTION_UP:this.goUp(graph,node,addToSelection);break;case this.DIRECTION_DOWN:this.goDown(graph,node,addToSelection);break;case this.DIRECTION_LEFT:this.goLeft(graph,node,addToSelection);break;case this.DIRECTION_RIGHT:this.goRight(graph,node,addToSelection);break;default:break;}},goUp:function(graph,node,addToSelection){if(!Thoughtmuse.GraphAPI.Operations.isNodeRoot(node)){var siblings=node.parent.children;var siblingNo=jQuery.inArray(node,siblings);if(siblingNo>0){if(!addToSelection){graph.selectedNodes=[];}
graph.selectedNodes.push(siblings[siblingNo-1]);}}},goDown:function(graph,node,addToSelection){if(!Thoughtmuse.GraphAPI.Operations.isNodeRoot(node)){var siblings=node.parent.children;var siblingNo=jQuery.inArray(node,siblings);if(siblingNo<(siblings.length-1)){if(!addToSelection){graph.selectedNodes=[];}
graph.selectedNodes.push(siblings[siblingNo+1]);}}},goLeft:function(graph,node,addToSelection){if(!Thoughtmuse.GraphAPI.Operations.isNodeRoot(node)){if(!addToSelection){graph.selectedNodes=[];}
graph.selectedNodes.push(node.parent);}},goRight:function(graph,node,addToSelection){if(!node.folded){if(node.children.length>0){if(!addToSelection){graph.selectedNodes=[];}
graph.selectedNodes.push(node.children[0]);}}},editMode:false,nodeBeingEdited:null,startNodeEdit:function(initialText,node){var editedNode=node;if(!editedNode){editedNode=this.getSelectedNodes()[0];}
if(editedNode){this.clearNodeSelection();this.setEditMode();this.nodeBeingEdited=editedNode;editedNode.editMode=true;}},setEditMode:function(){this.editMode=true;},endEditMode:function(){this.editMode=false;},finishNodeEdit:function(){if(this.editMode){this.endEditMode();if(this.nodeBeingEdited){this.nodeBeingEdited.editMode=false;var idOfEdited=this.nodeBeingEdited.id;this.nodeBeingEdited=null;this.addNodeToSelection(this.findNode(idOfEdited));}
Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.EDIT_TEXT);}}};Thoughtmuse.Graphics={NODE_Z_INDEX:"2",FOLD_INDICATOR_Z_INDEX:"3",CONTEXT_MENU_Z_INDEX:"4",MENUTOOLBAR_Z_INDEX:"4",ACTIVITY_INDICATOR_Z_INDEX:"5",OVERLAY_Z_INDEX:"10",COLORPICKER_Z_INDEX:"10",domLookupCache:{},domLookup:function(id){if(!this.domLookupCache[id]){this.domLookupCache[id]=$("#"+id);}
return this.domLookupCache[id];},clearWorkspace:function(){this.domLookup("workspace").empty();},redrawCurrentGraph:function(options){this.clearWorkspace();this.renderGraph(options);},getRenderedId:function(node){return"RENDERED-"+node.id;},activityIndicator:null,showActivityIndicator:function(message){var msg=message;if(!message){msg="Loading, please wait...";}
this.activityIndicator=new YAHOO.widget.Panel("wait",{width:"350px",fixedcenter:true,close:false,draggable:false,zindex:this.ACTIVITY_INDICATOR_Z_INDEX,modal:true,visible:false});this.activityIndicator.setHeader(msg);this.activityIndicator.setBody('<center><img src="/images/ajax-loader.gif" /></center>');this.activityIndicator.render(document.body);this.activityIndicator.show();},hideActivityIndicator:function(){if(this.activityIndicator){this.activityIndicator.hide();}},workspaceEffectFadeOutHide:function(){this.redrawCurrentGraph(true);Thoughtmuse.GraphAPI.Operations.eachUnfoldedGraphNode(function(element){var visualNodeId=Thoughtmuse.Graphics.getRenderedId(element);Thoughtmuse.Graphics.domLookup(visualNodeId).hide("explode",null,3000,function(){});});},workspaceEffectFadeInShow:function(){this.redrawCurrentGraph({skipConnectingLines:true,skipFoldIndicators:true});Thoughtmuse.GraphAPI.Operations.eachUnfoldedGraphNode(function(element){var visualNodeId=Thoughtmuse.Graphics.getRenderedId(element);Thoughtmuse.Graphics.domLookup(visualNodeId).show("slide",null,2000,function(){});});setTimeout(function(){Thoughtmuse.Graphics.redrawCurrentGraph();},2200);},workspaceEffectYellowBlink:function(){Thoughtmuse.GraphAPI.Operations.eachUnfoldedGraphNode(function(element){var visualNodeId=Thoughtmuse.Graphics.getRenderedId(element);Thoughtmuse.Graphics.domLookup(visualNodeId).effect("highlight",{color:"#37B700"},3000,function(){});});},createNode:function(node,skipFoldIndicator){if(node.editMode){this.createEditableNode(node);}
else{this.createViewNode(node,skipFoldIndicator);}},createEditableNode:function(node){var renderedNodeId=this.getRenderedId(node);Thoughtmuse.Graphics.domLookup("workspace").append("<input selected='true' style='visibility:hidden;z-index:10;' type='text' id='"+renderedNodeId+"'/>");var dataNode=node;var visualEditNode=Thoughtmuse.Graphics.domLookup(renderedNodeId);visualEditNode.val(node.text);visualEditNode.focus();visualEditNode.select();visualEditNode.change(function(){dataNode.text=visualEditNode.val();Thoughtmuse.GraphAPI.Operations.finishNodeEdit();Thoughtmuse.Graphics.redrawCurrentGraph();});visualEditNode.keydown(function(e){Thoughtmuse.Input.handleKeyDownEvent(e,function(key,shiftKey,ctrlKey,altKey){var RETURN_KEY=13;if(key===RETURN_KEY){dataNode.text=visualEditNode.val();Thoughtmuse.GraphAPI.Operations.finishNodeEdit();Thoughtmuse.Graphics.redrawCurrentGraph();}});});},createViewNode:function(node,skipFoldIndicator){var renderedNodeId=this.getRenderedId(node);var selected=Thoughtmuse.GraphAPI.Operations.isNodeSelected(node);var text=node.text;if(jQuery.trim(text)===""){text="<em>empty</em>";}
if(Thoughtmuse.Util.isUrl(text)){text="<a href='"+text+"'>"+text+"</a>";}
Thoughtmuse.Graphics.domLookup("workspace").append("<span id="+renderedNodeId+" style='visibility:hidden;'>"+text+"</span>");var visualNode=Thoughtmuse.Graphics.domLookup(renderedNodeId);if(!visualNode){alert("NULL");}
Thoughtmuse.Input.initNodeMouseInterface(visualNode);visualNode.css("z-index",this.NODE_Z_INDEX);if(node.bold){visualNode.css("font-weight","bold");}
if(node.italic){visualNode.css("font-style","italic");}
if(node.underlined){visualNode.css("text-decoration","underline");}
var size=Thoughtmuse.GraphAPI.Operations.magnifyByGraphZoomPercentage(node.size);if(selected){visualNode.css("background-color","#9C9C9C");visualNode.css("color",node.fontColor);visualNode.css("font-size",size+"%");}
else{visualNode.css("background-color",node.nodeColor);visualNode.css("color",node.fontColor);visualNode.css("font-size",size+"%");}
visualNode.mouseout(function(){visualNode.css("border","");}).mouseover(function(){visualNode.css("border","#9C9C9C solid medium");});if(!skipFoldIndicator&&node.children&&node.children.length>0){Thoughtmuse.Graphics.domLookup("workspace").append("<span id="+renderedNodeId+"fold"+" style='visibility:hidden;'></span>");var foldElementId=renderedNodeId+"fold";var foldElement=Thoughtmuse.Graphics.domLookup(foldElementId);foldElement.css("width","15px");foldElement.css("height","15px");foldElement.css("background-repeat","no-repeat");foldElement.css("z-index",this.FOLD_INDICATOR_Z_INDEX);Thoughtmuse.Input.initFoldWidgetClick(foldElementId,node.id);if(node.folded){foldElement.css("background-image","url('../../images/foldIndicator.jpg')");}
else{foldElement.css("background-image","url('../../images/unfoldIndicator.jpg')");}}},indicateDropTarget:function(targetId,draggedElementXPos,draggedElementYPos){var visualNode=Thoughtmuse.Graphics.domLookup(targetId);var nodeRegion=this.getPointVisualNodeRegionPos(visualNode,draggedElementXPos,draggedElementYPos);var nodeSelectionIndicator="black solid thick";var borderOrientation="";if(nodeRegion===this.VISUAL_NODE_REGIONS.TOP){borderOrientation="border-top";}
if(nodeRegion===this.VISUAL_NODE_REGIONS.BOTTOM){borderOrientation="border-bottom";}
if(nodeRegion===this.VISUAL_NODE_REGIONS.RIGHT){borderOrientation="border-right";}
if(visualNode.css(borderOrientation)!==nodeSelectionIndicator){visualNode.css("border","");visualNode.css(borderOrientation,nodeSelectionIndicator);Thoughtmuse.GraphAPI.Operations.eachGraphNode(function(node){var otherNodeId=Thoughtmuse.Graphics.getRenderedId(node);if(otherNodeId!==targetId){var otherVisualNode=Thoughtmuse.Graphics.domLookup(otherNodeId);otherVisualNode.css("border","");}});}},cancelDropTarget:function(targetId){var nodeCss=Thoughtmuse.Graphics.domLookup(targetId);nodeCss.css("border","");},VISUAL_NODE_REGIONS:{OUTSIDE:"outside",TOP:"top",BOTTOM:"bottom",RIGHT:"right"},getPointVisualNodeRegionPos:function(node,pointX,pointY){var nodeWidth=node.width();var nodeHeight=node.height();var nodePos=node.offset();var nodeLeft=parseInt(nodePos.left,10);var nodeTop=parseInt(nodePos.top,10);var nodeRight=nodeLeft+nodeWidth;var nodeBottom=nodeTop+nodeHeight;var nodeHorizontalMiddle=nodeTop+(nodeHeight/2);var nodeTwoThirdsToRight=nodeLeft+((nodeWidth/3)*2);if((pointX>=nodeLeft&&pointX<=nodeTwoThirdsToRight)&&(pointY>=nodeTop&&pointY<=nodeHorizontalMiddle)){return this.VISUAL_NODE_REGIONS.TOP;}
else if((pointX>=nodeLeft&&pointX<=nodeTwoThirdsToRight)&&(pointY>=nodeHorizontalMiddle&&pointY<=nodeBottom)){return this.VISUAL_NODE_REGIONS.BOTTOM;}
else if((pointX>=nodeTwoThirdsToRight&&pointX<=nodeRight)&&(pointY>=nodeTop&&pointY<=nodeBottom)){return this.VISUAL_NODE_REGIONS.RIGHT;}
else{return this.VISUAL_NODE_REGIONS.OUTSIDE;}},setNodePosition:function(node,visualNode,x,y){var renderedNodeId=this.getRenderedId(node);visualNode.css("position","absolute");visualNode.css("left",x);visualNode.css("top",y);visualNode.css("visibility","visible");visualNode.css("display","");if(node.children&&node.children.length>0){var foldElement=Thoughtmuse.Graphics.domLookup(renderedNodeId+"fold");foldElement.css("position","absolute");foldElement.css("left",x+visualNode.width());foldElement.css("top",y+visualNode.height()-7);foldElement.css("visibility","visible");}
if(node.editMode){visualNode.focus();}},moveNode:function(node,visualNode,deltaX,deltaY){var currLeft=visualNode.offset().left;var currTop=visualNode.offset().top;var newLeft=currLeft+deltaX;var newTop=currTop+deltaY;this.setNodePosition(node,visualNode,newLeft,newTop);},getNodePosition:function(node){var renderedNodeId=this.getRenderedId(node);var visualNode=Thoughtmuse.Graphics.domLookup(renderedNodeId);var left=visualNode.offset().left;var top=visualNode.offset().top;return[left,top];},lastTimeStamp:(new Date().getTime()),stopWatch:function(message){var newTime=new Date().getTime();var diff=newTime-this.lastTimeStamp;var msg=message+": "+diff+" ms";this.lastTimeStamp=new Date().getTime();},renderGraph:function(options){this.domLookupCache={};var graph=Thoughtmuse.GraphAPI.State.currentActiveGraph;var skipFoldIndicators=false;if(options&&options.skipFoldIndicators){skipFoldIndicators=true;}
var skipConnectingLines=false;if(options&&options.skipConnectingLines){skipConnectingLines=true;}
Thoughtmuse.Graphics.stopWatch("Starting stopwatch");this.createGraphNodes(graph.rootNode,graph.selectedNodes,skipFoldIndicators);Thoughtmuse.Graphics.stopWatch("Visual elements created");this.updateGraphPositioning(graph);Thoughtmuse.Graphics.stopWatch("Nodes reposition done");if(!skipConnectingLines){var visualRootNode=Thoughtmuse.Graphics.domLookup(this.getRenderedId(graph.rootNode));this.renderGraphConnections(visualRootNode,graph.rootNode);}
Thoughtmuse.Graphics.stopWatch("Connections rendered");this.removeNodesMarkedOutsideViewport();Thoughtmuse.Graphics.stopWatch("Nodes outside viewport removed");this.updateMindmapLabel();Thoughtmuse.Graphics.stopWatch("Label updated");for(var i=0;i<300;i++){var lookedup=Thoughtmuse.Graphics.domLookup("workspace");}
Thoughtmuse.Graphics.stopWatch("Tested a bunch of DOM lookups ");for(var i=0;i<3;i++){Thoughtmuse.Graphics.domLookup("workspace").append("<span id="+i+" style='visibility:hidden;'></span>");}
Thoughtmuse.Graphics.stopWatch("Tested a bunch of DOM inserts ");},updateMindmapLabel:function(){var mindmapName=Thoughtmuse.GraphAPI.State.currentGraphName;if(!mindmapName||mindmapName===""){mindmapName="<em>Unsaved mindmap</em>";}
Thoughtmuse.Graphics.domLookup("mindmapLabelAnchor").html("<strong>"+mindmapName+"</strong>");},getNodeXSpacing:function(){var DEFAULT_X_SPACING=50;return Thoughtmuse.GraphAPI.Operations.magnifyByGraphZoomPercentage(DEFAULT_X_SPACING);},getNodeYSpacing:function(){var DEFAULT_Y_SPACING=10;return Thoughtmuse.GraphAPI.Operations.magnifyByGraphZoomPercentage(DEFAULT_Y_SPACING);},createGraphNodes:function(node,selectedNodes,skipFoldIndicators){this.createNode(node,skipFoldIndicators);if(!node.folded){var that=this;jQuery.each(node.children,function(i,child){that.createGraphNodes(child,selectedNodes,skipFoldIndicators);});}},adjustNodePositions:function(node,nodeX,nodeY){var branchCollectedDebth=nodeY;var visualNode=Thoughtmuse.Graphics.domLookup(this.getRenderedId(node));if(!node.folded){var that=this;jQuery.each(node.children,function(i,child){var visualChildNode=Thoughtmuse.Graphics.domLookup(that.getRenderedId(child));var childX=nodeX+that.getNodeXSpacing()+visualNode.width();var childY=(nodeY+(i*(that.getNodeYSpacing()+visualChildNode.height())));if(childY<branchCollectedDebth){childY=branchCollectedDebth+that.getNodeYSpacing()+visualChildNode.height();}
branchCollectedDebth=that.adjustNodePositions(child,childX,childY);});}
var middleOffset=0;if(branchCollectedDebth>(nodeY+this.getNodeYSpacing())){middleOffset=(branchCollectedDebth-nodeY)/2;}
this.setNodePosition(node,visualNode,nodeX,nodeY+middleOffset);return branchCollectedDebth+visualNode.height();},updateGraphPositioning:function(graph){var originalRootPosX=100+graph.rootNode.offset[0];var originalRootPosY=(this.getViewPortHeight()/2)+graph.rootNode.offset[1];this.adjustNodePositions(graph.rootNode,originalRootPosX,originalRootPosY);var initialRootNodePos=this.getNodePosition(graph.rootNode);var deltaX=originalRootPosX-initialRootNodePos[0];var deltaY=originalRootPosY-initialRootNodePos[1];var that=this;Thoughtmuse.GraphAPI.Operations.eachUnfoldedGraphNode(function(node){var visualNode=Thoughtmuse.Graphics.domLookup(that.getRenderedId(node));that.moveNode(node,visualNode,deltaX,deltaY);that.markNodeForRemovalIfOutsideViewport(node,visualNode);});},elementsMarkedOutsideViewport:[],markNodeForRemovalIfOutsideViewport:function(node,visualNode){if(this.isOutsideViewport(visualNode)){visualNode.css("visibility","hidden");this.elementsMarkedOutsideViewport.push(visualNode);var foldElementId=this.getRenderedId(node)+"fold";var foldCss=Thoughtmuse.Graphics.domLookup(foldElementId);foldCss.css("visibility","hidden");this.elementsMarkedOutsideViewport.push(foldCss);}},removeNodesMarkedOutsideViewport:function(){var elements=this.elementsMarkedOutsideViewport;if(elements!==null&&elements.length>0){while(elements.length>0){var elementToRemove=elements.pop();elementToRemove.remove();}}
this.elementsMarkedOutsideViewport=[];},isOutsideViewport:function(nodeDiv){return(nodeDiv.offset().top>(this.getViewPortYPos()+this.getViewPortHeight())||nodeDiv.offset().top<this.getViewPortYPos()||(nodeDiv.offset().left+nodeDiv.width())>(this.getViewPortXPos()+this.getViewPortWidth())||nodeDiv.offset().left<this.getViewPortXPos());},renderGraphConnections:function(visualNode,node){var nodeX=parseInt(visualNode.css("left"),10);var nodeY=parseInt(visualNode.css("top"),10);if(!node.folded){var that=this;jQuery.each(node.children,function(i,childNode){var visualChildNode=Thoughtmuse.Graphics.domLookup(that.getRenderedId(childNode));var childX=parseInt(visualChildNode.css("left"),10);var childY=parseInt(visualChildNode.css("top"),10);that.renderNodeConnection(visualNode,visualChildNode,nodeX,nodeY,childX,childY);that.renderGraphConnections(visualChildNode,childNode);});}},renderNodeConnection:function(visualSrcNode,visualDestNode,parentX,parentY,childX,childY){var srcX=parentX+visualSrcNode.width();var srcY=parentY+visualSrcNode.height();var destX=childX;var destY=childY+(visualDestNode.height()/2);this.renderLineConnector(visualSrcNode.width(),srcX,srcY,destX,destY);},renderLineConnector:function(srcNodeWidth,x1,y1,x2,y2){this.renderer=new jsGraphics("workspace");this.renderer.setColor("#9C9C9C");var halfWayPoint=0;if(x1<x2){halfWayPoint=x1+((x2-x1)/2);}
else{halfWayPoint=x1-((x1-x2)/2);}
var halfLength=halfWayPoint/2;var line=this.trimVisibleLine(x1-srcNodeWidth,y1,x1,y1);if(line){this.renderer.drawLine(line[0],line[1],line[2],line[3]);}
line=this.trimVisibleLine(x1,y1,halfWayPoint,y1);if(line){this.renderer.drawLine(line[0],line[1],line[2],line[3]);}
line=this.trimVisibleLine(halfWayPoint,y2,x2,y2);if(line){this.renderer.drawLine(line[0],line[1],line[2],line[3]);}
line=this.trimVisibleLine(halfWayPoint,y1,halfWayPoint,y2);if(line){this.renderer.drawLine(line[0],line[1],line[2],line[3]);}
this.renderer.paint();},trimVisibleLine:function(x1,y1,x2,y2){var trimmedLine=[this.constrainWithinViewportXAxis(x1),this.constrainWithinViewportYAxis(y1),this.constrainWithinViewportXAxis(x2),this.constrainWithinViewportYAxis(y2)];trimmedLine=this.setLineNullIfAtEdges(trimmedLine);return trimmedLine;},constrainWithinViewportXAxis:function(xCoord){var trimmedX=xCoord;if(xCoord>=this.getViewPortWidth()){trimmedX=this.getViewPortWidth();}
else if(xCoord<=0){trimmedX=0;}
return trimmedX;},constrainWithinViewportYAxis:function(yCoord){var trimmedY=yCoord;if(yCoord>=this.getViewPortHeight()){trimmedY=this.getViewPortHeight();}
else if(yCoord<=0){trimmedY=0;}
return trimmedY;},setLineNullIfAtEdges:function(line){if(line[0]===0&&line[2]===0){return null;}
else if(line[1]===0&&line[3]===0){return null;}
else if(line[0]===this.getViewPortWidth()&&line[2]===this.getViewPortWidth()){return null;}
else if(line[1]===this.getViewPortHeight()&&line[3]===this.getViewPortHeight()){return null;}
return line;},makeRect:function(rectX,rectY,rectWidth,rectHeight){var rLeft=rectX;var rRight=rectX+rectWidth;var rTop=rectY;var rBottom=rectY+rectHeight;var rect={x:rectX,y:rectY,width:rectWidth,height:rectHeight,left:rLeft,right:rRight,top:rTop,bottom:rBottom};return rect;},intersectRect:function(r1,r2){return!(r1.left+1>r2.right||r2.left+1>r1.right||r1.top+1>r2.bottom||r2.top+1>r1.bottom);},getViewPortXPos:function(){return Thoughtmuse.Graphics.domLookup("workspace").offset().left;},getViewPortYPos:function(){return Thoughtmuse.Graphics.domLookup("workspace").offset().top;},getViewPortWidth:function(){return Thoughtmuse.Graphics.domLookup("workspace").width();},getViewPortHeight:function(){return Thoughtmuse.Graphics.domLookup("workspace").height();},toggleMoveCursor:function(){document.body.style.cursor="move";},resetCursorStyle:function(){document.body.style.cursor="auto";}};Thoughtmuse.Test.Gui={setupGuiTestPage:function(){Thoughtmuse.Input.initGlobalInput();Thoughtmuse.Widgets.initMenuToolbar();$("#shapeDrawTest").click(function(event){$("#workspace").empty();var jg=new jsGraphics("workspace");jg.setColor("#ff0000");jg.drawLine(0,0,50,50);jg.drawEllipse(0,0,50,50);jg.drawRect(0,0,50,50);jg.paint();});$("#nodeDrawTest").click(function(event){var api=Thoughtmuse.GraphAPI.Operations;$("#workspace").empty();var graph=api.createNewGraph("testGraph",100,100);var node=api.findNode(api.newChild(graph.rootNode));node.text="Plain";node=api.findNode(api.newChild(graph.rootNode));node.text="Half size";node.size=50;node=api.findNode(api.newChild(graph.rootNode));node.text="Double size";node.size=200;node=api.findNode(api.newChild(graph.rootNode));node.text="Bold";node.bold=true;node=api.findNode(api.newChild(graph.rootNode));node.text="Italic";node.italic=true;node=api.findNode(api.newChild(graph.rootNode));node.text="Underlined";node.underlined=true;node=api.findNode(api.newChild(graph.rootNode));node.text="Colored";node.fontColor="#7ACAFF";node.nodeColor="#6600CC";node=api.findNode(api.newChild(graph.rootNode));node.text="http://vg.no";Thoughtmuse.Graphics.redrawCurrentGraph();});$("#lineDrawTest").click(function(event){var api=Thoughtmuse.GraphAPI.Operations;$("#workspace").empty();Thoughtmuse.Graphics.renderLineConnector($("#workspace"),0,0,100,100);Thoughtmuse.Graphics.renderLineConnector($("#workspace"),100,0,0,100);});$("#panelTest").click(function(event){var menuApi=Thoughtmuse.Widgets;menuApi.showPanel("Test header","Test footer","This is a test panel");});$("#simpleDialogTest").click(function(event){var menuApi=Thoughtmuse.Widgets;menuApi.showSimpleDialog("Test header","This is a test dialog","Ok","Cancel",function(){alert("You clicked yes!");},function(){alert("You clicked no!");});});$("#activityIndicatorTest").click(function(event){if($("#activityIndicator").length===0){Thoughtmuse.Graphics.showActivityIndicator();}
else{Thoughtmuse.Graphics.hideActivityIndicator();}});$("#workspacefadeOutHideTest").click(function(event){Thoughtmuse.Graphics.workspaceEffectFadeOutHide();});$("#workspaceFadeInShowTest").click(function(event){Thoughtmuse.Graphics.workspaceEffectFadeInShow();});$("#yellowBlinkWorkspaceTest").click(function(event){Thoughtmuse.Graphics.workspaceEffectYellowBlink();});$("#importMMTest").click(function(event){Thoughtmuse.Operations.importMM();});$("#exportMMTest").click(function(event){Thoughtmuse.Operations.exportMM();});$("#exportTextTest").click(function(event){Thoughtmuse.Operations.exportText();});$("#exportHtmlTest").click(function(event){Thoughtmuse.Operations.exportHtml();});$("#emptyGraphTest").click(function(event){var api=Thoughtmuse.GraphAPI.Operations;api.createNewGraph("testGraph",100,100);Thoughtmuse.Graphics.redrawCurrentGraph();});$("#sizeZoomGraphTest").click(function(event){var api=Thoughtmuse.GraphAPI.Operations;var graph=api.createNewGraph("testGraph",100,100);api.newChild(graph.rootNode);graph.rootNode.children[0].text="Child One";api.newChild(graph.rootNode.children[0]);graph.rootNode.children[0].children[0].text="Child One Grandchild";api.newChild(graph.rootNode);graph.rootNode.children[1].text="Child2";api.addNodeToSelection(graph.rootNode);api.adjustGraphZoom(100);api.adjustNodeSize(graph.rootNode.children[0],100);Thoughtmuse.Graphics.redrawCurrentGraph();});$("#smallGraphTest").click(function(event){var api=Thoughtmuse.GraphAPI.Operations;var graph=api.createNewGraph("testGraph",100,100);api.newChild(graph.rootNode);graph.rootNode.children[0].text="Child One";api.newChild(graph.rootNode.children[0]);graph.rootNode.children[0].children[0].text="Child One Grandchild";api.newChild(graph.rootNode);graph.rootNode.children[1].text="Child2";api.newChild(graph.rootNode.children[1]);graph.rootNode.children[1].children[0].text="Child2-1";api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.addNodeToSelection(graph.rootNode);Thoughtmuse.Graphics.redrawCurrentGraph();});$("#largeGraphTest").click(function(event){var api=Thoughtmuse.GraphAPI.Operations;var graph=api.createNewGraph("testGraph",100,100);api.newChild(graph.rootNode);api.newChild(graph.rootNode.children[0]);api.newChild(graph.rootNode);api.newChild(graph.rootNode.children[1]);api.newChild(graph.rootNode.children[1]);api.newChild(graph.rootNode.children[1]);api.newChild(graph.rootNode.children[1]);api.newChild(graph.rootNode);api.newChild(graph.rootNode.children[2]);api.newChild(graph.rootNode.children[2]);api.newChild(graph.rootNode.children[2]);api.newChild(graph.rootNode.children[2]);api.newChild(graph.rootNode.children[2].children[0]);api.newChild(graph.rootNode.children[2].children[0]);api.newChild(graph.rootNode.children[2].children[0]);api.newChild(graph.rootNode.children[2].children[0]);api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.newChild(graph.rootNode);api.addNodeToSelection(graph.rootNode.children[1]);Thoughtmuse.Graphics.redrawCurrentGraph();});$("#setCursorMoveTest").click(function(event){Thoughtmuse.Graphics.toggleMoveCursor();});$("#setCursorPointerTest").click(function(event){Thoughtmuse.Graphics.resetCursorStyle();});}};Thoughtmuse.Input={initGlobalInput:function(){this.initKeyHandling();this.initDeselectClick();this.initDraggableMap();},initKeyHandling:function(){var operations=Thoughtmuse.Operations;var api=Thoughtmuse.GraphAPI.Operations;var DIR_KEY_DOWN=40;var DIR_KEY_UP=38;var DIR_KEY_LEFT=37;var DIR_KEY_RIGHT=39;var NUM_KEY_ZERO=48;var NUM_KEY_ONE=49;var NUM_KEY_TWO=50;var NUM_KEY_THREE=51;var NUM_KEY_FOUR=52;var NUM_KEY_FIVE=53;var NUM_KEY_SIX=54;var NUM_KEY_SEVEN=55;var NUM_KEY_EIGHT=56;var NUM_KEY_NINE=57;var B_KEY=66;var I_KEY=73;var U_KEY=85;var Z_KEY=90;var S_KEY=83;var T_KEY=84;var N_KEY=78;var O_KEY=79;var C_KEY=67;var X_KEY=88;var V_KEY=86;var F2_KEY=113;var DEL_KEY=46;var SPACE_KEY=32;var RETURN_KEY=13;var INSERT_KEY=45;var TAB_KEY=9;var ESCAPE_KEY=27;var PLUS_KEY=107;var MINUS_KEY=109;var SHIFT_KEY=16;var CTRL_KEY=17;var ALT_KEY=18;window.onkeydown=function(e){Thoughtmuse.Input.handleKeyDownEvent(e,function(key,shiftKey,ctrlKey,altKey,metaKey){if(key===ESCAPE_KEY){operations.clearSelectionAndEndEditMode();return;}
if(!api.editMode){if(key===DIR_KEY_UP){operations.navigateUp(shiftKey);}
else if(key===DIR_KEY_DOWN){operations.navigateDown(shiftKey);}
else if(key===DIR_KEY_LEFT){operations.navigateLeft(shiftKey);}
else if(key===DIR_KEY_RIGHT){operations.navigateRight(shiftKey);}
else if(key===SHIFT_KEY){}
else if(key===ALT_KEY){}
else if(key===CTRL_KEY){}
else if(key===SPACE_KEY){operations.updateSelectedNodeFold();}
else if(key===RETURN_KEY){operations.newSibling();}
else if(key===INSERT_KEY||key===TAB_KEY){operations.newChild();Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.CREATE_CHILD_USING_HOTKEY);}
else if(key===DEL_KEY){operations.deleteSelection();}
else if((ctrlKey||metaKey)&&key===B_KEY){operations.setSelectionBold();}
else if((ctrlKey||metaKey)&&key===I_KEY){operations.setSelectionItalic();}
else if((ctrlKey||metaKey)&&key===U_KEY){operations.setSelectionUnderlined();}
else if((ctrlKey||metaKey)&&key===S_KEY){operations.saveFile();}
else if((ctrlKey||metaKey)&&key===O_KEY){operations.loadFile();}
else if((ctrlKey||metaKey)&&key===N_KEY){operations.newFile();}
else if((ctrlKey||metaKey)&&key===Z_KEY){operations.undo();}
else if((ctrlKey||metaKey)&&key===C_KEY){operations.copySelection();}
else if((ctrlKey||metaKey)&&key===X_KEY){operations.cutSelection();}
else if((ctrlKey||metaKey)&&key===V_KEY){operations.pasteClipboardIntoSelection();}
else if((ctrlKey||metaKey)&&key===PLUS_KEY){operations.growSelection();}
else if((ctrlKey||metaKey)&&key===MINUS_KEY){operations.shrinkSelection();}
else{if(!altKey&&!ctrlKey&&!metaKey){var keyChar=String.fromCharCode(key);operations.switchNodeToInputMode(keyChar);}}}});};},handleKeyDownEvent:function(e,callback){var api=Thoughtmuse.GraphAPI.Operations;var key=null;e=e||window.event;if(e.keyCode){key=e.keyCode;}
else if(e.which){key=e.which;}
var shiftKey=false;var ctrlKey=false;var altKey=false;var metaKey=false;if(e.ctrlKey===true){ctrlKey=true;}
if(e.shiftKey===true){shiftKey=true;}
if(e.altKey===true){altKey=true;}
if(e.metaKey===true){metaKey=true;}
callback(key,shiftKey,ctrlKey,altKey,metaKey);if(!api.editMode&&!((ctrlKey||metaKey)&&key===84)&&!((ctrlKey||metaKey)&&key===87)){e.cancelBubble=true;e.returnValue=false;if(e.stopPropagation){e.stopPropagation();e.preventDefault();}
return false;}},initDeselectClick:function(){Thoughtmuse.Graphics.domLookup("workspace").click(function(e){window.focus();var clickTarget;if(e.target){clickTarget=e.target.id;}
if(e.srcElement){clickTarget=e.target.id;}
if(clickTarget==="content"||clickTarget==="wrapper"||clickTarget==="workspace"){Thoughtmuse.Operations.clearSelectionAndEndEditMode();}});},initDraggableMap:function(){var workspaceDiv=Thoughtmuse.Graphics.domLookup("workspace");var draggable=new YAHOO.util.DDProxy("workspace","default",{});workspaceDiv.width($(window).width()-30);workspaceDiv.height($(window).height()-workspaceDiv.offset().top-20);var workspaceDivHomePosLeft=workspaceDiv.css("left");var workspaceDivHomePosTop=workspaceDiv.css("top");var dragStartPosX=0;var dragStartPosY=0;var dragStarts=function(e){Thoughtmuse.Graphics.toggleMoveCursor();workspaceDivHomePosLeft=workspaceDiv.css("left");workspaceDivHomePosTop=workspaceDiv.css("top");dragStartPosX=null;dragStartPosY=null;YAHOO.util.Dom.setStyle(this.getDragEl(),'visibility','hidden');YAHOO.util.Dom.setStyle(this.getDragEl(),'width','1px');YAHOO.util.Dom.setStyle(this.getDragEl(),'height','1px');};var drag=function(e){if(dragStartPosX&&dragStartPosY){var deltaX=e.e.screenX-dragStartPosX;var deltaY=e.e.screenY-dragStartPosY;Thoughtmuse.GraphAPI.Operations.adjustGraphLocation(deltaX,deltaY);}
workspaceDiv.css("left",workspaceDivHomePosLeft);workspaceDiv.css("top",workspaceDivHomePosTop);dragStartPosX=e.e.screenX;dragStartPosY=e.e.screenY;Thoughtmuse.Graphics.redrawCurrentGraph();};var dragStops=function(e){workspaceDiv.css("left",workspaceDivHomePosLeft);workspaceDiv.css("top",workspaceDivHomePosTop);Thoughtmuse.Graphics.resetCursorStyle();};draggable.on('mouseUpEvent',dragStops,draggable,true);draggable.on('dragEvent',drag,draggable,true);draggable.on('startDragEvent',dragStarts,draggable,true);},initFoldWidgetClick:function(foldElementId,nodeId){var id=nodeId;Thoughtmuse.Graphics.domLookup(foldElementId).click(function(){Thoughtmuse.Operations.updateNodeFold(id);});},initNodeMouseInterface:function(visualNode){var visualNodeId=visualNode[0].id;var dataElementId=visualNodeId.replace("RENDERED-","");var dataNode=Thoughtmuse.GraphAPI.Operations.findNode(dataElementId);this.initNodeDragDropAndLeftClick(visualNode,dataNode);this.initNodeRightClick(visualNode,dataNode);},initNodeDragDropAndLeftClick:function(visualDraggedNode,dataNode){var visualDraggedNodeId=visualDraggedNode[0].id;var draggable=new YAHOO.util.DDProxy(visualDraggedNodeId);var dragTarget=new YAHOO.util.DDTarget(visualDraggedNodeId);var dragStarts=function(e){};var dragStops=function(e){Thoughtmuse.Input.handleNodeLeftClick(e.e,dataNode);};var draggedOverTarget=function(e){var targetVisualNodeId=e.info;var targetNodeId=e.info.replace("RENDERED-","");var targetNodeIsDescendant=Thoughtmuse.GraphAPI.Operations.isNodeDescendantOfNode(targetNodeId,dataNode.id);if(targetVisualNodeId!==visualDraggedNodeId&&targetVisualNodeId!=="workspace"&&!targetNodeIsDescendant){var draggedElementXPos=e.event.clientX;var draggedElementYPos=e.event.clientY;Thoughtmuse.Graphics.indicateDropTarget(targetVisualNodeId,draggedElementXPos,draggedElementYPos);}};var draggedOutOfTarget=function(e){var targetVisualNodeId=e.info;Thoughtmuse.Graphics.cancelDropTarget(targetVisualNodeId);};var droppedOnTarget=function(e){var targetVisualNodeId=e.info;var targetNodeId=e.info.replace("RENDERED-","");var targetNodeIsDescendant=Thoughtmuse.GraphAPI.Operations.isNodeDescendantOfNode(targetNodeId,dataNode.id);var targetNode=Thoughtmuse.GraphAPI.Operations.findNode(targetNodeId);var targetNodeIsRoot=Thoughtmuse.GraphAPI.Operations.isNodeRoot(targetNode);if(targetNodeId!==visualDraggedNodeId&&!Thoughtmuse.GraphAPI.Operations.editMode&&targetVisualNodeId!=="workspace"&&!targetNodeIsDescendant){var draggedElementXPos=e.event.clientX;var draggedElementYPos=e.event.clientY;var nodeRegion=Thoughtmuse.Graphics.getPointVisualNodeRegionPos(Thoughtmuse.Graphics.domLookup(targetVisualNodeId),draggedElementXPos,draggedElementYPos);if(nodeRegion===Thoughtmuse.Graphics.VISUAL_NODE_REGIONS.TOP&&!targetNodeIsRoot){if(Thoughtmuse.GraphAPI.Operations.isNodeSelected(dataNode)){Thoughtmuse.Operations.makeSelectionOlderSiblingsOfNode(targetNodeId);}else{Thoughtmuse.Operations.makeNodeOlderSiblingOfNode(dataNode.id,targetNodeId);}}
if(nodeRegion===Thoughtmuse.Graphics.VISUAL_NODE_REGIONS.BOTTOM&&!targetNodeIsRoot){if(Thoughtmuse.GraphAPI.Operations.isNodeSelected(dataNode)){Thoughtmuse.Operations.makeSelectionYoungerSiblingsOfNode(targetNodeId);}else{Thoughtmuse.Operations.makeNodeYoungerSiblingOfNode(dataNode.id,targetNodeId);}}
if(nodeRegion===Thoughtmuse.Graphics.VISUAL_NODE_REGIONS.RIGHT){if(Thoughtmuse.GraphAPI.Operations.isNodeSelected(dataNode)){Thoughtmuse.Operations.makeSelectionChildOfNode(targetNodeId);}else{Thoughtmuse.Operations.makeNodeChildOfNode(dataNode.id,targetNodeId);}}
Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.DRAG_AND_DROP);}};draggable.on('startDragEvent',dragStarts,draggable,true);draggable.on('mouseUpEvent',dragStops,draggable,true);draggable.on('dragOverEvent',draggedOverTarget,draggable,true);draggable.on('dragOutEvent',draggedOutOfTarget,draggable,true);draggable.on('dragDropEvent',droppedOnTarget,draggable,true);},initNodeRightClick:function(visualNode,node){var api=Thoughtmuse.GraphAPI.Operations;var operations=Thoughtmuse.Operations;visualNode.rightClick(function(e){if(!api.editMode){var selected=api.isNodeSelected(node);operations.selectThisNodeOnly(node);}
var offset=Thoughtmuse.Graphics.domLookup(this[0].id).offset();Thoughtmuse.Widgets.displayContextMenu(e.pageX,e.pageY);e.cancelBubble=true;e.returnValue=false;if(e.stopPropagation){e.stopPropagation();e.preventDefault();}
return false;});},handleNodeLeftClick:function(e,node){var api=Thoughtmuse.GraphAPI.Operations;var operations=Thoughtmuse.Operations;Thoughtmuse.Input.handleKeyDownEvent(e,function(key,shiftKey,ctrlKey,altKey){if(!api.editMode){if(shiftKey||ctrlKey){operations.addNodeToSelection(node);Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.MULTIPLE_SELECTION);}
else{operations.selectThisNodeOnly(node);Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.SELECT_ELEMENT);}}});}};Thoughtmuse.Locale={getStr:function(language,key){resource=Thoughtmuse.Locale[language].Bundle[key];if(!resource){Thoughtmuse.Log.warning("Was unable to find resource '"+key+"' in language '"+language+"'");resource=Thoughtmuse.Locale[language].Bundle.DEFAULT;}
return resource;}};Thoughtmuse.Locale.EN={Bundle:{test_string1:"This is a test string",test_string2:"This is also a test string",DEFAULT:"NO SUCH LANGUAGE RESOURCE"}};Thoughtmuse.Locale.NO={Bundle:{test_string1:"Dette er en test streng",test_string2:"Dette er også en test streng",DEFAULT:"SPRÅK-RESSURSSEN EKSISTERER IKKE"}};Thoughtmuse.Log={info:function(msg){Thoughtmuse.Log.internalLog(msg,"info");},warning:function(msg){Thoughtmuse.Log.internalLog(msg,"warn");},error:function(msg){Thoughtmuse.Log.internalLog(msg,"error");},internalLog:function(msg,category){YAHOO.log(msg,category);}};Thoughtmuse.Net={getMapList:function(handleResponseFunc){var url="/mindmap_services/get_map_list";Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getTemplateList:function(handleResponseFunc){var url="/mindmap_services/get_template_list";Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getMap:function(mapName,handleResponseFunc){var url="/mindmap_services/get_map/"+mapName;Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getPublishedMap:function(mapName,owner,handleResponseFunc){var url="/mindmap_services/get_published_map/"+mapName+"?owner="+owner;Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getTemplate:function(mapName,handleResponseFunc){var url="/mindmap_services/get_template/"+mapName;Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},deleteMap:function(mapName,handleResponseFunc){var url="/mindmap_services/delete_map/"+mapName;Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},saveOrUpdateMap:function(mapName,mapData,handleResponseFunc){mapData.selectedNodes=[];var callback={success:handleResponseFunc,failure:this.handleTransmissionFailure};var url="/mindmap_services/save_or_update_map/"+mapName;var serializedObject=YAHOO.lang.JSON.stringify(mapData);$('#uploadData')[0].value=serializedObject;YAHOO.util.Connect.setForm($('#testForm')[0]);var connectObject=YAHOO.util.Connect.asyncRequest('POST',url,callback);},renameMap:function(oldMapName,newMapName,handleResponseFunc){var url="/mindmap_services/rename_map/"+oldMapName+"?newId="+newMapName;Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getSubscriptionType:function(handleResponseFunc){var url="/mindmap_services/get_user_subscription_type/";Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},canUserSaveMoreMaps:function(handleResponseFunc){var url="/mindmap_services/can_user_save_more_maps/";Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getUploadPage:function(handleResponseFunc){var url="/mindmap_services/upload_mindmap/";Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getTemplateSelectPage:function(handleResponseFunc){var url="/mindmap_services/template_select_page/";if(Thoughtmuse.Tutorial.started){url+="?tutorial=true";}
Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},getFileOpenPage:function(handleResponseFunc){var url="/mindmap_services/file_open_page/";Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},serveExportedTxtFile:function(exportedData,handleResponseFunc){var url="/mindmap_services/render_exported_txt_as_file/";var callback={success:handleResponseFunc,failure:this.handleTransmissionFailure};$('#uploadData')[0].value=exportedData;YAHOO.util.Connect.setForm($('#testForm')[0]);var connectObject=YAHOO.util.Connect.asyncRequest('POST',url,callback);},serveExportedHtmlDoc:function(exportedData,handleResponseFunc){var url="/mindmap_services/render_exported_html_as_new_page/";var callback={success:handleResponseFunc,failure:this.handleTransmissionFailure};$('#uploadData')[0].value=exportedData;YAHOO.util.Connect.setForm($('#testForm')[0]);var connectObject=YAHOO.util.Connect.asyncRequest('POST',url,callback);},serveExportedMMFile:function(exportedData,handleResponseFunc){var url="/mindmap_services/render_exported_mm_as_file/";var callback={success:handleResponseFunc,failure:this.handleTransmissionFailure};$('#uploadData')[0].value=exportedData;YAHOO.util.Connect.setForm($('#testForm')[0]);var connectObject=YAHOO.util.Connect.asyncRequest('POST',url,callback);},publishMap:function(mapName,handleResponseFunc){var url="/mindmap_services/publish_mindmap/"+mapName;Thoughtmuse.Net.ajaxGet(url,handleResponseFunc);},parseJSONMapData:function(jsonString){var jsonObject;try{jsonObject=YAHOO.lang.JSON.parse(jsonString);}
catch(e){throw e;}
return jsonObject;},handleTransmissionFailure:function(o){var menuApi=Thoughtmuse.Widgets;menuApi.showPanel("ThoughtMuse Error","ThoughtMuse Error",o.responseText);Thoughtmuse.Graphics.hideActivityIndicator();},handlePostResponse:function(o){if(o.responseText!=="OK"){Thoughtmuse.Net.handleTransmissionFailure(o);}},ajaxGet:function(url,successFunc){var callback={success:successFunc,failure:this.handleTransmissionFailure};var request=YAHOO.util.Connect.asyncRequest('GET',url,callback);},ajaxPost:function(url,successFunc){var callback={success:this.handlePostResponse,failure:this.handleTransmissionFailure};var request=YAHOO.util.Connect.asyncRequest('POST',url,callback);}};Thoughtmuse.Operations={navigateDown:function(addToSelection){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.navigate(api.DIRECTION_DOWN,addToSelection);Thoughtmuse.Graphics.redrawCurrentGraph();}},navigateUp:function(addToSelection){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.navigate(api.DIRECTION_UP,addToSelection);Thoughtmuse.Graphics.redrawCurrentGraph();}},navigateLeft:function(addToSelection){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.navigate(api.DIRECTION_LEFT,addToSelection);Thoughtmuse.Graphics.redrawCurrentGraph();}},navigateRight:function(addToSelection){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.navigate(api.DIRECTION_RIGHT,addToSelection);Thoughtmuse.Graphics.redrawCurrentGraph();}},updateSelectedNodeFold:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){api.invertNodeFold(node);});Thoughtmuse.Graphics.redrawCurrentGraph();}},updateNodeFold:function(nodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();var node=api.findNode(nodeId);api.invertNodeFold(node);Thoughtmuse.Graphics.redrawCurrentGraph();}},newSibling:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.newSibling();Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.CREATE_SIBLING);}},newChild:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.newChild();Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.CREATE_CHILD);}},selectThisNodeOnly:function(node){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.clearNodeSelection();api.addNodeToSelection(node);Thoughtmuse.Graphics.redrawCurrentGraph();}},clearSelectionAndEndEditMode:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.finishNodeEdit();api.clearNodeSelection();Thoughtmuse.Graphics.redrawCurrentGraph();}},deleteSelection:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.deleteSelectedNodesFromGraph();Thoughtmuse.Graphics.redrawCurrentGraph();}},copySelection:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){api.copySelection();}},cutSelection:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.cutSelection();Thoughtmuse.Graphics.redrawCurrentGraph();}},pasteClipboardIntoSelection:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.pasteClipboardIntoSelection();Thoughtmuse.Graphics.redrawCurrentGraph();}},addNodeToSelection:function(node){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.addNodeToSelection(node);Thoughtmuse.Graphics.redrawCurrentGraph();}},makeNodeChildOfNode:function(movedNodeId,targetNodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.makeNodeChildOfNode(movedNodeId,targetNodeId);Thoughtmuse.Graphics.redrawCurrentGraph();}},makeNodeOlderSiblingOfNode:function(movedNodeId,targetNodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.makeNodeOlderSiblingOfNode(movedNodeId,targetNodeId);Thoughtmuse.Graphics.redrawCurrentGraph();}},makeNodeYoungerSiblingOfNode:function(movedNodeId,targetNodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.makeNodeYoungerSiblingOfNode(movedNodeId,targetNodeId);Thoughtmuse.Graphics.redrawCurrentGraph();}},makeSelectionChildOfNode:function(targetNodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.makeSelectionChildOfNode(targetNodeId);Thoughtmuse.Graphics.redrawCurrentGraph();}},makeSelectionYoungerSiblingsOfNode:function(targetNodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.makeSelectionYoungerSiblingsOfNode(targetNodeId);Thoughtmuse.Graphics.redrawCurrentGraph();}},makeSelectionOlderSiblingsOfNode:function(targetNodeId){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.makeSelectionOlderSiblingsOfNode(targetNodeId);Thoughtmuse.Graphics.redrawCurrentGraph();}},setSelectionBold:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){node.bold=(!node.bold);});Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.SET_BOLD);}},setSelectionItalic:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){node.italic=(!node.italic);});Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.SET_MULTIPLE_ITALIC);}},setSelectionUnderlined:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){node.underlined=(!node.underlined);});Thoughtmuse.Graphics.redrawCurrentGraph();}},growSelection:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){api.adjustNodeSize(node,20);});Thoughtmuse.Graphics.redrawCurrentGraph();}},shrinkSelection:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){api.adjustNodeSize(node,-20);});Thoughtmuse.Graphics.redrawCurrentGraph();}},newFile:function(){Thoughtmuse.File.newFile(function(){Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Graphics.workspaceEffectFadeInShow();});},saveFileAs:function(){var api=Thoughtmuse.GraphAPI.Operations;if(Thoughtmuse.GlobalState.userLoggedIn&&api.isAnyGraphLoaded()){Thoughtmuse.File.saveFileAs(function(){Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Graphics.workspaceEffectYellowBlink();});}},saveFile:function(){var api=Thoughtmuse.GraphAPI.Operations;if(Thoughtmuse.GlobalState.userLoggedIn&&api.isAnyGraphLoaded()){Thoughtmuse.File.saveFile(function(){Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Graphics.workspaceEffectYellowBlink();});}},loadFile:function(){if(Thoughtmuse.GlobalState.userLoggedIn){Thoughtmuse.File.loadFile(function(){Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Graphics.workspaceEffectFadeInShow();});}},renameFile:function(){var api=Thoughtmuse.GraphAPI.Operations;if(Thoughtmuse.GlobalState.userLoggedIn&&api.isAnyGraphLoaded()){Thoughtmuse.File.renameFile(function(){Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Graphics.workspaceEffectYellowBlink();});}},deleteMindmap:function(){if(Thoughtmuse.GlobalState.userLoggedIn){Thoughtmuse.File.deleteMindmap();}},undo:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.undoLastChange();Thoughtmuse.Graphics.redrawCurrentGraph();Thoughtmuse.Tutorial.completeLesson(Thoughtmuse.Tutorial.Lessons.UNDO);}},switchNodeToInputMode:function(character){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.startNodeEdit(""+character,null);Thoughtmuse.Graphics.redrawCurrentGraph();}},setNodeColor:function(color){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){var newColor=color;Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){node.nodeColor=newColor;});Thoughtmuse.Graphics.redrawCurrentGraph();}},setFontColor:function(color){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){var newColor=color;Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.eachSelectedNode(function(node){node.fontColor=newColor;});Thoughtmuse.Graphics.redrawCurrentGraph();}},zoomIn:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.adjustGraphZoom(20);Thoughtmuse.Graphics.redrawCurrentGraph();}},zoomOut:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.GraphAPI.State.storeCurrentGraphState();api.adjustGraphZoom(-20);Thoughtmuse.Graphics.redrawCurrentGraph();}},importMM:function(){if(Thoughtmuse.GlobalState.userLoggedIn){Thoughtmuse.Transformations.importMM();}},exportHtml:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.Transformations.exportHtml();}},exportText:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.Transformations.exportText();}},exportMM:function(){var api=Thoughtmuse.GraphAPI.Operations;if(api.isAnyGraphLoaded()){Thoughtmuse.Transformations.exportMM();}},publishMindmap:function(){var api=Thoughtmuse.GraphAPI.Operations;if(Thoughtmuse.GlobalState.userLoggedIn&&api.isAnyGraphLoaded()){Thoughtmuse.File.publishMindmap();}},startTutorial:function(){Thoughtmuse.Tutorial.start();},toggleFileOpenOrTutorialIfNoFilesSaved:function(){Thoughtmuse.File.toggleFileOpenOrTutorialIfNoFilesSaved();}};Thoughtmuse.Transformations={importMM:function(){Thoughtmuse.Net.getUploadPage(function(response){Thoughtmuse.Widgets.showPanel("Import a Freemind mindmap","Conversion of large files can take a while",response.responseText,"300px");});},exportHtml:function(){var exported_html="";Thoughtmuse.GraphAPI.Operations.eachGraphNode(function(node,debth){var indent="";for(var i=0;i<debth;i+=1){indent+="&nbsp;&nbsp;&nbsp;&nbsp;";}
var styles="";if(node.bold){styles+="font-weight:bold;";}
if(node.italic){styles+="font-style:italic;";}
if(node.underlined){styles+="text-decoration:underline;";}
styles+="font-size:"+node.size+"%;";styles+="font-size:"+node.size+"%;";if(node.fontColor){styles+="color:"+node.fontColor+";";}
if(node.nodeColor){styles+="background-color:"+node.nodeColor+";";}
exported_html+="<div style='"+styles+"' >";exported_html+=indent+node.text;},function(node,debth){exported_html+=("</div>"+"\n");});Thoughtmuse.Net.serveExportedHtmlDoc(exported_html,function(response){Thoughtmuse.Widgets.showContentInNewWindow(response.responseText);});},exportText:function(){var exported_text="";Thoughtmuse.GraphAPI.Operations.eachGraphNode(function(node,debth){for(var i=0;i<debth;i+=1){exported_text+="    ";}
exported_text+=(node.text+"@BACKSLASH@");});var url="/mindmap_services/render_exported_txt_as_file/?uploadData=";Thoughtmuse.Widgets.openUrlInNewWindow(url+exported_text);},exportMM:function(){var exported_mm_file_body="<map>@BACKSLASH@";Thoughtmuse.GraphAPI.Operations.eachGraphNode(function(node,debth){var fontStyle="";if(node.bold){fontStyle+="BOLD='true' ";}
if(node.italic){fontStyle+="ITALIC='true' ";}
var nodeStyle="";if(node.nodeColor){}
if(node.fontColor){}
exported_mm_file_body+=("<node TEXT='"+node.text+"' "+nodeStyle+" >"+"@BACKSLASH@");exported_mm_file_body+=("<font "+fontStyle+" SIZE='12'/>"+"@BACKSLASH@");},function(node,debth){exported_mm_file_body+=("</node>"+"@BACKSLASH@");});exported_mm_file_body+="</map>";var url="/mindmap_services/render_exported_mm_as_file/?uploadData=";Thoughtmuse.Widgets.openUrlInNewWindow(url+exported_mm_file_body);}};Thoughtmuse.Util={getTimestamp:function(){return(new Date()).getTime();},getRandomNumber:function(maxNumber){var random=Math.floor(Math.random()*maxNumber);return random;},incrementingId:0,getUniqueId:function(){this.incrementingId++;return"TM"+this.incrementingId;},isUrl:function(text){var match=text.match(/^http/);return(match!==null&&match.length>0);}};if(typeof Object.create!=='function'){Object.create=function(o){var F=function(){};F.prototype=o;return new F();};}
Thoughtmuse.Widgets={menuToolbar:null,initMenuToolbar:function(){var operations=Thoughtmuse.Operations;var logonRestrictedFileOps=[{text:"Open",helptext:"<em>Ctrl + O</em>",onclick:{fn:function(){operations.loadFile();}}},{text:"Save",helptext:"<em>Ctrl + S</em>",onclick:{fn:function(){operations.saveFile();}}},{text:"Save as..",onclick:{fn:function(){operations.saveFileAs();}}},{text:"Rename",onclick:{fn:function(){operations.renameFile();}}},{text:"Delete",onclick:{fn:function(){operations.deleteMindmap();}}},{text:"Publish",onclick:{fn:function(){operations.publishMindmap();}}},{text:"Import",submenu:{id:"importmenu",itemdata:[{text:"Import Freemind file (.mm)",onclick:{fn:function(){operations.importMM();}}}]}}];var logonRestrictedFreemindExport={text:"Export Freemind file (.mm)",onclick:{fn:function(){operations.exportMM();}}};if(!Thoughtmuse.GlobalState.userLoggedIn){logonRestrictedFileOps={text:"<em>Log in to save and publish mindmaps!</em>"};logonRestrictedFreemindExport=null;}
var aItemData=[{text:"File",submenu:{id:"filemenu",itemdata:[[{text:"New",helptext:"<em>Ctrl + N</em>",onclick:{fn:function(){operations.newFile();}}}],logonRestrictedFileOps,[{text:"Export",submenu:{id:"exportmenu",itemdata:[{text:"Export to html",onclick:{fn:function(){operations.exportHtml();}}},{text:"Export to text",onclick:{fn:function(){operations.exportText();}}},logonRestrictedFreemindExport]}}]]}},{text:"Edit",submenu:{id:"editmenu",itemdata:[[{text:"Copy",helptext:"<em>Ctrl + C</em>",onclick:{fn:function(){operations.copySelection();}}},{text:"Cut",helptext:"<em>Ctrl + X</em>",onclick:{fn:function(){operations.cutSelection();}}},{text:"Paste",helptext:"<em>Ctrl + V</em>",onclick:{fn:function(){operations.pasteClipboardIntoSelection();}}},{text:"Delete",helptext:"<em>Del</em>",onclick:{fn:function(){operations.deleteSelection();}}}],[{text:"Edit text",helptext:"<em>Start typing</em>",onclick:{fn:function(){operations.switchNodeToInputMode("");}}},{text:"New child",helptext:"<em>Tab or Insert</em>",onclick:{fn:function(){operations.newChild();}}},{text:"New sibling",helptext:"<em>Return</em>",onclick:{fn:function(){operations.newSibling();}}}],[{text:"Fold/Unfold",helptext:"<em>Space</em>",onclick:{fn:function(){operations.updateSelectedNodeFold();}}},{text:"Clear selected",helptext:"<em>Esc</em>",onclick:{fn:function(){operations.clearSelectionAndEndEditMode();}}}],[{text:"Undo",helptext:"<em>Ctrl + Z</em>",onclick:{fn:function(){operations.undo();}}}]]}},{text:"Format",submenu:{id:"formatmenu",itemdata:[[{text:"<b>Bold</b>",helptext:"<em>Ctrl + B</em>",onclick:{fn:function(){operations.setSelectionBold();}}},{text:"<u>Underlined</u>",helptext:"<em>Ctrl + U</em>",onclick:{fn:function(){operations.setSelectionUnderlined();}}},{text:"<i>Italic</i>",helptext:"<em>Ctrl + I</em>",onclick:{fn:function(){operations.setSelectionItalic();}}}],[{text:"Larger",helptext:"<em>Ctrl + plus</em>",onclick:{fn:function(){operations.growSelection();}}},{text:"Smaller",helptext:"<em>Ctrl + minus</em>",onclick:{fn:function(){operations.shrinkSelection();}}}],[{text:"Font color",onclick:{fn:function(){Thoughtmuse.Widgets.bringUpColorPicker(Thoughtmuse.Operations.setFontColor);}}},{text:"Background color",onclick:{fn:function(){Thoughtmuse.Widgets.bringUpColorPicker(Thoughtmuse.Operations.setNodeColor);}}}]]}},{text:"View",submenu:{id:"viewmenu",itemdata:[{text:"Zoom in",onclick:{fn:function(){operations.zoomIn();}}},{text:"Zoom out",onclick:{fn:function(){operations.zoomOut();}}}]}},{text:"Help",submenu:{id:"helpmenu",itemdata:[{text:"Tutorial",onclick:{fn:function(){operations.startTutorial();}}},{text:"About",onclick:{fn:function(){Thoughtmuse.Widgets.showAboutPanel();}}}]}}];this.menuToolbar=new YAHOO.widget.MenuBar("menuToolbar",{position:"static",zindex:Thoughtmuse.Graphics.MENUTOOLBAR_Z_INDEX});this.menuToolbar.addItems(aItemData);this.menuToolbar.render($("#menubarAnchor")[0]);this.menuToolbar.show();},hideMenuToolbar:function(){$("#menuToolbar").hide();},showMenuToolbar:function(){$("#menuToolbar").show();},showAboutPanel:function(){var version=$("#product_version").html();var body="<p>ThoughtMuse is a product of <a href='http://climbingmind.com'>Climbing Mind Ltd</a>. All rights reserved.</p>"+"<p>Current version: "+version+"</p>";Thoughtmuse.Widgets.showPanel("About ThoughMuse","",body,"600px");},nodeContextMenu:null,displayContextMenu:function(xPos,yPos){var operations=Thoughtmuse.Operations;if(!this.nodeContextMenu){this.nodeContextMenu=new YAHOO.widget.ContextMenu("nodeContextMenu",{position:"dynamic",zindex:Thoughtmuse.Graphics.CONTEXT_MENU_Z_INDEX});this.nodeContextMenu.addItems([{text:"Copy",helptext:"<em>Ctrl + C</em>",onclick:{fn:function(){operations.copySelection();}}},{text:"Cut",helptext:"<em>Ctrl + X</em>",onclick:{fn:function(){operations.cutSelection();}}},{text:"Paste",helptext:"<em>Ctrl + V</em>",onclick:{fn:function(){operations.pasteClipboardIntoSelection();}}},{text:"Delete",helptext:"<em>Del</em>",onclick:{fn:function(){operations.deleteSelection();}}},{text:"Edit text",helptext:"<em>Start typing</em>",onclick:{fn:function(){operations.switchNodeToInputMode("");}}},{text:"New child",helptext:"<em>Tab or Insert</em>",onclick:{fn:function(){operations.newChild();}}},{text:"New sibling",helptext:"<em>Return</em>",onclick:{fn:function(){operations.newSibling();}}},{text:"Fold/Unfold",helptext:"<em>Space</em>",onclick:{fn:function(){operations.updateSelectedNodeFold();}}},{text:"<b>Bold</b>",helptext:"<em>Ctrl + B</em>",onclick:{fn:function(){operations.setSelectionBold();}}},{text:"<u>Underlined</u>",helptext:"<em>Ctrl + U</em>",onclick:{fn:function(){operations.setSelectionUnderlined();}}},{text:"<i>Italic</i>",helptext:"<em>Ctrl + I</em>",onclick:{fn:function(){operations.setSelectionItalic();}}},{text:"Larger",helptext:"<em>Ctrl + plus</em>",onclick:{fn:function(){operations.growSelection();}}},{text:"Smaller",helptext:"<em>Ctrl + minus</em>",onclick:{fn:function(){operations.shrinkSelection();}}},{text:"Font color",onclick:{fn:function(){Thoughtmuse.Widgets.bringUpColorPicker(Thoughtmuse.Operations.setFontColor);}}},{text:"Background color",onclick:{fn:function(){Thoughtmuse.Widgets.bringUpColorPicker(Thoughtmuse.Operations.setNodeColor);}}}]);}
this.nodeContextMenu.cfg.setProperty("x",(xPos+20));this.nodeContextMenu.cfg.setProperty("y",yPos);this.nodeContextMenu.render($("#workspace")[0]);this.nodeContextMenu.show();},colorPicker:null,bringUpColorPicker:function(colorSetFunction){var colorSetter=colorSetFunction;$("#workspace").append("<div id='yui-picker-panel' class='yui-picker-panel'>"+"<div class='hd'>Please choose a color:</div>"+"<div class='bd'>"+"<div class='yui-picker' id='yui-picker'></div>"+"</div> "+"<div class='ft'></div>"+"</div>");this.colorPicker=function(){var Event=YAHOO.util.Event,Dom=YAHOO.util.Dom,lang=YAHOO.lang;return{init:function(){this.dialog=new YAHOO.widget.Dialog("yui-picker-panel",{width:"500px",close:true,fixedcenter:true,zindex:Thoughtmuse.Graphics.COLORPICKER_Z_INDEX,visible:false,constraintoviewport:true,buttons:[{text:"Set color",handler:this.handleOk,isDefault:true},{text:"Cancel",handler:this.handleCancel}]});this.dialog.renderEvent.subscribe(function(){if(!this.picker){YAHOO.log("Instantiating the color picker","info","example");this.picker=new YAHOO.widget.ColorPicker("yui-picker",{container:this.dialog,images:{PICKER_THUMB:"images/picker_thumb.png",HUE_THUMB:"images/hue_thumb.png"}});this.picker.on("rgbChange",function(o){YAHOO.log(lang.dump(o),"info","example");});}});this.dialog.render($("#workspace")[0]);},handleOk:function(){colorSetter("#"+this.picker.get("hex"));this.hide();},handleCancel:function(){this.cancel();}};}();this.colorPicker.init();this.colorPicker.dialog.show();},simplePanel:null,showPanel:function(header,footer,content,panelWidth,panelHeight){var containerWidth="300px";if(panelWidth){containerWidth=panelWidth;}
this.simplePanel=new YAHOO.widget.Panel("panel",{width:containerWidth,height:panelHeight,visible:false,fixedcenter:true,zindex:Thoughtmuse.Graphics.OVERLAY_Z_INDEX,constraintoviewport:true});this.simplePanel.setHeader(header);this.simplePanel.setBody(content);this.simplePanel.setFooter(footer);this.simplePanel.render($("#workspace")[0]);this.simplePanel.show();},simpleDialog:null,showSimpleDialog:function(header,content,okBtnText,cancelBtnText,okHandler,cancelHandler,dialogWidth,dialogHeight){var handleYes=function(){okHandler();this.hide();};var handleNo=function(){cancelHandler();this.hide();};var containerWidth="300px";if(dialogWidth){containerWidth=dialogWidth;}
this.simpleDialog=new YAHOO.widget.SimpleDialog("simpleDialog",{width:containerWidth,height:dialogHeight,fixedcenter:true,visible:false,draggable:false,close:true,text:content,zindex:Thoughtmuse.Graphics.OVERLAY_Z_INDEX,constraintoviewport:true,buttons:[{text:okBtnText,handler:handleYes,isDefault:true},{text:cancelBtnText,handler:handleNo}]});this.simpleDialog.setHeader(header);this.simpleDialog.render($("#workspace")[0]);this.simpleDialog.show();},showContentInNewWindow:function(content){var generator=window.open('','name','height=600,width=800');generator.document.write(content);generator.document.close();},openUrlInNewWindow:function(url){window.open(url,'','height=600,width=800');},overlay:null,showOverlay:function(header,footer,content,width){this.overlay=new YAHOO.widget.Overlay("overlay",{zindex:Thoughtmuse.Graphics.OVERLAY_Z_INDEX,visible:true,width:width+"px",constraintoviewport:true,context:["header","tr","tr"]});this.overlay.setHeader(header);this.overlay.setBody(content);this.overlay.setFooter(footer);this.overlay.render(document.body);this.overlay.show();var draggable=new YAHOO.util.DD("overlay");},hideOverlay:function(){this.overlay.hide();},setOverlayContent:function(content,header,footer){this.overlay.setBody(content);this.overlay.setHeader(header);this.overlay.setFooter(footer);}};Thoughtmuse.Tutorial={lessonProgression:0,started:false,getLessonAtIndex:function(index){var counter=0;for(var lessonName in this.Lessons){if(this.Lessons.hasOwnProperty(lessonName)){if(counter===index){return this.Lessons[lessonName];}
counter++;}}
throw"No such tutorial lesson!";},getIndexOfLesson:function(desiredLesson){var counter=0;for(var lessonName in this.Lessons){if(this.Lessons.hasOwnProperty(lessonName)){if(this.Lessons[lessonName]===desiredLesson){return counter;}
counter++;}}
throw"No such tutorial lesson!";},getLessonsLength:function(){var counter=0;for(var lesson in this.Lessons){if(this.Lessons.hasOwnProperty(lesson)){counter++;}}
return counter;},start:function(){this.started=true;Thoughtmuse.Widgets.showOverlay("Tutorial","","",500);this.lessonProgression=0;this.showLesson();},restart:function(){this.start();},end:function(){Thoughtmuse.Widgets.hideOverlay();this.started=false;},nextLesson:function(){if((this.lessonProgression+1)<this.getLessonsLength()&&this.started){this.lessonProgression++;this.showLesson();}},previousLesson:function(){if(this.lessonProgression>0&&this.started){this.lessonProgression--;this.showLesson();}},completeLesson:function(lessonName){var lessonIndex=this.getIndexOfLesson(lessonName);if(this.lessonProgression===lessonIndex){this.nextLesson();}},goStraightToEndOfLesson:function(lessonName){var lessonIndex=this.getIndexOfLesson(lessonName);this.lessonProgression=lessonIndex;this.nextLesson();},tutorialOverlayMarkup:"",showLesson:function(){var header="<div id='tutorialFooter'><p><h3>ThoughtMuse Tutorial Lesson # "+(this.lessonProgression+1)+"</h3></p></div>";var msg="<div id='tutorialMessage'><p>"+this.getLessonAtIndex(this.lessonProgression)+"</p></div>";var endButtonMarkup="<div id='tutorialHeader' class='rightAligned'>";if(this.lessonProgression>0){endButtonMarkup+="<input type='submit' value='Back' onClick='Thoughtmuse.Tutorial.previousLesson();' />";}
endButtonMarkup+="<input type='submit' value='End'  onClick='Thoughtmuse.Tutorial.end();' />";if(this.lessonProgression<(this.getLessonsLength()-1)){endButtonMarkup+="<input type='submit' value='Next' onClick='Thoughtmuse.Tutorial.nextLesson();' />";}
endButtonMarkup+="</div>";var footer=endButtonMarkup;Thoughtmuse.Widgets.setOverlayContent(msg,header,footer);}};Thoughtmuse.Tutorial.Lessons={INTRO:"<p>Welcome!</p> <p>This is a short interactive tutorial which will introduce you to the basics of the ThoughtMuse mindmap editor.</p>  <p>Tutorial lessons progress by performing actions described. You can also skip back and forth in the lessons by using the buttons in this box. Click, hold and drag this box if it gets in the way.</p> <p>Try clicking 'next' right now to skip ahead to the next lesson.</p>",CREATE_NEW_MINDMAP:"Let's start by creating a new mindmap. Click 'File' in the menu bar, then 'New'. For now, select the <em>'(Empty)'</em> mindmap template.",SELECT_ELEMENT:"This is the start of a new mindmap. Think of it as a tree growing sideways. The text element on the far left is the 'root' of the tree. The other text elements are its children. We are basically going to create leaves and branches of text. <p>Let's start by selecting one of the text elements. Click any of them.</p>",EDIT_TEXT:"Good. See how that text changed appearance? That means it's selected. Let's change the text in that element now. <p>Simply start typing text. You can also click 'Edit->Edit text' in the top menu, which has the same effect. Hit return once you've finished writing.</p>",CREATE_SIBLING:"Now, let's create another text element. <p>Right-click any text element in the mindmap. Then select 'New sibling'.</p>",CREATE_CHILD:"See how a new element appeared below right now? <p>They both have the same 'parent', so we'll call them siblings! Now let's create a child, too.</p> <p>Right-click one of the elements, select 'New child'.</p> ",CREATE_CHILD_USING_HOTKEY:"You can keep creating deeper and deeper branches and lists this way. This is very useful for editing hierarchies of information, like an organization chart or ideas within ideas during brainstorming sessions. <p>You can use keyboard shortcuts to speed this process up. Select a text element by left-clicking it. The return key will then create a sibling, tab or insert creates a child. Try creating a child by pressing the tab or insert key.</p>",UNDO:"You can of course undo changes at any point. Click 'Edit' in the top menu, then select 'Undo'. Or just use the hotkey shortcut: CTRL+Z. Go on, try an 'Undo'.",SET_BOLD:"Just like a regular text document, you will want to apply styling to your elements to make your mindmap more readable and appealing. <p>Let's try that now. Right click a node, select 'bold'.</p> ",MULTIPLE_SELECTION:"<p>As your mindmap gets larger you'll find it tedious to edit each node on its own. It would be nice to change several texts at once, right?</p> <p>No problem! Press and hold the shift key, then left click a few texts.</p>",SET_MULTIPLE_ITALIC:"Now, let's set all the selected elements as italic text style. Click 'Format' in the menu bar, then select 'Italic'",DRAG_AND_DROP:"You can also reorganize elements by dragging them to other places in the mindmap. This makes it very easy to sort information and quickly shift things around. <p>Try to click, hold and drag any one of the selected elements to other elements in the mindmap. They will snap into the side, top or bottom of the destination element. <p>This also works for mulitple selected elements: drag one of the selected and all will follow.</p> ",CONCLUSION:"Neat, eh? This was just a quick tour of some things you are able to do in the mindmap editor. Play around with it yourself. Experiment! <p>Oh, and remember: if you haven't registered yet, you'll need to do so to save your work or publish it online for others to see.</p> <p>Have fun!</p> <p><em>See the <a href='/help'>tutorials</a> for articles and videos with more tips and tricks</em></p>"};Thoughtmuse.Init={initEditorWindow:function(){var readOnly=$("#init_load_map_readonly").html();var loadedMapName=$("#init_load_map_name").html();var loadedTemplateName=$("#init_load_template_name").html();var loadedMapOwner=$("#init_load_map_owner_login").html();var startTutorial=$("#start_tutorial").html();var userLoggedIn=$("#user_logged_in").html();if(userLoggedIn==="true"){Thoughtmuse.GlobalState.userLoggedIn=true;}
if(loadedMapName){if(readOnly){Thoughtmuse.GraphAPI.Operations.loadPublishedFromServer(loadedMapName,loadedMapOwner,function(){Thoughtmuse.Graphics.workspaceEffectFadeInShow();});}
else{Thoughtmuse.GraphAPI.Operations.loadFromServer(loadedMapName,function(){Thoughtmuse.Graphics.workspaceEffectFadeInShow();});}}
else if(loadedTemplateName){Thoughtmuse.GraphAPI.Operations.loadTemplateFromServer(loadedTemplateName,function(){Thoughtmuse.Graphics.workspaceEffectFadeInShow();});if(startTutorial){Thoughtmuse.Tutorial.start();Thoughtmuse.Tutorial.goStraightToEndOfLesson(Thoughtmuse.Tutorial.Lessons.CREATE_NEW_MINDMAP);}}
else{if(startTutorial){Thoughtmuse.Tutorial.start();}
else{Thoughtmuse.Operations.toggleFileOpenOrTutorialIfNoFilesSaved();}}
if(!readOnly){Thoughtmuse.Widgets.initMenuToolbar();}
Thoughtmuse.Input.initGlobalInput();}};