//
// ChemDoodle Web Components 4.6.0
//
// http://web.chemdoodle.com
//
// Copyright 2009 iChemLabs, LLC.  All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// As a special exception to the GPL, any HTML file in a public website
// or any free web service which merely makes function calls to this
// code, and for that purpose includes it by reference, shall be deemed
// a separate work for copyright law purposes. If you modify this code,
// you may extend this exception to your version of the code, but you
// are not obligated to do so. If you do not wish to do so, delete this
// exception statement from your version.
//
// As an additional exception to the GPL, you may distribute this
// packed form of the code without the copy of the GPL license normally
// required, provided you include this license notice and a URL through
// which recipients can access the corresponding unpacked source code.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// Please contact iChemLabs <http://www.ichemlabs.com/contact> for
// alternate licensing options.
//
ChemDoodle.sketcher=function(){var e={};e.actions={};e.gui={};e.gui.desktop={};e.gui.mobile={};e.states={};return e}();(function(e){e._Action=function(){this.forward=function(g){this.innerForward();this.checks(g)};this.reverse=function(g){this.innerReverse();this.checks(g)};this.checks=function(g){g.molecule.check();g.repaint()};return true}})(ChemDoodle.sketcher.actions);
(function(e,g){e.AddAction=function(i,c,d){this.mol=i;this.as=c;this.bs=d;return true};e.AddAction.prototype=new e._Action;e.AddAction.prototype.innerForward=function(){if(this.as!=null)for(var i=0,c=this.as.length;i<c;i++)this.mol.atoms.push(this.as[i]);if(this.bs!=null){i=0;for(c=this.bs.length;i<c;i++)this.mol.bonds.push(this.bs[i])}};e.AddAction.prototype.innerReverse=function(){if(this.as!=null){for(var i=[],c=0,d=this.mol.atoms.length;c<d;c++)g(this.mol.atoms[c],this.as)==-1&&i.push(this.mol.atoms[c]);
this.mol.atoms=i}if(this.bs!=null){i=[];c=0;for(d=this.mol.bonds.length;c<d;c++)g(this.mol.bonds[c],this.bs)==-1&&i.push(this.mol.bonds[c]);this.mol.bonds=i}}})(ChemDoodle.sketcher.actions,jQuery.inArray);
(function(e,g){e.ChangeBondAction=function(i,c,d){this.b=i;this.orderBefore=i.bondOrder;this.stereoBefore=i.stereo;if(c){this.orderAfter=c;this.stereoAfter=d}else{this.orderAfter=i.bondOrder+1;if(this.orderAfter>3)this.orderAfter=1;this.stereoAfter=g.STEREO_NONE}return true};e.ChangeBondAction.prototype=new e._Action;e.ChangeBondAction.prototype.innerForward=function(){this.b.bondOrder=this.orderAfter;this.b.stereo=this.stereoAfter};e.ChangeBondAction.prototype.innerReverse=function(){this.b.bondOrder=
this.orderBefore;this.b.stereo=this.stereoBefore}})(ChemDoodle.sketcher.actions,ChemDoodle.structures.Bond);(function(e){e.ChangeChargeAction=function(g,i){this.a=g;this.delta=i;return true};e.ChangeChargeAction.prototype=new e._Action;e.ChangeChargeAction.prototype.innerForward=function(){this.a.charge+=this.delta};e.ChangeChargeAction.prototype.innerReverse=function(){this.a.charge-=this.delta}})(ChemDoodle.sketcher.actions);
(function(e){e.ChangeCoordinatesAction=function(g,i){this.as=g;this.recs=[];for(var c=0,d=this.as.length;c<d;c++)this.recs[c]={xo:this.as[c].x,yo:this.as[c].y,xn:i[c].x,yn:i[c].y};return true};e.ChangeCoordinatesAction.prototype=new e._Action;e.ChangeCoordinatesAction.prototype.innerForward=function(){for(var g=0,i=this.as.length;g<i;g++){this.as[g].x=this.recs[g].xn;this.as[g].y=this.recs[g].yn}};e.ChangeCoordinatesAction.prototype.innerReverse=function(){for(var g=0,i=this.as.length;g<i;g++){this.as[g].x=
this.recs[g].xo;this.as[g].y=this.recs[g].yo}}})(ChemDoodle.sketcher.actions);(function(e){e.ChangeLabelAction=function(g,i){this.a=g;this.before=g.label;this.after=i;return true};e.ChangeLabelAction.prototype=new e._Action;e.ChangeLabelAction.prototype.innerForward=function(){this.a.label=this.after};e.ChangeLabelAction.prototype.innerReverse=function(){this.a.label=this.before}})(ChemDoodle.sketcher.actions);
(function(e){e.ChangeLonePairAction=function(g,i){this.a=g;this.delta=i;return true};e.ChangeLonePairAction.prototype=new e._Action;e.ChangeLonePairAction.prototype.innerForward=function(){this.a.numLonePair+=this.delta};e.ChangeLonePairAction.prototype.innerReverse=function(){this.a.numLonePair-=this.delta}})(ChemDoodle.sketcher.actions);
(function(e){e.ClearAction=function(g){this.sketcher=g;this.before=this.sketcher.getMolecule();this.sketcher.clear();this.after=this.sketcher.getMolecule();return true};e.ClearAction.prototype=new e._Action;e.ClearAction.prototype.innerForward=function(){this.sketcher.molecule=this.after};e.ClearAction.prototype.innerReverse=function(){this.sketcher.molecule=this.before}})(ChemDoodle.sketcher.actions);
(function(e){e.DeleteAction=function(g,i,c){this.mol=g;this.as=i;this.bs=c;return true};e.DeleteAction.prototype=new e._Action;e.DeleteAction.prototype.innerForward=e.AddAction.prototype.innerReverse;e.DeleteAction.prototype.innerReverse=e.AddAction.prototype.innerForward})(ChemDoodle.sketcher.actions);
(function(e){e.FlipBondAction=function(g){this.b=g;return true};e.FlipBondAction.prototype=new e._Action;e.FlipBondAction.prototype.innerForward=function(){var g=this.b.a1;this.b.a1=this.b.a2;this.b.a2=g};e.FlipBondAction.prototype.innerReverse=function(){this.innerForward()}})(ChemDoodle.sketcher.actions);
(function(e){e.MoveAction=function(g,i){this.as=g;this.dif=i;return true};e.MoveAction.prototype=new e._Action;e.MoveAction.prototype.innerForward=function(){for(var g=0,i=this.as.length;g<i;g++)this.as[g].add(this.dif)};e.MoveAction.prototype.innerReverse=function(){for(var g=0,i=this.as.length;g<i;g++)this.as[g].sub(this.dif)}})(ChemDoodle.sketcher.actions);
(function(e,g){e.RotateAction=function(i,c,d){this.as=i;this.dif=c;this.center=d;return true};e.RotateAction.prototype=new e._Action;e.RotateAction.prototype.innerForward=function(){for(var i=0,c=this.as.length;i<c;i++){var d=this.center.distance(this.as[i]),h=this.center.angle(this.as[i])+this.dif;this.as[i].x=this.center.x+d*g.cos(h);this.as[i].y=this.center.y-d*g.sin(h)}};e.RotateAction.prototype.innerReverse=function(){for(var i=0,c=this.as.length;i<c;i++){var d=this.center.distance(this.as[i]),
h=this.center.angle(this.as[i])-this.dif;this.as[i].x=this.center.x+d*g.cos(h);this.as[i].y=this.center.y-d*g.sin(h)}}})(ChemDoodle.sketcher.actions,Math);
(function(e){e.SwitchMoleculeAction=function(g,i){this.sketcher=g;this.molB=g.molecule;this.molA=i;return true};e.SwitchMoleculeAction.prototype=new e._Action;e.SwitchMoleculeAction.prototype.innerForward=function(){this.sketcher.loadMolecule(this.molA)};e.SwitchMoleculeAction.prototype.innerReverse=function(){this.sketcher.molecule=this.molB}})(ChemDoodle.sketcher.actions,jQuery.inArray);
(function(e){e.HistoryManager=function(g){this.sketcher=g;this.undoStack=[];this.redoStack=[];return true};e.HistoryManager.prototype.undo=function(){if(this.undoStack.length!=0){var g=this.undoStack.pop();g.reverse(this.sketcher);this.redoStack.push(g);this.undoStack.length==0&&this.sketcher.toolbarManager.buttonUndo.disable();this.sketcher.toolbarManager.buttonRedo.enable()}};e.HistoryManager.prototype.redo=function(){if(this.redoStack.length!=0){var g=this.redoStack.pop();g.forward(this.sketcher);
this.undoStack.push(g);this.sketcher.toolbarManager.buttonUndo.enable();this.redoStack.length==0&&this.sketcher.toolbarManager.buttonRedo.disable()}};e.HistoryManager.prototype.pushUndo=function(g){g.forward(this.sketcher);this.undoStack.push(g);if(this.redoStack.length!=0)this.redoStack=[];this.sketcher.toolbarManager.buttonUndo.enable();this.sketcher.toolbarManager.buttonRedo.disable()};e.HistoryManager.prototype.clear=function(){if(this.undoStack.length!=0){this.undoStack=[];this.sketcher.toolbarManager.buttonUndo.disable()}if(this.redoStack.length!=
0){this.redoStack=[];this.sketcher.toolbarManager.buttonRedo.disable()}}})(ChemDoodle.sketcher.actions);
(function(e,g,i,c,d,h,n,b){c._State=function(){return true};c._State.prototype.setup=function(f){this.sketcher=f};c._State.prototype.bondExists=function(f,a){for(var j=0,m=this.sketcher.molecule.bonds.length;j<m;j++)if(this.sketcher.molecule.bonds[j].contains(f)&&this.sketcher.molecule.bonds[j].contains(a))return true;return false};c._State.prototype.getBond=function(f,a){for(var j=0,m=this.sketcher.molecule.bonds.length;j<m;j++)if(this.sketcher.molecule.bonds[j].contains(f)&&this.sketcher.molecule.bonds[j].contains(a))return this.sketcher.molecule.bonds[j];
return null};c._State.prototype.clearHover=function(){if(this.sketcher.hovering!=null){this.sketcher.hovering.isHover=false;this.sketcher.hovering.isSelected=false}this.sketcher.hovering=null};c._State.prototype.findHoveredObject=function(f,a,j){this.clearHover();var m=Infinity,l=null;if(a){a=0;for(var k=this.sketcher.molecule.atoms.length;a<k;a++){this.sketcher.molecule.atoms[a].isHover=false;var o=f.p.distance(this.sketcher.molecule.atoms[a]);if(o<this.sketcher.specs.bondLength&&o<m){m=o;l=this.sketcher.molecule.atoms[a]}}}if(j){a=
0;for(k=this.sketcher.molecule.bonds.length;a<k;a++){this.sketcher.molecule.bonds[a].isHover=false;o=f.p.distance(this.sketcher.molecule.bonds[a].getCenter());if(o<this.sketcher.specs.bondLength&&o<m){m=o;l=this.sketcher.molecule.bonds[a]}}}if(l!=null){l.isHover=true;this.sketcher.hovering=l}};c._State.prototype.getOptimumAngle=function(f){f=this.sketcher.molecule.getAngles(f);var a=0;if(f.length==0)a=b.PI/6;else if(f.length==1){a=null;for(var j=0,m=this.sketcher.molecule.bonds.length;j<m;j++)if(this.sketcher.molecule.bonds[j].contains(this.sketcher.hovering))a=
this.sketcher.molecule.bonds[j];if(a.bondOrder>=3)a=f[0]+b.PI;else{a=f[0]%b.PI*2;a=e.isBetween(a,0,b.PI/2)||e.isBetween(a,b.PI,3*b.PI/2)?f[0]+2*b.PI/3:f[0]-2*b.PI/3}}else a=e.angleBetweenLargest(f).angle;return a};c._State.prototype.click=function(f){this.innerclick&&this.innerclick(f)};c._State.prototype.rightclick=function(f){this.innerrightclick&&this.innerrightclick(f)};c._State.prototype.dblclick=function(f){this.innerdblclick&&this.innerdblclick(f);if(this.sketcher.hovering==null){f=new d.Point(this.sketcher.width/
2,this.sketcher.height/2);f.sub(this.sketcher.molecule.getCenter());this.sketcher.historyManager.pushUndo(new i.MoveAction(this.sketcher.molecule.atoms,f))}};c._State.prototype.mousedown=function(f){this.sketcher.lastPoint=f.p;if(this.sketcher.isHelp||this.sketcher.isMobile&&f.op.distance(this.sketcher.helpPos)<10){this.sketcher.isHelp=false;this.sketcher.repaint();window.open("http://web.chemdoodle.com/sketcher")}else this.innermousedown&&this.innermousedown(f)};c._State.prototype.rightmousedown=
function(f){this.innerrightmousedown&&this.innerrightmousedown(f)};c._State.prototype.mousemove=function(f){this.innermousemove&&this.innermousemove(f);this.sketcher.repaint()};c._State.prototype.mouseout=function(f){this.innermouseout&&this.innermouseout(f)};c._State.prototype.mouseover=function(f){this.innermouseover&&this.innermouseover(f)};c._State.prototype.mouseup=function(f){this.parentAction=null;this.innermouseup&&this.innermouseup(f)};c._State.prototype.rightmouseup=function(f){this.innerrightmouseup&&
this.innerrightmouseup(f)};c._State.prototype.mousewheel=function(f,a){this.innermousewheel&&this.innermousewheel(f);this.sketcher.specs.scale+=a/10;this.sketcher.checkScale();this.sketcher.repaint()};c._State.prototype.drag=function(f){this.innerdrag&&this.innerdrag(f);if(this.sketcher.hovering==null){if(g.SHIFT){var a=new d.Point(this.sketcher.width/2,this.sketcher.height/2),j=a.angle(this.sketcher.lastPoint),m=a.angle(f.p)-j;if(this.parentAction==null){this.parentAction=new i.RotateAction(this.sketcher.molecule.atoms,
m,a);this.sketcher.historyManager.pushUndo(this.parentAction)}else{this.parentAction.dif+=m;j=0;for(var l=this.sketcher.molecule.atoms.length;j<l;j++){var k=a.distance(this.sketcher.molecule.atoms[j]),o=a.angle(this.sketcher.molecule.atoms[j])+m;this.sketcher.molecule.atoms[j].x=a.x+k*b.cos(o);this.sketcher.molecule.atoms[j].y=a.y-k*b.sin(o)}this.sketcher.molecule.check()}}else{if(!this.sketcher.lastPoint)return;a=new d.Point(f.p.x,f.p.y);a.sub(this.sketcher.lastPoint);if(this.parentAction==null){this.parentAction=
new i.MoveAction(this.sketcher.molecule.atoms,a);this.sketcher.historyManager.pushUndo(this.parentAction)}else{this.parentAction.dif.add(a);j=0;for(l=this.sketcher.molecule.atoms.length;j<l;j++)this.sketcher.molecule.atoms[j].add(a);this.sketcher.molecule.check()}}this.sketcher.repaint()}this.sketcher.lastPoint=f.p};c._State.prototype.keydown=function(f){if(g.CANVAS_DRAGGING==this.sketcher){if(this.sketcher.lastPoint!=null){f.p=this.sketcher.lastPoint;this.drag(f)}}else if(g.META)if(f.which==90)this.sketcher.historyManager.undo();
else if(f.which==89)this.sketcher.historyManager.redo();else if(f.which==83)this.sketcher.toolbarManager.buttonSave.getElement().click();else if(f.which==79)this.sketcher.toolbarManager.buttonOpen.getElement().click();else if(f.which==78)this.sketcher.toolbarManager.buttonClear.getElement().click();else if(f.which==187||f.which==61)this.sketcher.toolbarManager.buttonScalePlus.getElement().click();else{if(f.which==189||f.which==109)this.sketcher.toolbarManager.buttonScaleMinus.getElement().click()}else if(f.which>=
37&&f.which<=40){var a=new d.Point;switch(f.which){case 37:a.x=-10;break;case 38:a.y=-10;break;case 39:a.x=10;break;case 40:a.y=10;break}this.sketcher.historyManager.pushUndo(new i.MoveAction(this.sketcher.molecule.atoms,a))}else if(f.which==187||f.which==189||f.which==61||f.which==109){if(this.sketcher.hovering!=null&&this.sketcher.hovering instanceof d.Atom)this.sketcher.historyManager.pushUndo(new i.ChangeChargeAction(this.sketcher.hovering,f.which==187||f.which==61?1:-1))}else if(f.which==8||
f.which==127)this.sketcher.stateManager.STATE_ERASE.handleDelete();else if(f.which>=48&&f.which<=57){if(this.sketcher.hovering!=null){var j=f.which-48;a=[];var m=[];if(this.sketcher.hovering instanceof d.Atom)if(g.SHIFT){if(j>2&&j<9){var l=this.sketcher.molecule.getAngles(this.sketcher.hovering),k=3*b.PI/2;if(l.length!=0)k=e.angleBetweenLargest(l).angle;k=this.sketcher.stateManager.STATE_NEW_RING.getRing(this.sketcher.hovering,j,this.sketcher.specs.bondLength,k,false);n(k[0],this.sketcher.molecule.atoms)==
-1&&a.push(k[0]);this.bondExists(this.sketcher.hovering,k[0])||m.push(new d.Bond(this.sketcher.hovering,k[0]));l=1;for(j=k.length;l<j;l++){n(k[l],this.sketcher.molecule.atoms)==-1&&a.push(k[l]);this.bondExists(k[l-1],k[l])||m.push(new d.Bond(k[l-1],k[l]))}this.bondExists(k[k.length-1],this.sketcher.hovering)||m.push(new d.Bond(k[k.length-1],this.sketcher.hovering))}}else{if(j==0)j=10;var o=new d.Point(this.sketcher.hovering.x,this.sketcher.hovering.y),p=this.getOptimumAngle(this.sketcher.hovering),
t=this.sketcher.hovering;for(l=0;l<j;l++){k=p+(l%2==1?b.PI/3:0);o.x+=this.sketcher.specs.bondLength*b.cos(k);o.y-=this.sketcher.specs.bondLength*b.sin(k);var q=new d.Atom("C",o.x,o.y),s=Infinity,u=null;k=0;for(var r=this.sketcher.molecule.atoms.length;k<r;k++){var v=this.sketcher.molecule.atoms[k].distance(q);if(v<s){s=v;u=this.sketcher.molecule.atoms[k]}}if(s<5)q=u;else a.push(q);this.bondExists(t,q)||m.push(new d.Bond(t,q));t=q}}else if(this.sketcher.hovering instanceof d.Bond)if(g.SHIFT){if(j>
2&&j<9){k=this.sketcher.stateManager.STATE_NEW_RING.getOptimalRing(this.sketcher.hovering,j);l=this.sketcher.hovering.a2;r=this.sketcher.hovering.a1;if(k[0]==this.sketcher.hovering.a1){l=this.sketcher.hovering.a1;r=this.sketcher.hovering.a2}n(k[1],this.sketcher.molecule.atoms)==-1&&a.push(k[1]);this.bondExists(l,k[1])||m.push(new d.Bond(l,k[1]));l=2;for(j=k.length;l<j;l++){n(k[l],this.sketcher.molecule.atoms)==-1&&a.push(k[l]);this.bondExists(k[l-1],k[l])||m.push(new d.Bond(k[l-1],k[l]))}this.bondExists(k[k.length-
1],r)||m.push(new d.Bond(k[k.length-1],r))}}else j>0&&j<4&&this.sketcher.historyManager.pushUndo(new i.ChangeBondAction(this.sketcher.hovering,j,d.Bond.STEREO_NONE));if(a.length!=0||m.length!=0)this.sketcher.historyManager.pushUndo(new i.AddAction(this.sketcher.molecule,a,m))}}else if(f.which>=65&&f.which<=90)if(this.sketcher.hovering!=null)if(this.sketcher.hovering instanceof d.Atom){l=String.fromCharCode(f.which);m=a=null;j=false;k=0;for(r=h.length;k<r;k++)if(this.sketcher.hovering.label.charAt(0)==
l)if(h[k]==this.sketcher.hovering.label)j=true;else{if(h[k].charAt(0)==l)if(j&&m==null)m=h[k];else if(a==null)a=h[k]}else if(h[k].charAt(0)==l){a=h[k];break}q="C";if(m!=null)q=m;else if(a!=null)q=a;this.sketcher.historyManager.pushUndo(new i.ChangeLabelAction(this.sketcher.hovering,q))}else this.sketcher.hovering instanceof d.Bond&&f.which==70&&this.sketcher.historyManager.pushUndo(new i.FlipBondAction(this.sketcher.hovering));this.innerkeydown&&this.innerkeydown(f)};c._State.prototype.keypress=function(f){this.innerkeypress&&
this.innerkeypress(f)};c._State.prototype.keyup=function(f){if(g.CANVAS_DRAGGING==this.sketcher)if(this.sketcher.lastPoint!=null){f.p=this.sketcher.lastPoint;this.sketcher.drag(f)}this.innerkeyup&&this.innerkeyup(f)}})(ChemDoodle.math,ChemDoodle.monitor,ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states,ChemDoodle.structures,ChemDoodle.SYMBOLS,jQuery.inArray,Math);
(function(e,g){g.ChargeState=function(i){this.setup(i);this.delta=1;return true};g.ChargeState.prototype=new g._State;g.ChargeState.prototype.innermouseup=function(){this.sketcher.hovering!=null&&this.sketcher.historyManager.pushUndo(new e.ChangeChargeAction(this.sketcher.hovering,this.delta))};g.ChargeState.prototype.innermousemove=function(i){this.findHoveredObject(i,true,false)}})(ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states);
(function(e,g,i,c){g.EraseState=function(d){this.setup(d);return true};g.EraseState.prototype=new g._State;g.EraseState.prototype.handleDelete=function(){if(this.sketcher.hovering!=null){if(this.sketcher.hovering instanceof i.Atom){for(var d=0,h=this.sketcher.molecule.atoms.length;d<h;d++)this.sketcher.molecule.atoms[d].visited=false;var n=[],b=[];this.sketcher.hovering.visited=true;d=0;for(h=this.sketcher.molecule.bonds.length;d<h;d++)if(this.sketcher.molecule.bonds[d].contains(this.sketcher.hovering)){var f=
[],a=[],j=new i.Queue;for(j.enqueue(this.sketcher.molecule.bonds[d].getNeighbor(this.sketcher.hovering));!j.isEmpty();){var m=j.dequeue();if(!m.visited){m.visited=true;f.push(m);for(var l=0,k=this.sketcher.molecule.bonds.length;l<k;l++)if(this.sketcher.molecule.bonds[l].contains(m)&&!this.sketcher.molecule.bonds[l].getNeighbor(m).visited){j.enqueue(this.sketcher.molecule.bonds[l].getNeighbor(m));a.push(this.sketcher.molecule.bonds[l])}}}n.push(f);b.push(a)}f=a=-1;d=0;for(h=n.length;d<h;d++)if(n[d].length>
a){f=d;a=n[d].length}if(f>-1){d=[];h=[];a=0;for(j=this.sketcher.molecule.atoms.length;a<j;a++)c(this.sketcher.molecule.atoms[a],n[f])==-1&&d.push(this.sketcher.molecule.atoms[a]);a=0;for(j=this.sketcher.molecule.bonds.length;a<j;a++)c(this.sketcher.molecule.bonds[a],b[f])==-1&&h.push(this.sketcher.molecule.bonds[a]);this.sketcher.historyManager.pushUndo(new e.DeleteAction(this.sketcher.molecule,d,h))}else this.sketcher.historyManager.pushUndo(new e.ClearAction(this.sketcher))}else if(this.sketcher.hovering instanceof
i.Bond)if(this.sketcher.hovering.ring!=null){h=[];h[0]=this.sketcher.hovering;this.sketcher.historyManager.pushUndo(new e.DeleteAction(this.sketcher.molecule,null,h))}this.sketcher.repaint()}};g.EraseState.prototype.innermouseup=function(){this.handleDelete()};g.EraseState.prototype.innermousemove=function(d){this.findHoveredObject(d,true,true)}})(ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states,ChemDoodle.structures,jQuery.inArray);
(function(e,g){g.LabelState=function(i){this.setup(i);this.label="C";return true};g.LabelState.prototype=new g._State;g.LabelState.prototype.innermouseup=function(){this.sketcher.hovering!=null&&this.sketcher.historyManager.pushUndo(new e.ChangeLabelAction(this.sketcher.hovering,this.label))};g.LabelState.prototype.innermousemove=function(i){this.findHoveredObject(i,true,false)}})(ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states);
(function(e,g){g.LonePairState=function(i){this.setup(i);this.delta=1;return true};g.LonePairState.prototype=new g._State;g.LonePairState.prototype.innermouseup=function(){this.delta<0&&this.sketcher.hovering.numLonePair<1||this.sketcher.hovering!=null&&this.sketcher.historyManager.pushUndo(new e.ChangeLonePairAction(this.sketcher.hovering,this.delta))};g.LonePairState.prototype.innermousemove=function(i){this.findHoveredObject(i,true,false)}})(ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states);
(function(e,g,i){g.MoveState=function(c){this.setup(c);this.action=null;return true};g.MoveState.prototype=new g._State;g.MoveState.prototype.innerdrag=function(c){if(this.sketcher.hovering!=null)if(this.action==null){var d=[];c=new i.Point(c.p.x,c.p.y);if(this.sketcher.hovering instanceof i.Atom){c.sub(this.sketcher.hovering);d[0]=this.sketcher.hovering}else if(this.sketcher.hovering instanceof i.Bond){c.sub(this.sketcher.lastPoint);d[0]=this.sketcher.hovering.a1;d[1]=this.sketcher.hovering.a2}this.action=
new e.MoveAction(d,c);this.sketcher.historyManager.pushUndo(this.action)}else{c=new i.Point(c.p.x,c.p.y);c.sub(this.sketcher.lastPoint);this.action.dif.add(c);d=0;for(var h=this.action.as.length;d<h;d++)this.action.as[d].add(c);this.sketcher.molecule.check();this.sketcher.repaint()}};g.MoveState.prototype.innermousemove=function(c){this.findHoveredObject(c,true,true)};g.MoveState.prototype.innermouseup=function(){this.action=null}})(ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states,ChemDoodle.structures);
(function(e,g,i,c,d){i.NewBondState=function(h){this.setup(h);this.bondOrder=1;this.stereo=c.Bond.STEREO_NONE;return true};i.NewBondState.prototype=new i._State;i.NewBondState.prototype.incrementBondOrder=function(h){if(this.bondOrder==1&&this.stereo==c.Bond.STEREO_NONE)this.sketcher.historyManager.pushUndo(new g.ChangeBondAction(h));else if(h.bondOrder==this.bondOrder&&h.stereo==this.stereo){if(h.bondOrder==1&&h.stereo!=c.Bond.STEREO_NONE||h.bondOrder==2&&h.stereo==c.Bond.STEREO_NONE)this.sketcher.historyManager.pushUndo(new g.FlipBondAction(h))}else this.sketcher.historyManager.pushUndo(new g.ChangeBondAction(h,
this.bondOrder,this.stereo))};i.NewBondState.prototype.innerdrag=function(h){if(this.sketcher.hovering instanceof c.Atom){if(h.p.distance(this.sketcher.hovering)<15){var n=this.getOptimumAngle(this.sketcher.hovering);h=this.sketcher.hovering.x+this.sketcher.specs.bondLength*d.cos(n);n=this.sketcher.hovering.y-this.sketcher.specs.bondLength*d.sin(n);this.sketcher.tempAtom=new c.Atom("C",h,n,0)}else if(e.ALT&&e.SHIFT)this.sketcher.tempAtom=new c.Atom("C",h.p.x,h.p.y,0);else{n=this.sketcher.hovering.angle(h.p);
h=this.sketcher.hovering.distance(h.p);if(!e.SHIFT)h=this.sketcher.specs.bondLength;e.ALT||(n=d.floor((n+d.PI/12)/(d.PI/6))*d.PI/6);this.sketcher.tempAtom=new c.Atom("C",this.sketcher.hovering.x+h*d.cos(n),this.sketcher.hovering.y-h*d.sin(n),0)}n=0;for(h=this.sketcher.molecule.atoms.length;n<h;n++)if(this.sketcher.molecule.atoms[n].distance(this.sketcher.tempAtom)<5){this.sketcher.tempAtom.x=this.sketcher.molecule.atoms[n].x;this.sketcher.tempAtom.y=this.sketcher.molecule.atoms[n].y;this.sketcher.tempAtom.isOverlap=
true}this.sketcher.repaint()}};i.NewBondState.prototype.innermousedown=function(h){if(this.sketcher.hovering instanceof c.Atom){this.sketcher.hovering.isHover=false;this.sketcher.hovering.isSelected=true;this.drag(h)}else if(this.sketcher.hovering instanceof c.Bond){this.sketcher.hovering.isHover=false;this.incrementBondOrder(this.sketcher.hovering);this.sketcher.molecule.check();this.sketcher.repaint()}};i.NewBondState.prototype.innermouseup=function(h){if(this.sketcher.tempAtom!=null&&this.sketcher.hovering!=
null){var n=[],b=[],f=true;if(this.sketcher.tempAtom.isOverlap){for(var a=0,j=this.sketcher.molecule.atoms.length;a<j;a++)if(this.sketcher.molecule.atoms[a].distance(this.sketcher.tempAtom)<5)this.sketcher.tempAtom=this.sketcher.molecule.atoms[a];a=this.getBond(this.sketcher.hovering,this.sketcher.tempAtom);if(a!=null){this.incrementBondOrder(a);f=false}}else n.push(this.sketcher.tempAtom);if(f){b[0]=new c.Bond(this.sketcher.hovering,this.sketcher.tempAtom,this.bondOrder);b[0].stereo=this.stereo;
this.sketcher.historyManager.pushUndo(new g.AddAction(this.sketcher.molecule,n,b))}}this.sketcher.tempAtom=null;this.sketcher.isMobile||this.mousemove(h)};i.NewBondState.prototype.innermousemove=function(h){this.sketcher.tempAtom==null&&this.findHoveredObject(h,true,true)}})(ChemDoodle.monitor,ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states,ChemDoodle.structures,Math);
(function(e,g,i,c,d,h,n){c.NewRingState=function(b){this.setup(b);this.numSides=6;this.unsaturated=false;return true};c.NewRingState.prototype=new c._State;c.NewRingState.prototype.getRing=function(b,f,a,j,m){var l=n.PI-2*n.PI/f;j+=l/2;for(var k=[],o=0;o<f-1;o++){var p=o==0?new d.Atom("C",b.x,b.y):new d.Atom("C",k[k.length-1].x,k[k.length-1].y);p.x+=a*n.cos(j);p.y-=a*n.sin(j);k.push(p);j+=n.PI+l}b=0;for(f=this.sketcher.molecule.atoms.length;b<f;b++)this.sketcher.molecule.atoms[b].isOverlap=false;
o=0;for(a=k.length;o<a;o++){j=Infinity;l=null;b=0;for(f=this.sketcher.molecule.atoms.length;b<f;b++){p=this.sketcher.molecule.atoms[b].distance(k[o]);if(p<j){j=p;l=this.sketcher.molecule.atoms[b]}}if(j<5){k[o]=l;if(m)l.isOverlap=true}}return k};c.NewRingState.prototype.getOptimalRing=function(b,f){var a=n.PI/2-n.PI/f,j=b.a1.distance(b.a2),m=this.getRing(b.a1,f,j,b.a1.angle(b.a2)-a,false);a=this.getRing(b.a2,f,j,b.a2.angle(b.a1)-a,false);for(var l=j=0,k=1,o=m.length;k<o;k++)for(var p=0,t=this.sketcher.molecule.atoms.length;p<
t;p++){var q=this.sketcher.molecule.atoms[p].distance(m[k]),s=this.sketcher.molecule.atoms[p].distance(a[k]);j+=n.min(1E8,1/(q*q));l+=n.min(1E8,1/(s*s))}return j<l?m:a};c.NewRingState.prototype.innerdrag=function(b){if(this.sketcher.hovering instanceof d.Atom){var f=0,a=0;if(b.p.distance(this.sketcher.hovering)<15){b=this.sketcher.molecule.getAngles(this.sketcher.hovering);f=b.length==0?3*n.PI/2:e.angleBetweenLargest(b).angle;a=this.sketcher.specs.bondLength}else{f=this.sketcher.hovering.angle(b.p);
a=this.sketcher.hovering.distance(b.p);if(!(g.ALT&&g.SHIFT)){if(!g.SHIFT)a=this.sketcher.specs.bondLength;g.ALT||(f=n.floor((f+n.PI/12)/(n.PI/6))*n.PI/6)}}this.sketcher.tempRing=this.getRing(this.sketcher.hovering,this.numSides,a,f,true);this.sketcher.repaint()}else if(this.sketcher.hovering instanceof d.Bond){f=e.distanceFromPointToLineInclusive(b.p,this.sketcher.hovering.a1,this.sketcher.hovering.a2);a=null;if(f!=-1&&f<=7)a=this.getOptimalRing(this.sketcher.hovering,this.numSides);else{a=n.PI/2-
n.PI/this.numSides;var j=this.sketcher.hovering.a1.distance(this.sketcher.hovering.a2);f=this.getRing(this.sketcher.hovering.a1,this.numSides,j,this.sketcher.hovering.a1.angle(this.sketcher.hovering.a2)-a,false);a=this.getRing(this.sketcher.hovering.a2,this.numSides,j,this.sketcher.hovering.a2.angle(this.sketcher.hovering.a1)-a,false);var m=new d.Point;j=new d.Point;for(var l=1,k=f.length;l<k;l++){m.add(f[l]);j.add(a[l])}m.x/=f.length-1;m.y/=f.length-1;j.x/=a.length-1;j.y/=a.length-1;m=m.distance(b.p);
b=j.distance(b.p);a=a;if(m<b)a=f}b=1;for(f=a.length;b<f;b++)if(h(a[b],this.sketcher.molecule.atoms)!=-1)a[b].isOverlap=true;this.sketcher.tempRing=a;this.sketcher.repaint()}};c.NewRingState.prototype.innermousedown=function(b){if(this.sketcher.hovering!=null){this.sketcher.hovering.isHover=false;this.sketcher.hovering.isSelected=true;this.drag(b)}};c.NewRingState.prototype.innermouseup=function(b){if(this.sketcher.tempRing!=null&&this.sketcher.hovering!=null){var f=[],a=[];if(this.sketcher.hovering instanceof
d.Atom){h(this.sketcher.tempRing[0],this.sketcher.molecule.atoms)==-1&&f.push(this.sketcher.tempRing[0]);this.bondExists(this.sketcher.hovering,this.sketcher.tempRing[0])||a.push(new d.Bond(this.sketcher.hovering,this.sketcher.tempRing[0]));for(var j=1,m=this.sketcher.tempRing.length;j<m;j++){h(this.sketcher.tempRing[j],this.sketcher.molecule.atoms)==-1&&f.push(this.sketcher.tempRing[j]);this.bondExists(this.sketcher.tempRing[j-1],this.sketcher.tempRing[j])||a.push(new d.Bond(this.sketcher.tempRing[j-
1],this.sketcher.tempRing[j],j%2==1&&this.unsaturated?2:1))}this.bondExists(this.sketcher.tempRing[this.sketcher.tempRing.length-1],this.sketcher.hovering)||a.push(new d.Bond(this.sketcher.tempRing[this.sketcher.tempRing.length-1],this.sketcher.hovering,this.unsaturated?2:1))}else if(this.sketcher.hovering instanceof d.Bond){j=this.sketcher.hovering.a2;var l=this.sketcher.hovering.a1;if(this.sketcher.tempRing[0]==this.sketcher.hovering.a1){j=this.sketcher.hovering.a1;l=this.sketcher.hovering.a2}h(this.sketcher.tempRing[1],
this.sketcher.molecule.atoms)==-1&&f.push(this.sketcher.tempRing[1]);this.bondExists(j,this.sketcher.tempRing[1])||a.push(new d.Bond(j,this.sketcher.tempRing[1]));j=2;for(m=this.sketcher.tempRing.length;j<m;j++){h(this.sketcher.tempRing[j],this.sketcher.molecule.atoms)==-1&&f.push(this.sketcher.tempRing[j]);this.bondExists(this.sketcher.tempRing[j-1],this.sketcher.tempRing[j])||a.push(new d.Bond(this.sketcher.tempRing[j-1],this.sketcher.tempRing[j],j%2==0&&this.unsaturated?2:1))}this.bondExists(this.sketcher.tempRing[this.sketcher.tempRing.length-
1],l)||a.push(new d.Bond(this.sketcher.tempRing[this.sketcher.tempRing.length-1],l))}if(f.length!=0||a.length!=0)this.sketcher.historyManager.pushUndo(new i.AddAction(this.sketcher.molecule,f,a))}f=0;for(a=this.sketcher.molecule.atoms.length;f<a;f++)this.sketcher.molecule.atoms[f].isOverlap=false;this.sketcher.tempRing=null;this.sketcher.isMobile||this.mousemove(b)};c.NewRingState.prototype.innermousemove=function(b){this.sketcher.tempAtom==null&&this.findHoveredObject(b,true,true)}})(ChemDoodle.math,
ChemDoodle.monitor,ChemDoodle.sketcher.actions,ChemDoodle.sketcher.states,ChemDoodle.structures,jQuery.inArray,Math);(function(e){e.StateManager=function(g){this.STATE_NEW_BOND=new e.NewBondState(g);this.STATE_NEW_RING=new e.NewRingState(g);this.STATE_CHARGE=new e.ChargeState(g);this.STATE_LONE_PAIR=new e.LonePairState(g);this.STATE_MOVE=new e.MoveState(g);this.STATE_ERASE=new e.EraseState(g);this.STATE_LABEL=new e.LabelState(g);this.currentState=this.STATE_NEW_BOND;return true}})(ChemDoodle.sketcher.states);
(function(e,g){e.Button=function(i,c,d,h,n){this.id=i;this.iconPath=c;this.icon=d;this.toggle=false;this.tooltip=h?h:"";this.func=n?n:null;return true};e.Button.prototype.getElement=function(){return g("#"+this.id)};e.Button.prototype.getSource=function(i){var c=[];if(this.toggle){c.push('<input type="radio" name="');c.push(i);c.push('" id="');c.push(this.id);c.push('"><label for="');c.push(this.id);c.push('"><img id="');c.push(this.id);c.push('_icon" title="');c.push(this.tooltip);c.push('" src="');
c.push(this.iconPath);c.push(this.icon);c.push('.png"></label>')}else{c.push('<button id="');c.push(this.id);c.push('" onclick="return false;"><img title="');c.push(this.tooltip);c.push('" width="20" height="20" src="');c.push(this.iconPath);c.push(this.icon);c.push('.png"></button>')}return c.join("")};e.Button.prototype.setup=function(i){if(!this.toggle||i)this.getElement().button();this.getElement().click(this.func)};e.Button.prototype.disable=function(){var i=this.getElement();i.mouseout();i.button("disable")};
e.Button.prototype.enable=function(){this.getElement().button("enable")};e.Button.prototype.select=function(){var i=this.getElement();i.attr("checked",true);i.button("refresh")}})(ChemDoodle.sketcher.gui.desktop,jQuery);
(function(e,g){e.ButtonSet=function(i){this.id=i;this.buttons=[];this.buttonGroup="main_group";return this.toggle=true};e.ButtonSet.prototype.getElement=function(){return g("#"+this.id)};e.ButtonSet.prototype.getSource=function(){var i=[];i.push('<span id="');i.push(this.id);i.push('">');for(var c=0,d=this.buttons.length;c<d;c++){if(this.toggle)this.buttons[c].toggle=true;i.push(this.buttons[c].getSource(this.buttonGroup))}this.dropDown!=null&&i.push(this.dropDown.getButtonSource());i.push("</span>");
this.dropDown!=null&&i.push(this.dropDown.getHiddenSource());return i.join("")};e.ButtonSet.prototype.setup=function(){this.getElement().buttonset();for(var i=0,c=this.buttons.length;i<c;i++)this.buttons[i].setup(false);this.dropDown!=null&&this.dropDown.setup()};e.ButtonSet.prototype.addDropDown=function(i,c){this.dropDown=new e.DropDown(this.id+"_dd",c,i,this.buttons[this.buttons.length-1])}})(ChemDoodle.sketcher.gui.desktop,jQuery);
(function(e,g,i){e.Dialog=function(c,d){this.id=c;this.title=d?d:"Information";this.afterMessage=this.message=this.buttons=null;this.includeTextArea=false;return true};e.Dialog.prototype.getElement=function(){return g("#"+this.id)};e.Dialog.prototype.getTextArea=function(){return g("#"+this.id+"_ta")};e.Dialog.prototype.setup=function(){var c=[];c.push('<div style="font-size:12px;" id="');c.push(this.id);c.push('" title="');c.push(this.title);c.push('">');if(this.message!=null){c.push("<p>");c.push(this.message);
c.push("</p>")}if(this.includeTextArea){c.push('<textarea style="font-family:\'Courier New\';" id="');c.push(this.id);c.push('_ta" cols="55" rows="10"></textarea>')}if(this.afterMessage!=null){c.push("<p>");c.push(this.afterMessage);c.push("</p>")}c.push("</div>");i.writeln(c.join(""));this.getElement().dialog({autoOpen:false,width:435,buttons:this.buttons})}})(ChemDoodle.sketcher.gui.desktop,jQuery,document);
(function(e,g,i,c){g.MolGrabberDialog=function(d){this.id=d;this.title="MolGrabber";this.afterMessage=this.message=this.buttons=null;this.includeTextArea=false;return true};g.MolGrabberDialog.prototype=new g.Dialog;g.MolGrabberDialog.prototype.setup=function(){var d=[];d.push('<div style="font-size:12px;text-align:center;" id="');d.push(this.id);d.push('" title="');d.push(this.title);d.push('">');if(this.message!=null){d.push("<p>");d.push(this.message);d.push("</p>")}c.writeln(d.join(""));this.canvas=
new ChemDoodle.MolGrabberCanvas(this.id+"_mg",200,200);d=[];if(this.afterMessage!=null){d.push("<p>");d.push(this.afterMessage);d.push("</p>")}d.push("</div>");c.writeln(d.join(""));this.getElement().dialog({autoOpen:false,width:250,buttons:this.buttons})}})(ChemDoodle,ChemDoodle.sketcher.gui.desktop,jQuery,document);
(function(e,g,i,c){g.PeriodicTableDialog=function(d){this.id=d;this.title="Periodic Table";this.afterMessage=this.message=this.buttons=null;this.includeTextArea=false;return true};g.PeriodicTableDialog.prototype=new g.Dialog;g.PeriodicTableDialog.prototype.setup=function(){var d=[];d.push('<div style="text-align:center;" id="');d.push(this.id);d.push('" title="');d.push(this.title);d.push('">');c.writeln(d.join(""));this.canvas=new ChemDoodle.PeriodicTableCanvas(this.id+"_pt",20);c.writeln("</div>");
this.getElement().dialog({autoOpen:false,width:400,buttons:this.buttons})}})(ChemDoodle,ChemDoodle.sketcher.gui.desktop,jQuery,document);
(function(e,g,i,c){g.SaveFileDialog=function(d,h){this.id=d;this.sketcher=h;this.title="Save File";this.afterMessage=this.buttons=null;this.includeTextArea=false;return true};g.SaveFileDialog.prototype=new g.Dialog;g.SaveFileDialog.prototype.clear=function(){i("#"+this.id+"_link").html("The file link will appear here.")};g.SaveFileDialog.prototype.setup=function(){var d=[];d.push('<div style="font-size:12px;" id="');d.push(this.id);d.push('" title="');d.push(this.title);d.push('">');d.push("<p>Select the file format to save your structure to and click on the <strong>Generate File</strong> button.</p>");
d.push('<select id="');d.push(this.id);d.push('_select">');d.push('<option value="sk2">ACD/ChemSketch Document {sk2}');d.push('<option value="ros">Beilstein ROSDAL {ros}');d.push('<option value="cdx">Cambridgesoft ChemDraw Exchange {cdx}');d.push('<option value="cdxml">Cambridgesoft ChemDraw XML {cdxml}');d.push('<option value="mrv">ChemAxon Marvin Document {mrv}');d.push('<option value="cml">Chemical Markup Language {cml}');d.push('<option value="smiles">Daylight SMILES {smiles}');d.push('<option value="icl" selected>iChemLabs ChemDoodle Document {icl}');
d.push('<option value="inchi">IUPAC InChI {inchi}');d.push('<option value="jdx">IUPAC JCAMP-DX {jdx}');d.push('<option value="skc">MDL ISIS Sketch {skc}');d.push('<option value="tgf">MDL ISIS Sketch Transportable Graphics File {tgf}');d.push('<option value="mol">MDL MOLFile {mol}');d.push('<option value="sdf">MDL SDFile {sdf}');d.push('<option value="jme">Molinspiration JME String {jme}');d.push('<option value="pdb">RCSB Protein Data Bank {pdb}');d.push('<option value="mmd">Schr&ouml;dinger Macromodel {mmd}');
d.push('<option value="mae">Schr&ouml;dinger Maestro {mae}');d.push('<option value="smd">Standard Molecular Data {smd}');d.push('<option value="mol2">Tripos Mol2 {mol2}');d.push('<option value="sln">Tripos SYBYL SLN {sln}');d.push('<option value="xyz">XYZ {xyz}');d.push("</select>");d.push('<button id="');d.push(this.id);d.push('_button">');d.push("Generate File</button>");d.push("<p>When the file is written, a link will appear in the red-bordered box below, right-click on the link and choose the browser's <strong>Save As...</strong> function to save the file to your computer.</p>");
d.push('<div style="width:100%;height:30px;border:1px solid #c10000;text-align:center;" id="');d.push(this.id);d.push('_link">The file link will appear here.</div>');d.push('<p><a href="http://www.chemdoodle.com" target="_blank">How do I use these files?</a></p>');d.push("</div>");c.writeln(d.join(""));var h=this;i("#"+this.id+"_button").click(function(){i("#"+h.id+"_link").html("Generating file, please wait...");ChemDoodle.iChemLabs.saveFile(h.sketcher.molecule,i("#"+h.id+"_select").val(),function(n){i("#"+
h.id+"_link").html('<a href="'+n+'"><span style="text-decoration:underline;">File is generated. Right-click on this link and Save As...</span></a>')})});this.getElement().dialog({autoOpen:false,width:435,buttons:h.buttons})}})(ChemDoodle,ChemDoodle.sketcher.gui.desktop,jQuery,document);
(function(e,g,i,c,d){i.DialogManager=function(h){if(h.useServices)this.saveDialog=new c.SaveFileDialog(h.id+"_save_dialog",h);else{this.saveDialog=new c.Dialog(h.id+"_save_dialog","Save Molecule");this.saveDialog.message="Copy and paste the content of the textarea into a file and save it with the extension <strong>.mol</strong>.";this.saveDialog.includeTextArea=true;this.saveDialog.afterMessage='<a href="http://www.chemdoodle.com" target="_blank">How do I use MOLFiles?</a>'}this.saveDialog.setup();
this.loadDialog=new c.Dialog(h.id+"_load_dialog","Load Molecule");this.loadDialog.message="Copy and paste the contents of a MOLFile (extension <strong>.mol</strong>) in the textarea below and then press the <strong>Load</strong> button.";this.loadDialog.includeTextArea=true;this.loadDialog.afterMessage='<a href="http://www.chemdoodle.com" target="_blank">Where do I get MOLFiles?</a>';var n=this;this.loadDialog.buttons={Load:function(){d(this).dialog("close");var b=e.readMOL(n.loadDialog.getTextArea().val());
b.atoms.length!=0?h.historyManager.pushUndo(new g.SwitchMoleculeAction(h,b)):alert("No chemical content was recognized.")}};this.loadDialog.setup();this.searchDialog=new c.MolGrabberDialog(h.id+"_search_dialog");this.searchDialog.buttons={Load:function(){d(this).dialog("close");var b=n.searchDialog.canvas.molecule;b!=null&&b.atoms.length!=0&&b!=h.molecule&&h.historyManager.pushUndo(new g.SwitchMoleculeAction(h,b))}};this.searchDialog.setup();this.periodicTableDialog=new c.PeriodicTableDialog(h.id+
"_periodicTable_dialog");this.periodicTableDialog.buttons={Close:function(){d(this).dialog("close")}};this.periodicTableDialog.setup();this.periodicTableDialog.canvas.click=function(){if(this.hovered!=null){this.selected=this.hovered;var b=this.getHoveredElement();h.stateManager.currentState=h.stateManager.STATE_LABEL;h.stateManager.STATE_LABEL.label=b.symbol;this.repaint()}};this.calculateDialog=new c.Dialog(h.id+"_calculate_dialog","Calculations");this.calculateDialog.includeTextArea=true;this.calculateDialog.afterMessage=
'<a href="http://www.chemdoodle.com" target="_blank">Want more calculations?</a>';this.calculateDialog.setup();return true}})(ChemDoodle,ChemDoodle.sketcher.actions,ChemDoodle.sketcher.gui,ChemDoodle.sketcher.gui.desktop,jQuery);
(function(e,g,i){e.DropDown=function(c,d,h,n){this.id=c;this.iconPath=d;this.tooltip=h;this.dummy=n;this.buttonSet=new e.ButtonSet(c+"_set");this.buttonSet.buttonGroup=h;this.defaultButton=null;return true};e.DropDown.prototype.getButtonSource=function(){var c=[];c.push('<button id="');c.push(this.id);c.push('" onclick="return false;"><img title="');c.push(this.tooltip);c.push('" src="');c.push(this.iconPath);c.push('arrowDown.png"></button>');return c.join("")};e.DropDown.prototype.getHiddenSource=
function(){var c=[];c.push('<div style="display:none;position:absolute;z-index:10;border:1px #C1C1C1 solid;background:#F5F5F5;padding:5px;border-bottom-left-radius:5px;-moz-border-radius-bottomleft:5px;border-bottom-right-radius:5px;-moz-border-radius-bottomright:5px;" id="');c.push(this.id);c.push('_hidden">');c.push(this.buttonSet.getSource());c.push("</div>");return c.join("")};e.DropDown.prototype.setup=function(){if(this.defaultButton==null)this.defaultButton=this.buttonSet.buttons[0];var c=
"#"+this.id;g(c).button();g(c+"_hidden").hide();g(c).click(function(){var h=g(c+"_hidden");h.show().position({my:"center top",at:"center bottom",of:this,collision:"fit"});g(i).one("click",function(){h.hide()});return false});this.buttonSet.setup();var d=this;g.each(this.buttonSet.buttons,function(h){d.buttonSet.buttons[h].getElement().click(function(){d.dummy.absorb(d.buttonSet.buttons[h]);d.dummy.select();d.dummy.func()})});d.dummy.absorb(this.defaultButton);this.defaultButton.select()}})(ChemDoodle.sketcher.gui.desktop,
jQuery,document);(function(e,g){e.DummyButton=function(i,c,d,h){this.id=i;this.iconPath=c;this.icon=d;this.toggle=false;this.tooltip=h?h:"";this.func=null;return true};e.DummyButton.prototype=new e.Button;e.DummyButton.prototype.setup=function(){var i=this;this.getElement().click(function(){i.func()})};e.DummyButton.prototype.absorb=function(i){g("#"+this.id+"_icon").attr("src",i.iconPath+i.icon+".png");g("#"+this.id).button("refresh");this.func=i.func}})(ChemDoodle.sketcher.gui.desktop,jQuery);
(function(e,g,i,c,d,h,n,b,f){d.ToolbarManager=function(a){this.sketcher=a;this.buttonOpen=new h.Button(a.id+"_button_open",a.iconPath,"open20","Open",function(){a.dialogManager.loadDialog.getTextArea().val("");a.dialogManager.loadDialog.getElement().dialog("open")});this.buttonSave=new h.Button(a.id+"_button_save",a.iconPath,"save20","Save",function(){a.useServices?a.dialogManager.saveDialog.clear():a.dialogManager.saveDialog.getTextArea().val(e.writeMOL(a.molecule));a.dialogManager.saveDialog.getElement().dialog("open")});
this.buttonSearch=new h.Button(a.id+"_button_search",a.iconPath,"search20","Search",function(){a.dialogManager.searchDialog.getElement().dialog("open")});this.buttonCalculate=new h.Button(a.id+"_button_calculate",a.iconPath,"calculate20","Calculate",function(){g.calculate(a.molecule,["mf","mw","miw","deg_unsat","hba","hbd","pol_miller","cmr","tpsa","xlogp2"],function(j){function m(k,o,p){l.push(k);l.push(": ");for(k=k.length+2;k<30;k++)l.push(" ");l.push(o);l.push(" ");l.push(p);l.push("\n")}var l=
[];m("Molecular Formula",j.mf,"");m("Molecular Mass",j.mw,"amu");m("Monoisotopic Mass",j.miw,"amu");m("Degree of Unsaturation",j.deg_unsat,"");m("Hydrogen Bond Acceptors",j.hba,"");m("Hydrogen Bond Donors",j.hbd,"");m("Molecular Polarizability",j.pol_miller,"\u00c5\u00b3");m("Molar Refractivity",j.cmr,"cm\u00b3/mol");m("Polar Surface Area",j.tpsa,"\u00c5\u00b2");m("logP",j.xlogp2,"");a.dialogManager.calculateDialog.getTextArea().val(l.join(""));a.dialogManager.calculateDialog.getElement().dialog("open")})});
this.buttonMove=new h.Button(a.id+"_button_move",a.iconPath,"move20","Move",function(){a.stateManager.currentState=a.stateManager.STATE_MOVE});this.buttonMove.toggle=true;this.buttonErase=new h.Button(a.id+"_button_erase",a.iconPath,"erase20","Erase",function(){a.stateManager.currentState=a.stateManager.STATE_ERASE});this.buttonErase.toggle=true;this.buttonClear=new h.Button(a.id+"_button_clear",a.iconPath,"clear20","Clear",function(){var j=true;if(a.molecule.atoms.length==1){var m=a.molecule.atoms[0];
if(m.label=="C"&&m.charge==0&&m.mass==-1)j=false}j&&a.historyManager.pushUndo(new c.ClearAction(a))});this.buttonClean=new h.Button(a.id+"_button_clean",a.iconPath,"optimize20","Clean",function(){g.contactServer("optimize",{mol:i.toJSONDummy(a.molecule),dimension:2},function(j){j=i.fromJSONDummy(j.mol);var m=j.getCenter(),l=new n.Point(a.width/2,a.height/2);l.sub(m);m=0;for(var k=j.atoms.length;m<k;m++)j.atoms[m].add(l);a.historyManager.pushUndo(new c.ChangeCoordinatesAction(a.molecule.atoms,j.atoms))})});
this.makeScaleSet(this);this.makeHistorySet(this);this.makeLabelSet(this);this.makeBondSet(this);this.makeRingSet(this);this.makeAttributeSet(this);return true};d.ToolbarManager.prototype.write=function(){var a=[];a.push(this.buttonOpen.getSource());a.push(this.buttonSave.getSource());this.sketcher.useServices&&a.push(this.buttonSearch.getSource());a.push(this.scaleSet.getSource());a.push(this.buttonClear.getSource());a.push(this.buttonErase.getSource("main_group"));a.push(this.buttonMove.getSource("main_group"));
this.sketcher.useServices&&a.push(this.buttonClean.getSource());a.push(this.historySet.getSource());this.sketcher.useServices&&a.push(this.buttonCalculate.getSource());a.push("<br>");a.push(this.labelSet.getSource());a.push(this.bondSet.getSource());a.push(this.ringSet.getSource());a.push(this.attributeSet.getSource());a.push("<br>");f.write(a.join(""))};d.ToolbarManager.prototype.setup=function(){this.buttonOpen.setup();this.buttonSave.setup();this.sketcher.useServices&&this.buttonSearch.setup();
this.scaleSet.setup();this.buttonClear.setup();this.buttonErase.setup(true);this.buttonMove.setup(true);this.sketcher.useServices&&this.buttonClean.setup();this.historySet.setup();this.sketcher.useServices&&this.buttonCalculate.setup();this.labelSet.setup();this.bondSet.setup();this.ringSet.setup();this.attributeSet.setup();this.buttonSingle.select();this.buttonUndo.disable();this.buttonRedo.disable()};d.ToolbarManager.prototype.makeScaleSet=function(a){this.scaleSet=new h.ButtonSet(a.sketcher.id+
"_buttons_scale");this.scaleSet.toggle=false;this.buttonScalePlus=new h.Button(a.sketcher.id+"_button_scale_plus",a.sketcher.iconPath,"zoomIn20","Increase Scale",function(){a.sketcher.specs.scale*=1.5;a.sketcher.checkScale();a.sketcher.repaint()});this.scaleSet.buttons.push(this.buttonScalePlus);this.buttonScaleMinus=new h.Button(a.sketcher.id+"_button_scale_minus",a.sketcher.iconPath,"zoomOut20","Decrease Scale",function(){a.sketcher.specs.scale/=1.5;a.sketcher.checkScale();a.sketcher.repaint()});
this.scaleSet.buttons.push(this.buttonScaleMinus)};d.ToolbarManager.prototype.makeHistorySet=function(a){this.historySet=new h.ButtonSet(a.sketcher.id+"_buttons_history");this.historySet.toggle=false;this.buttonUndo=new h.Button(a.sketcher.id+"_button_undo",a.sketcher.iconPath,"undo20","Undo",function(){a.sketcher.historyManager.undo()});this.historySet.buttons.push(this.buttonUndo);this.buttonRedo=new h.Button(a.sketcher.id+"_button_redo",a.sketcher.iconPath,"redo20","Redo",function(){a.sketcher.historyManager.redo()});
this.historySet.buttons.push(this.buttonRedo)};d.ToolbarManager.prototype.makeLabelSet=function(a){this.labelSet=new h.ButtonSet(a.sketcher.id+"_buttons_label");this.buttonLabel=new h.DummyButton(a.sketcher.id+"_button_label",a.sketcher.iconPath,"Carbon","Set Label");this.labelSet.buttons.push(this.buttonLabel);this.labelSet.addDropDown("More Labels",a.sketcher.iconPath);this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_h",a.sketcher.iconPath,"Hydrogen","Hydrogen",
function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label="H"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_c",a.sketcher.iconPath,"Carbon","Carbon",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label="C"}));this.labelSet.dropDown.defaultButton=this.labelSet.dropDown.buttonSet.buttons[this.labelSet.dropDown.buttonSet.buttons.length-
1];this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_n",a.sketcher.iconPath,"Nitrogen","Nitrogen",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label="N"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_o",a.sketcher.iconPath,"Oxygen","Oxygen",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label=
"O"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_f",a.sketcher.iconPath,"Fluorine","Fluorine",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label="F"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_cl",a.sketcher.iconPath,"Chlorine","Chlorine",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label=
"Cl"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_br",a.sketcher.iconPath,"Bromine","Bromine",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label="Br"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_i",a.sketcher.iconPath,"Iodine","Iodine",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label=
"I"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_p",a.sketcher.iconPath,"Phosphorus","Phosphorus",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label="P"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_s",a.sketcher.iconPath,"Sulfur","Sulfur",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LABEL;a.sketcher.stateManager.STATE_LABEL.label=
"S"}));this.labelSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_label_pt",a.sketcher.iconPath,"periodicTable20","Choose Symbol",function(){for(var j=0,m=a.sketcher.dialogManager.periodicTableDialog.canvas.cells.length;j<m;j++){var l=a.sketcher.dialogManager.periodicTableDialog.canvas.cells[j];if(l.element.symbol==a.sketcher.stateManager.STATE_LABEL.label){a.sketcher.dialogManager.periodicTableDialog.canvas.selected=l;a.sketcher.dialogManager.periodicTableDialog.canvas.repaint();
break}}a.sketcher.dialogManager.periodicTableDialog.getElement().dialog("open")}))};d.ToolbarManager.prototype.makeBondSet=function(a){this.bondSet=new h.ButtonSet(a.sketcher.id+"_buttons_bond");this.buttonSingle=new h.Button(a.sketcher.id+"_button_bond_single",a.sketcher.iconPath,"SingleBond","Single Bond",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_BOND;a.sketcher.stateManager.STATE_NEW_BOND.bondOrder=1;a.sketcher.stateManager.STATE_NEW_BOND.stereo=n.Bond.STEREO_NONE});
this.bondSet.buttons.push(this.buttonSingle);this.buttonRecessed=new h.Button(a.sketcher.id+"_button_bond_recessed",a.sketcher.iconPath,"RecessedBond","Recessed Bond",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_BOND;a.sketcher.stateManager.STATE_NEW_BOND.bondOrder=1;a.sketcher.stateManager.STATE_NEW_BOND.stereo=n.Bond.STEREO_RECESSED});this.bondSet.buttons.push(this.buttonRecessed);this.buttonProtruding=new h.Button(a.sketcher.id+"_button_bond_protruding",a.sketcher.iconPath,
"ProtrudingBond","Protruding Bond",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_BOND;a.sketcher.stateManager.STATE_NEW_BOND.bondOrder=1;a.sketcher.stateManager.STATE_NEW_BOND.stereo=n.Bond.STEREO_PROTRUDING});this.bondSet.buttons.push(this.buttonProtruding);this.buttonDouble=new h.Button(a.sketcher.id+"_button_bond_double",a.sketcher.iconPath,"DoubleBond","Double Bond",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_BOND;a.sketcher.stateManager.STATE_NEW_BOND.bondOrder=
2;a.sketcher.stateManager.STATE_NEW_BOND.stereo=n.Bond.STEREO_NONE});this.bondSet.buttons.push(this.buttonDouble);this.buttonBond=new h.DummyButton(a.sketcher.id+"_button_bond",a.sketcher.iconPath,"TripleBond","Other Bond");this.bondSet.buttons.push(this.buttonBond);this.bondSet.addDropDown("More Bonds",a.sketcher.iconPath);this.bondSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_bond_triple",a.sketcher.iconPath,"TripleBond","Triple Bond",function(){a.sketcher.stateManager.currentState=
a.sketcher.stateManager.STATE_NEW_BOND;a.sketcher.stateManager.STATE_NEW_BOND.bondOrder=3;a.sketcher.stateManager.STATE_NEW_BOND.stereo=n.Bond.STEREO_NONE}));this.bondSet.dropDown.defaultButton=this.bondSet.dropDown.buttonSet.buttons[this.bondSet.dropDown.buttonSet.buttons.length-1];this.bondSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_bond_ambiguous_double",a.sketcher.iconPath,"AmbiguousDoubleBond","Ambiguous Double Bond",function(){a.sketcher.stateManager.currentState=
a.sketcher.stateManager.STATE_NEW_BOND;a.sketcher.stateManager.STATE_NEW_BOND.bondOrder=2;a.sketcher.stateManager.STATE_NEW_BOND.stereo=n.Bond.STEREO_AMBIGUOUS}))};d.ToolbarManager.prototype.makeRingSet=function(a){this.ringSet=new h.ButtonSet(a.sketcher.id+"_buttons_ring");this.buttonCyclohexane=new h.Button(a.sketcher.id+"_button_ring_cyclohexane",a.sketcher.iconPath,"Cyclohexane","Cyclohexane Ring",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=
6;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=false});this.ringSet.buttons.push(this.buttonCyclohexane);this.buttonBenzene=new h.Button(a.sketcher.id+"_button_ring_benzene",a.sketcher.iconPath,"Benzene","Benzene Ring",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=6;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=true});this.ringSet.buttons.push(this.buttonBenzene);this.buttonBond=new h.DummyButton(a.sketcher.id+
"_button_ring",a.sketcher.iconPath,"Cyclopentane","Other Ring");this.ringSet.buttons.push(this.buttonBond);this.ringSet.addDropDown("More Rings",a.sketcher.iconPath);this.ringSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_ring_cyclopropane",a.sketcher.iconPath,"Cyclopropane","Cyclopropane Ring",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=3;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=
false}));this.ringSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_ring_cyclobutane",a.sketcher.iconPath,"Cyclobutane","Cyclobutane Ring",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=4;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=false}));this.ringSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_ring_cyclopentane",a.sketcher.iconPath,"Cyclopentane","Cyclopentane Ring",
function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=5;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=false}));this.ringSet.dropDown.defaultButton=this.ringSet.dropDown.buttonSet.buttons[this.ringSet.dropDown.buttonSet.buttons.length-1];this.ringSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_ring_cycloheptane",a.sketcher.iconPath,"Cycloheptane","Cycloheptane Ring",function(){a.sketcher.stateManager.currentState=
a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=7;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=false}));this.ringSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_ring_cyclooctane",a.sketcher.iconPath,"Cyclooctane","Cyclooctane Ring",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_NEW_RING;a.sketcher.stateManager.STATE_NEW_RING.numSides=8;a.sketcher.stateManager.STATE_NEW_RING.unsaturated=false}))};d.ToolbarManager.prototype.makeAttributeSet=
function(a){this.attributeSet=new h.ButtonSet(a.sketcher.id+"_buttons_attribute");this.buttonChargePlus=new h.Button(a.sketcher.id+"_button_attribute_charge_increment",a.sketcher.iconPath,"IncreaseCharge","Increase Charge",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_CHARGE;a.sketcher.stateManager.STATE_CHARGE.delta=1});this.attributeSet.buttons.push(this.buttonChargePlus);this.buttonAttribute=new h.DummyButton(a.sketcher.id+"_button_attribute",a.sketcher.iconPath,
"DecreaseCharge","Other Attribute");this.attributeSet.buttons.push(this.buttonAttribute);this.attributeSet.addDropDown("More Attributes",a.sketcher.iconPath);this.attributeSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_attribute_charge_decrement",a.sketcher.iconPath,"DecreaseCharge","Decrease Charge",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_CHARGE;a.sketcher.stateManager.STATE_CHARGE.delta=-1}));this.attributeSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+
"_button_attribute_lonePair_increment",a.sketcher.iconPath,"AddLonePair","Add Lone Pair",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LONE_PAIR;a.sketcher.stateManager.STATE_LONE_PAIR.delta=1}));this.attributeSet.dropDown.buttonSet.buttons.push(new h.Button(a.sketcher.id+"_button_attribute_lonePair_decrement",a.sketcher.iconPath,"RemoveLonePair","Remove Lone Pair",function(){a.sketcher.stateManager.currentState=a.sketcher.stateManager.STATE_LONE_PAIR;a.sketcher.stateManager.STATE_LONE_PAIR.delta=
-1}))}})(ChemDoodle,ChemDoodle.iChemLabs,ChemDoodle.io,ChemDoodle.sketcher.actions,ChemDoodle.sketcher.gui,ChemDoodle.sketcher.gui.desktop,ChemDoodle.structures,jQuery,document);
(function(e,g,i,c,d,h,n){e.SketcherCanvas=function(b,f,a,j,m,l){var k=this;this.iconPath=j;this.isMobile=m;this.useServices=l;this.id=b;this.toolbarManager=new i.gui.ToolbarManager(this);if(j!=null){this.toolbarManager.write();d(n).load(function(){k.toolbarManager.setup()});this.dialogManager=new i.gui.DialogManager(this)}this.stateManager=new i.states.StateManager(this);this.historyManager=new i.actions.HistoryManager(this);b&&this.create(b,f,a);this.specs.atoms_circleDiameter_2D=7;this.specs.atoms_circleBorderWidth_2D=
0;this.isHelp=false;this.helpPos=new c.Point(this.width-20,20);this.clear();this.lastPinchScale=1;this.lastGestureRotate=0;return true};e.SketcherCanvas.prototype=new e._Canvas;e.SketcherCanvas.prototype.clear=function(){var b=new c.Molecule;b.atoms[0]=new c.Atom("C",0,0,0);this.loadMolecule(b)};e.SketcherCanvas.prototype.drawSketcherDecorations=function(b){b.save();b.translate(this.width/2,this.height/2);b.rotate(this.specs.rotateAngle);b.scale(this.specs.scale,this.specs.scale);b.translate(-this.width/
2,-this.height/2);this.hovering!=null&&this.hovering.drawDecorations(b);if(this.tempAtom!=null){b.strokeStyle="#00FF00";b.fillStyle="#00FF00";b.lineWidth=1;b.beginPath();b.moveTo(this.hovering.x,this.hovering.y);g.contextHashTo(b,this.hovering.x,this.hovering.y,this.tempAtom.x,this.tempAtom.y,2,2);b.stroke();b.beginPath();b.arc(this.tempAtom.x,this.tempAtom.y,3,0,h.PI*2,false);b.fill();if(this.tempAtom.isOverlap){b.strokeStyle="#C10000";b.lineWidth=1.2;b.beginPath();b.arc(this.tempAtom.x,this.tempAtom.y,
7,0,h.PI*2,false);b.stroke()}}if(this.tempRing!=null){b.strokeStyle="#00FF00";b.fillStyle="#00FF00";b.lineWidth=1;b.beginPath();if(this.hovering instanceof c.Atom){b.moveTo(this.hovering.x,this.hovering.y);g.contextHashTo(b,this.hovering.x,this.hovering.y,this.tempRing[0].x,this.tempRing[0].y,2,2);for(var f=1,a=this.tempRing.length;f<a;f++)g.contextHashTo(b,this.tempRing[f-1].x,this.tempRing[f-1].y,this.tempRing[f].x,this.tempRing[f].y,2,2);g.contextHashTo(b,this.tempRing[this.tempRing.length-1].x,
this.tempRing[this.tempRing.length-1].y,this.hovering.x,this.hovering.y,2,2)}else if(this.hovering instanceof c.Bond){f=this.hovering.a2;var j=this.hovering.a1;if(this.tempRing[0]==this.hovering.a1){f=this.hovering.a1;j=this.hovering.a2}b.moveTo(f.x,f.y);g.contextHashTo(b,f.x,f.y,this.tempRing[1].x,this.tempRing[1].y,2,2);f=2;for(a=this.tempRing.length;f<a;f++)g.contextHashTo(b,this.tempRing[f-1].x,this.tempRing[f-1].y,this.tempRing[f].x,this.tempRing[f].y,2,2);g.contextHashTo(b,this.tempRing[this.tempRing.length-
1].x,this.tempRing[this.tempRing.length-1].y,j.x,j.y,2,2)}b.stroke();f=0;for(a=this.molecule.atoms.length;f<a;f++)if(this.molecule.atoms[f].isOverlap){b.strokeStyle="#C10000";b.lineWidth=1.2;b.beginPath();b.arc(this.molecule.atoms[f].x,this.molecule.atoms[f].y,7,0,h.PI*2,false);b.stroke()}}b.restore()};e.SketcherCanvas.prototype.drawChildExtras=function(b){this.drawSketcherDecorations(b);if(!this.hideHelp){var f=b.createRadialGradient(this.width-20,20,10,this.width-20,20,2);f.addColorStop(0,"#00680F");
f.addColorStop(1,"#FFFFFF");b.fillStyle=f;b.beginPath();b.arc(this.helpPos.x,this.helpPos.y,10,0,h.PI*2,false);b.fill();if(this.isHelp){b.lineWidth=2;b.strokeStyle="black";b.stroke()}b.fillStyle=this.isHelp?"red":"black";b.textAlign="center";b.textBaseline="middle";b.font="14px sans-serif";b.fillText("?",this.helpPos.x,this.helpPos.y)}if(!this.paidToHideTrademark){f=b.measureText("ChemDoodle").width;b.textAlign="left";b.textBaseline="bottom";b.fillStyle="rgba(0, 90, 0, 0.5)";b.fillText("ChemDoodle",
this.width-f-18,this.height-4);b.font="8px sans-serif";b.fillText("TM",this.width-18,this.height-12)}};e.SketcherCanvas.prototype.scaleEvent=function(b){b.op=new c.Point(b.p.x,b.p.y);if(this.specs.scale!=1){b.p.x=this.width/2+(b.p.x-this.width/2)/this.specs.scale;b.p.y=this.height/2+(b.p.y-this.height/2)/this.specs.scale}};e.SketcherCanvas.prototype.checkScale=function(){if(this.specs.scale<0.5)this.specs.scale=0.5;else if(this.specs.scale>10)this.specs.scale=10};e.SketcherCanvas.prototype.click=
function(b){this.scaleEvent(b);this.stateManager.currentState.click(b)};e.SketcherCanvas.prototype.rightclick=function(b){this.scaleEvent(b);this.stateManager.currentState.rightclick(b)};e.SketcherCanvas.prototype.dblclick=function(b){this.scaleEvent(b);this.stateManager.currentState.dblclick(b)};e.SketcherCanvas.prototype.mousedown=function(b){this.scaleEvent(b);this.stateManager.currentState.mousedown(b)};e.SketcherCanvas.prototype.rightmousedown=function(b){this.scaleEvent(b);this.stateManager.currentState.rightmousedown(b)};
e.SketcherCanvas.prototype.mousemove=function(b){this.isHelp=false;if(b.p.distance(this.helpPos)<10)this.isHelp=true;this.scaleEvent(b);this.stateManager.currentState.mousemove(b)};e.SketcherCanvas.prototype.mouseout=function(b){this.scaleEvent(b);this.stateManager.currentState.mouseout(b)};e.SketcherCanvas.prototype.mouseover=function(b){this.scaleEvent(b);this.stateManager.currentState.mouseover(b)};e.SketcherCanvas.prototype.mouseup=function(b){this.scaleEvent(b);this.stateManager.currentState.mouseup(b)};
e.SketcherCanvas.prototype.rightmouseup=function(b){this.scaleEvent(b);this.stateManager.currentState.rightmouseup(b)};e.SketcherCanvas.prototype.mousewheel=function(b,f){this.scaleEvent(b);this.stateManager.currentState.mousewheel(b,f)};e.SketcherCanvas.prototype.drag=function(b){this.scaleEvent(b);this.stateManager.currentState.drag(b)};e.SketcherCanvas.prototype.keydown=function(b){this.scaleEvent(b);this.stateManager.currentState.keydown(b)};e.SketcherCanvas.prototype.keypress=function(b){this.scaleEvent(b);
this.stateManager.currentState.keypress(b)};e.SketcherCanvas.prototype.keyup=function(b){this.scaleEvent(b);this.stateManager.currentState.keyup(b)};e.SketcherCanvas.prototype.touchstart=function(b){if(b.originalEvent.touches&&b.originalEvent.touches.length>1){if(this.tempAtom!=null||this.tempRing!=null){this.hovering=this.tempRing=this.tempAtom=null;this.repaint()}this.lastPoint=null}else{this.scaleEvent(b);this.stateManager.currentState.mousemove(b);this.stateManager.currentState.mousedown(b)}};
e.SketcherCanvas.prototype.touchmove=function(b){this.scaleEvent(b);this.stateManager.currentState.drag(b)};e.SketcherCanvas.prototype.touchend=function(b){this.scaleEvent(b);this.stateManager.currentState.mouseup(b);if(this.hovering!=null){this.stateManager.currentState.clearHover();this.repaint()}};e.SketcherCanvas.prototype.gesturechange=function(b){if(b.originalEvent.scale-this.lastPinchScale!=1){this.specs.scale*=b.originalEvent.scale/this.lastPinchScale;this.checkScale();this.lastPinchScale=
b.originalEvent.scale}if(this.lastGestureRotate-b.originalEvent.rotation!=0){var f=(this.lastGestureRotate-b.originalEvent.rotation)/180*h.PI,a=new c.Point(this.width/2,this.height/2);if(this.parentAction==null){this.parentAction=new i.actions.RotateAction(this.molecule.atoms,f,a);this.historyManager.pushUndo(this.parentAction)}else{this.parentAction.dif+=f;for(var j=0,m=this.molecule.atoms.length;j<m;j++){var l=a.distance(this.molecule.atoms[j]),k=a.angle(this.molecule.atoms[j])+f;this.molecule.atoms[j].x=
a.x+l*h.cos(k);this.molecule.atoms[j].y=a.y-l*h.sin(k)}this.molecule.check()}this.lastGestureRotate=b.originalEvent.rotation}this.repaint()};e.SketcherCanvas.prototype.gestureend=function(){this.lastPinchScale=1;this.lastGestureRotate=0;this.parentAction=null}})(ChemDoodle,ChemDoodle.extensions,ChemDoodle.sketcher,ChemDoodle.structures,jQuery,Math,window);

