summaryrefslogtreecommitdiff
path: root/index.html
blob: 91e1665b03213230da2bf4536a2fc28b6ca89111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
<html>

<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <title>Xcos</title>
    <style type="text/css" media="screen">
        BODY {
            font-family: Arial;
        }
        
        H1 {
            font-size: 18px;
        }
        
        H2 {
            font-size: 16px;
        }
    </style>

    <!-- Loads and initializes the library -->
    <script type="text/javascript" src="jquery/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="mxClient.min.js"></script>
    <script type="text/javascript" src="editor/mxDefaultKeyHandler.js"></script>
    <script type="text/javascript" src="handler/mxKeyHandler.js"></script>
    <script type="text/javascript" src="jquery/farbtastic.js"></script>

    <link rel="stylesheet" href="jquery/farbtastic.css" type="text/css" />
    <link rel="stylesheet" href="jquery/jquery-ui.css">

    <script type="text/javascript" src="details.js"></script>
    <script type="text/javascript" src="json2.js"></script>
    <script type="text/javascript">
        function main(container, outline, toolbar, sidebar, status) {
            // Checks if the browser is supported
            if (!mxClient.isBrowserSupported()) {
                // Displays an error message if the browser is not supported.
                mxUtils.error('Browser is not supported!', 200, false);
            } else {
                // If connect preview is not moved away then getCellAt is used to detect the cell under
                // the mouse if the mouse is over the preview shape in IE (no event transparency), ie.
                // the built-in hit-detection of the HTML document will not be used in this case.
                mxConnectionHandler.prototype.movePreviewAway = false;
                mxConnectionHandler.prototype.waypointsEnabled = true;
                mxGraph.prototype.resetEdgesOnConnect = false;

                // Enables guides
                mxGraphHandler.prototype.guidesEnabled = true;

                // Alt disables guides
                mxGuide.prototype.isEnabledForEvent = function(evt) {
                    return !mxEvent.isAltDown(evt);
                };

                // Enables snapping waypoints to terminals
                mxEdgeHandler.prototype.snapToTerminals = true;

                // Assigns some global constants for general behaviour, eg. minimum
                // size (in pixels) of the active region for triggering creation of
                // new connections, the portion (100%) of the cell area to be used
                // for triggering new connections, as well as some fading options for
                // windows and the rubberband selection.
                mxConstants.MIN_HOTSPOT_SIZE = 16;
                mxConstants.DEFAULT_HOTSPOT = 1;

                // Workaround for Internet Explorer ignoring certain CSS directives
                if (mxClient.IS_QUIRKS) {
                    document.body.style.overflow = 'hidden';
                    new mxDivResizer(container);
                    new mxDivResizer(outline);
                    new mxDivResizer(toolbar);
                    new mxDivResizer(sidebar);
                    new mxDivResizer(status);
                }

                // Creates a wrapper editor with a graph inside the given container.
                // The editor is used to create certain functionality for the
                // graph, such as the rubberband selection, but most parts
                // of the UI are custom in this example.
                var editor = new mxEditor();
                var graph = editor.graph;
                var model = graph.getModel();

                graph.setPanning(true);
                graph.setConnectable(true);
                graph.setConnectableEdges(true);
                graph.setDisconnectOnMove(false);
                graph.foldingEnabled = false;

                // Disable highlight of cells when dragging from toolbar
                graph.setDropEnabled(false);

                // Centers the port icon on the target port
                graph.connectionHandler.targetConnectImage = true;

                // Does not allow dangling edges
                graph.setAllowDanglingEdges(false);

                // Sets the graph container and configures the editor
                editor.setGraphContainer(container);

                // Disables built-in context menu
                mxEvent.disableContextMenu(document.body);

                // Configures automatic expand on mouseover
                graph.panningHandler.autoExpand = true;

                // Creates a right-click menu
                graph.panningHandler.factoryMethod = function(menu, cell, evt) {

                    if (cell != null) {

                        if (cell.value == "ExplicitInputPort" || cell.value == "ExplicitOutputPort" || cell.value == "CommandPort" || cell.value == "ControlPort") {

                        } else if (cell.isEdge() == true) // @ToDo: Pooja: Different edge value cases.
                        {

                            menu.addItem('Delete', 'images/delete2.png', function() {
                                editor.execute('delete');
                            });
                            var edgeformat = menu.addItem('Format', null, null);

                            menu.addItem('Border Color', 'images/draw-brush.png', function() {
                                // @ToDo: Pooja: Functionality to be put.   
                                showColorWheel(graph, cell, 'edgeStrokeColor');

                            }, edgeformat);
                            menu.addItem('Text and Text Font', 'images/edit.png', function() {
                                alert('Edit...'); // @ToDo: Pooja: Functionality to be put.
                            }, edgeformat);
                            menu.addItem('Text Color', 'images/edit.png', function() {
                                alert('Edit...'); // @ToDo: Pooja: Functionality to be put.
                            }, edgeformat);

                        } else {
                            menu.addItem('Block Parameters...', 'images/gear.gif', function() {
                                showPropertiesWindow(graph, cell);
                            });

                            menu.addItem('Cut', 'images/cut.png', function() {
                                editor.execute('cut');
                            });
                            menu.addItem('Copy', 'images/copy.png', function() {
                                editor.execute('copy');
                            });
                            menu.addItem('Delete', 'images/delete2.png', function() {
                                editor.execute('delete');
                            });

                            menu.addItem('Selection to superblock', 'images/superblock.png', function() {
                                // @ToDo: Pooja: Functionality to be put.
                            });
                            var format = menu.addItem('Format', null, null);

                            menu.addItem('Rotate', 'images/rotate.png', function() {
                                editor.execute('rotateCustom');
                            }, format);
                            menu.addItem('Border Color', 'images/draw-brush.png', function() {
                                showColorWheel(graph, cell, 'vertexStrokeColor');

                            }, format);
                            menu.addItem('Fill Color', 'images/edit.png', function() {
                                showColorWheel(graph, cell, 'vertexFillColor');
                            }, format);
                            menu.addItem('Details', null, function() {
                                // @ToDo: Pooja: Functionality to be put.
                            });
                        }
                    } else {
                        menu.addItem('Undo', 'images/undo.png', function() {
                            editor.execute('undo');
                        });
                        menu.addItem('Redo', 'images/redo.png', function() {
                            editor.execute('redo');
                        });
                        menu.addItem('Paste', 'images/paste.png', function() {
                            editor.execute('paste');
                        });
                        menu.addItem('Select all', 'images/selectall.png', function() {
                            editor.execute('selectAll');
                        });
                        menu.addItem('Set Context', null, function() {
                            // @ToDo: Pooja: Functionality to be put.
                        });
                        menu.addItem('Setup', 'images/setup.png', function() {
                            // @ToDo: Pooja: Functionality to be put.
                        });
                        menu.addItem('Zoom In', 'images/zoom_in.png', function() {
                            editor.execute('zoomIn');
                        });
                        menu.addItem('Zoom Out', 'images/zoom_out.png', function() {
                            editor.execute('zoomOut');
                        });
                        menu.addItem('Diagram background...', null, function() {
                            showColorWheel(graph, cell, 'bgColor');
                        });
                    }

                };

                //var config = mxUtils.load('config/editor-commons.xml').getDocumentElement();
                var config = mxUtils.load('config/keyhandler-commons.xml').getDocumentElement();
                editor.configure(config);

                // @jiteshjha, @pooja
                /*
                   The code creates a function that informs the undoManager of an undoable edit
                   and binds it to the undo event of mxGraphModel and mxGraphView
                   using mxEventSource.addListener.
                */
                var undoManager = new mxUndoManager();
                var listener = function(sender, evt) {
                    undoManager.undoableEditHappened(evt.getProperty('edit'));
                };
                graph.getModel().addListener(mxEvent.UNDO, listener);
                graph.getModel().addListener(mxEvent.REDO, listener);
                graph.getView().addListener(mxEvent.UNDO, listener);
                graph.getView().addListener(mxEvent.REDO, listener);

                editor.addAction('undoCustom', function(editor, cell) {
                    undoManager.undo();
                });

                editor.addAction('redoCustom', function(editor, cell) {
                    undoManager.redo();
                });

                /*
                  For every click on the graph, check if the selected mxCell is the recently created edge,
                  and then check if that edge satisfies one of the port constraints.

                */
                graph.addListener(mxEvent.CLICK, function(sender, evt) {
                    var selectedEdgeObject = graph.getSelectionCell();
                    if (selectedEdgeObject != null && selectedEdgeObject.isEdge() == true) {

                        var selectedEdgeObject = graph.getSelectionCell();
                        var target = selectedEdgeObject.target;
                        var source;

                        if (selectedEdgeObject != null && selectedEdgeObject.isEdge() == true) {
                            function getEdgeId(edgeObject) {
                                while (edgeObject.source != null && edgeObject.source.isEdge() == true) {
                                    edgeObject = edgeObject.source;
                                }
                                return edgeObject.source;
                            }

                            if (selectedEdgeObject.isEdge() == true) {
                                source = getEdgeId(selectedEdgeObject);
                            }
                            if (source != null && target != null) {
                                if (!(((source.value == "ExplicitOutputPort" && target.value == "ExplicitInputPort") ||
                                            (source.value == "ExplicitInputPort" && target.value == "ExplicitOutputPort") ||
                                            (source.value == "ImplicitOutputPort" && target.value == "ImplicitInputPort") ||
                                            (source.value == "ImplicitInputPort" && target.value == "ImplicitOutputPort") ||
                                            (source.value == "CommandPort" && target.value == "ControlPort") ||
                                            (source.value == "ControlPort" && target.value == "CommandPort")) &&
                                        (source.getEdgeCount() <= 1 && source.isVertex() == true &&
                                            target.getEdgeCount() <= 1 && target.isVertex() == true)
                                    )) {

                                    if (!(source.getEdgeCount() <= 1 && source.isVertex() == true &&
                                            target.getEdgeCount() <= 1 && target.isVertex() == true)) {
                                        alert("Port is already connected, please select an please select an unconnected port or a valid link");
                                    } else if (source.value == "ImplicitInputPort") {
                                        alert("Implicit data input port must be connected to implicit data output port");
                                    } else if (source.value == "ImplicitOutputPort") {
                                        alert("Implicit data output port must be connected to implicit data input port");
                                    } else if (source.value == "ExplicitOutputPort") {
                                        alert("Explicit data output port must be connected to explicit data input port");
                                    } else if (source.value == "ExplicitInputPort") {
                                        alert("Explicit data input port must be connected to explicit data output port");
                                    } else if (source.value = "ControlPort") {
                                        alert("Control port must be connected to command port");
                                    } else if (source.value = "CommandPort") {
                                        alert("Command port must be connected to control port");
                                    }

                                    /*
                                      Remove last mxEvent from the undoManager history stack, 
                                      Store all the remaining undo mxEvents into a temporary array, 
                                      clears the history, and readds the mxEvents into the undoManager history stack.
                                    */
                                    editor.execute('undo');

                                    // Remove the last element from the history array.
                                    undoManager.history.splice(-1, 1);

                                    // storage[] -> temporary array
                                    var storage = [];
                                    for (i in undoManager.history) {
                                        if (undoManager.history[i] != null) {
                                            storage.push(undoManager.history[i])
                                        }
                                    }

                                    // Clear the undoManager history, and reset the undoManager pointer to avoid any undo of null events.
                                    undoManager.clear();

                                    // Move the remaning mxEvents back into the undoManager history stack.
                                    for (i in storage) {
                                        if (storage[i] != null) {
                                            undoManager.undoableEditHappened(storage[i]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                });

                // Disables drag-and-drop into non-swimlanes.
                graph.isValidDropTarget = function(cell, cells, evt) {
                    return this.isSwimlane(cell);
                };


                // Disables drilling into non-swimlanes.
                graph.isValidRoot = function(cell) {
                    return this.isValidDropTarget(cell);
                }

                // Does not allow selection of locked cells
                graph.isCellSelectable = function(cell) {
                    return !this.isCellLocked(cell);
                };

                // Returns a shorter label if the cell is collapsed and no
                // label for expanded groups
                graph.getLabel = function(cell) {
                    var tmp = mxGraph.prototype.getLabel.apply(this, arguments); // "supercall"

                    if (this.isCellLocked(cell)) {
                        // Returns an empty label but makes sure an HTML
                        // element is created for the label (for event
                        // processing wrt the parent label)
                        return '';
                    } else if (this.isCellCollapsed(cell)) {
                        var index = tmp.indexOf('</h1>');

                        if (index > 0) {
                            tmp = tmp.substring(0, index + 5);
                        }
                    }

                    return tmp;
                }

                // Disables HTML labels for swimlanes to avoid conflict
                // for the event processing on the child cells. HTML
                // labels consume events before underlying cells get the
                // chance to process those events.
                //
                // NOTE: Use of HTML labels is only recommended if the specific
                // features of such labels are required, such as special label
                // styles or interactive form fields. Otherwise non-HTML labels
                // should be used by not overidding the following function.
                // See also: configureStylesheet.
                graph.isHtmlLabel = function(cell) {
                    return !this.isSwimlane(cell);
                }

                // To disable the folding icon, use the following code:
                graph.isCellFoldable = function(cell) {
                    return false;
                }

                // Shows a "modal" window when double clicking a vertex.
                graph.dblClick = function(evt, cell) {
                    // Do not fire a DOUBLE_CLICK event here as mxEditor will
                    // consume the event and start the in-place editor.
                    if (this.isEnabled() &&
                        !mxEvent.isConsumed(evt) &&
                        cell != null &&
                        this.isCellEditable(cell)) {
                        if (!this.isHtmlLabel(cell)) {
                            this.startEditingAtCell(cell);
                        } else {
                            /*
                            var content = document.createElement('div');
                            content.innerHTML = this.convertValueToString(cell);
                            showModalWindow(this, 'Properties', content, 400, 300);
                            */
                            showPropertiesWindow(graph, cell);
                        }
                    }

                    // Disables any default behaviour for the double click
                    mxEvent.consume(evt);
                };

                graph.getTooltipForCell = function(cell) {
                    var text = null;
                    // If cell is a block or port
                    if (cell.source == null && cell.target == null) {
                        if (cell.connectable) { // Cell is a port
                            // @ToDo: Port Number
                            text = 'Style : ' + cell.style + "\n";
                        } else { //Cell is a block
                            // @ToDo: Block Name, Simulation, Flip, Mirror
                            // @ToDo: Number of Input, Output, Control, Command Ports
                            var geometry = cell.getGeometry();
                            text = 'UID : ' + cell.id + "\n" +
                                'Style : ' + cell.style + "\n" +
                                'x : ' + geometry.x + "\n" +
                                'y : ' + geometry.y + "\n" +
                                'w : ' + geometry.width + "\n" +
                                'h : ' + geometry.height + "\n";
                        }
                    }
                    return text;
                };

                // Create XML tags!
                // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                // https://jgraph.github.io/mxgraph/docs/js-api/files/model/mxCell-js.html
                // Uncomment this block to see XML tags work
                /*graph.convertValueToString = function(cell)
                {
                  if (mxUtils.isNode(cell.value))
                  {
                    return cell.getAttribute('label', '');
                  }
                };*/

                var cellLabelChanged = graph.cellLabelChanged;
                graph.cellLabelChanged = function(cell, newValue, autoSize) {
                    if (mxUtils.isNode(cell.value)) {
                        // Clones the value for correct undo/redo
                        var elt = cell.value.cloneNode(true);
                        elt.setAttribute('label', newValue);
                        newValue = elt;
                    }

                    cellLabelChanged.apply(this, arguments);
                };

                // Enables new connections
                graph.setConnectable(true);

                // Adds all required styles to the graph (see below)
                configureStylesheet(graph);

                // Adds sidebar icons.
                addIcons(graph, sidebar);

                // Creates a new DIV that is used as a toolbar and adds
                // toolbar buttons.
                var spacer = document.createElement('div');
                spacer.style.display = 'inline';
                spacer.style.padding = '8px';

                // Defines a new export action
                editor.addAction('toggle', function(editor, cell) {
                    var toggle = document.getElementById("toggleBlocks");
                    var button = document.getElementById("toggle");
                    toggle.click();
                    button.innerHTML = '';
                    if (toggle.innerHTML == 'Expand All') {
                        createButtonImage(button, 'images/navigate_plus.png');
                    } else if (toggle.innerHTML == 'Collapse All') {
                        createButtonImage(button, 'images/navigate_minus.png');
                    }
                    var titleName = document.createTextNode(toggle.innerHTML);
                    button.appendChild(titleName);
                });


                /*
                	@pooja, @jiteshjha
					Create a custom rotate action for a selected cell.
                */
                editor.addAction('rotateCustom', function(editor, cell) {
                    selectedCell = graph.getSelectionCell();
                    if (selectedCell != null) {
                        var cells = [];
                        cells.push(selectedCell);
                        for (var i = 0; i < selectedCell.getChildCount(); i++)
                            cells.push(selectedCell.getChildAt(i));
                        graph.getModel().beginUpdate();
                        try {
                            for (var i = 0; i < cells.length; i++) {
                                var cell = cells[i];
                                if (cell.isVertex() == true) {
                                    var geo = graph.getCellGeometry(cell);

                                    if (geo != null) {
                                        // Rotates the size and position in the geometry
                                        geo = geo.clone();
                                        geo.x += geo.width / 2 - geo.height / 2;
                                        geo.y += geo.height / 2 - geo.width / 2;
                                        var tmp = geo.width;
                                        geo.width = geo.height;
                                        geo.height = tmp;
                                        graph.getModel().setGeometry(cell, geo);
                                        // Reads the current direction and advances by 90 degrees
                                        var state = graph.view.getState(cell);

                                        if (state != null) {
                                            if (cell.isConnectable() == true) {
                                                if (cell.value == "ExplicitOutputPort" || cell.value == "ImplicitOutputPort") {
                                                    var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east';
                                                    var geoCell = cell.getGeometry();
                                                    if (dir == 'east' || dir == 'west') {
                                                        var temp = geoCell.x;
                                                        geoCell.x = geoCell.y - 0.0625;
                                                        geoCell.y = temp + 0.0625;
                                                        cell.setGeometry(geoCell);
                                                        if (dir == 'east')
                                                            dir = 'south';
                                                        else
                                                            dir = 'north';
                                                    } else if (dir == 'south' || dir == 'north') {

                                                        geoCell.y = geoCell.x + 0.0625;
                                                        if (dir == 'south') {
                                                            dir = 'west';
                                                            geoCell.x = 0 - 0.125;
                                                        } else {
                                                            dir = 'east';
                                                            geoCell.x = 1;
                                                        }
                                                        cell.setGeometry(geoCell);
                                                    }
                                                } else if (cell.value == "ExplicitInputPort" || cell.value == "ImplicitInputPort") {
                                                    var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east';
                                                    var geoCell = cell.getGeometry();
                                                    if (dir == 'south' || dir == 'north') {
                                                        geoCell.y = geoCell.x - 0.0625;
                                                        if (dir == 'south') {
                                                            dir = 'west';
                                                            geoCell.x = 1 + 0.125;
                                                        } else {
                                                            dir = 'east';
                                                            geoCell.x = 0;
                                                        }
                                                        cell.setGeometry(geoCell);
                                                    } else if (dir == 'east' || dir == 'west') {
                                                        geoCell = geoCell.clone();
                                                        var temp = geoCell.x;
                                                        geoCell.x = parseFloat(geoCell.y) + 0.0625;
                                                        geoCell.y = temp - 0.0625;
                                                        cell.setGeometry(geoCell);
                                                        if (dir == 'east')
                                                            dir = 'south';
                                                        else
                                                            dir = 'north';
                                                    }
                                                } else if (cell.value == 'CommandPort') {
                                                    var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east';
                                                    var geoCell = cell.getGeometry();
                                                    if (dir == 'south' || dir == 'north') {
                                                        var temp = geoCell.x;
                                                        geoCell.x = geoCell.y + 0.0625;
                                                        geoCell.y = temp - 0.0625;
                                                        cell.setGeometry(geoCell);
                                                        if (dir == 'south')
                                                            dir = 'west';
                                                        else
                                                            dir = 'east';
                                                    } else if (dir == 'east' || dir == 'west') {
                                                        geoCell.y = parseFloat(geoCell.x) - 0.0625;
                                                        if (dir == 'east') {
                                                            dir = 'south';
                                                            geoCell.x = 0 - 0.0625;
                                                        } else {
                                                            dir = 'north';
                                                            geoCell.x = 1 + 0.0625;
                                                        }
                                                        cell.setGeometry(geoCell);
                                                    }
                                                } else if (cell.value == 'ControlPort') {
                                                    var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east';
                                                    var geoCell = cell.getGeometry();
                                                    if (dir == 'south' || dir == 'north') {
                                                        var temp = geoCell.x;
                                                        geoCell.x = geoCell.y - 0.0625;
                                                        geoCell.y = temp + 0.0625;
                                                        cell.setGeometry(geoCell);
                                                        if (dir == 'south')
                                                            dir = 'west';
                                                        else
                                                            dir = 'east';
                                                    } else if (dir == 'east' || dir == 'west') {
                                                        geoCell.y = parseFloat(geoCell.x) + 0.0625;
                                                        if (dir == 'east') {
                                                            dir = 'south';

                                                            geoCell.x = 1 + 0.0625;
                                                        } else {
                                                            dir = 'north';
                                                            geoCell.x = 0 - 0.0625;
                                                        }
                                                        cell.setGeometry(geoCell);
                                                    }
                                                }
                                            } else {
                                                var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east';

                                                if (dir == 'east') {
                                                    dir = 'south';
                                                } else if (dir == 'south') {
                                                    dir = 'west';
                                                } else if (dir == 'west') {
                                                    dir = 'north';
                                                } else if (dir == 'north') {
                                                    dir = 'east';
                                                }
                                            }
                                            graph.setCellStyles(mxConstants.STYLE_DIRECTION, dir, [cell]);
                                        }
                                    }
                                }
                            }
                        } finally {
                            graph.getModel().endUpdate();
                        }
                    }
                }, null, null, 'Ctrl+R');


                // @jiteshjha, @pooja
                /*
                   On selection and deletion of any block, 'deleteBlock'
                   function deletes all the associated edges with that block.
                   Used Preorder traversal for edges.
                */
                editor.addAction('deleteBlock', function(editor, cell) {
                    var cells = [];
                    var selectionCells = graph.getSelectionCells();
                    for (var k = 0; k < selectionCells.length; k++) {
                        var portCount = selectionCells[k].getChildCount();
                        cells.push(selectionCells[k]);
                        // Finds all the port with edges of the selected cell, and calls getEdgeId() for
                        // each edge object of that port.
                        for (var i = 0; i < portCount; i++) {
                            var edgeCount = selectionCells[k].getChildAt(i).getEdgeCount();
                            if (edgeCount != 0) {
                                getEdgeId(selectionCells[k].getChildAt(i));

                                for (var j = 0; j < edgeCount; j++) {
                                    var edgeObject = selectionCells[k].getChildAt(i).getEdgeAt(j);
                                    getEdgeId(edgeObject);
                                }
                            }
                        }
                    }


                    /* getEdgeId() find all the associated edges from an edge.
                     Pushes the object of that edge into an array of mxCell objects.
                     */
                    function getEdgeId(edgeObject) {
                        var cellStack = [];
                        if (edgeObject != null && edgeObject.isEdge() == true) {
                            cellStack.push(edgeObject);
                            while (cellStack.length != 0) {
                                var tempEdgeObject = cellStack.pop();
                                if (tempEdgeObject.edge == true && (cells.indexOf(tempEdgeObject) == -1)) {
                                    cells.push(tempEdgeObject);
                                }
                                for (var j = 0; j < tempEdgeObject.getEdgeCount(); j++) {
                                    cellStack.push(tempEdgeObject.getEdgeAt(j));
                                }
                            }
                        }
                    }

                    // The mxCells to be deleted are first highlighted,
                    // and then the selection is deleted in a single go.
                    graph.getSelectionModel().setCells(cells);
                    editor.execute('delete');
                });

                addToolbarButton(editor, toolbar, 'toggle', 'Expand All', 'images/navigate_plus.png');
                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'cut', 'Cut', 'images/cut.png');
                addToolbarButton(editor, toolbar, 'copy', 'Copy', 'images/copy.png');
                addToolbarButton(editor, toolbar, 'paste', 'Paste', 'images/paste.png');

                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'undoCustom', '', 'images/undo.png');
                addToolbarButton(editor, toolbar, 'redoCustom', '', 'images/redo.png');
                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'show', 'Show', 'images/camera.png');
                addToolbarButton(editor, toolbar, 'print', 'Print', 'images/printer.png');

                toolbar.appendChild(spacer.cloneNode(true));


                /*
                    Maverick
                    This method is used for loading the stylesheet from the file.
                    Reference: http://www.w3schools.com/xsl/xsl_client.asp
	        */

                function loadXMLDoc(filename) {
                    if (window.ActiveXObject) {
                        xhttp = new ActiveXObject("Msxml2.XMLHTTP");
                    } else {
                        xhttp = new XMLHttpRequest();
                    }
                    xhttp.open("GET", filename, false);
                    try {
                        xhttp.responseType = "msxml-document"
                    } catch (err) {}
                    xhttp.send("");
                    return xhttp.responseXML;
                }


                /*              
				Maverick
                The Export buttons in toolbar call this function with varying
                arguments. 
                The third argument is used to decide which button is being 
                pressed.
				exportXML : 2 arguments
				exportXcos: 3 arguments
                */
                function displayXMLorXcos() {
                    var textarea = document.createElement('textarea');
                    textarea.style.width = '400px';
                    textarea.style.height = '400px';

                    var enc = new mxCodec(mxUtils.createXmlDocument());
                    var node = enc.encode(arguments[0].graph.getModel());


                    //console.log(mxUtils.getPrettyXml(node));
                    textarea.value = mxUtils.getPrettyXml(node);


                    if (arguments[2] == null) {
                        showModalWindow(graph, 'XML', textarea, 410, 440);
                    } else {
                        xmlFromExportXML = mxUtils.getXml(node);
                        return xmlFromExportXML;
                    }
                }

                // Defines a new export action
                editor.addAction('exportXML', function(editor, cell) {
                    //Only two parameters passed here.
                    displayXMLorXcos(editor, cell);
                });

                /* Maverick
                 Reference: http://www.w3schools.com/xsl/xsl_client.asp
                */

                editor.addAction('exportXcos', function(editor, cell) {
                    //Mind the 3 parameters.
                    var xmlFromExportXML = displayXMLorXcos(editor, cell, true);
                    if (xmlFromExportXML == null) alert('First create the XML file.');
                    else {
                        /* 
                         Maverick
                         Adding <mxGraphModel> tag to make up for the missing tag.
                        */

                        var xml = mxUtils.parseXml("<mxGraphModel>" + xmlFromExportXML + "</mxGraphModel>");

                        var xsl = loadXMLDoc("finalmodsheet.xsl");

                        xsltProcessor = new XSLTProcessor();
                        xsltProcessor.importStylesheet(xsl);
                        resultDocument = xsltProcessor.transformToDocument(xml);


                        var textarea = document.createElement('textarea');
                        textarea.style.width = '400px';
                        textarea.style.height = '400px';
                        /*
                            Maverick
                            Using resultDocument.documentElement to remove an additional tag "<#document>" created by the XSLTProcessor.
                        */
                        textarea.value = mxUtils.getPrettyXml(resultDocument.documentElement);
                        showModalWindow(graph, 'Xcos', textarea, 410, 440);
                    }
                });

                addToolbarButton(editor, toolbar, 'exportXML', 'Export XML', 'images/export1.png');

                addToolbarButton(editor, toolbar, 'exportXcos', 'Export Xcos', 'images/export1.png');

                // Adds toolbar buttons into the status bar at the bottom
                // of the window.

                addToolbarButton(editor, status, 'zoomIn', '', 'images/zoom_in.png', true);
                addToolbarButton(editor, status, 'zoomOut', '', 'images/zoom_out.png', true);
                addToolbarButton(editor, status, 'actualSize', '', 'images/view_1_1.png', true);
                addToolbarButton(editor, status, 'fit', '', 'images/fit_to_size.png', true);

                // Creates the outline (navigator, overview) for moving
                // around the graph in the top, right corner of the window.
                var outln = new mxOutline(graph, outline);

                // To show the images in the outline, uncomment the following code
                //outln.outline.labelsVisible = true;
                //outln.outline.setHtmlLabels(true);

                // Fades-out the splash screen after the UI has been loaded.
                var splash = document.getElementById('splash');
                if (splash != null) {
                    try {
                        mxEvent.release(splash);
                        mxEffects.fadeOut(splash, 100, true);
                    } catch (e) {

                        // mxUtils is not available (library not loaded)
                        splash.parentNode.removeChild(splash);
                    }
                }

                // Handles cursor keys - guides.html
                var nudge = function(keyCode) {
                    if (!graph.isSelectionEmpty()) {
                        var dx = 0;
                        var dy = 0;
                        if (keyCode == 37) {
                            dx = -1;
                        } else if (keyCode == 38) {
                            dy = -1;
                        } else if (keyCode == 39) {
                            dx = 1;
                        } else if (keyCode == 40) {
                            dy = 1;
                        }
                        graph.moveCells(graph.getSelectionCells(), dx, dy);
                    }
                };
                // Transfer initial focus to graph container for keystroke handling
                // graph.container.focus();
                // Handles keystroke events
                var keyHandler = new mxKeyHandler(graph);
                keyHandler.bindKey(37, function() {
                    nudge(37);
                });
                keyHandler.bindKey(38, function() {
                    nudge(38);
                });
                keyHandler.bindKey(39, function() {
                    nudge(39);
                });
                keyHandler.bindKey(40, function() {
                    nudge(40);
                });

                // Starts connections on the background in wire-mode
                var connectionHandlerIsStartEvent = graph.connectionHandler.isStartEvent;
                graph.connectionHandler.isStartEvent = function(me) {
                    return connectionHandlerIsStartEvent.apply(this, arguments);
                };

                // Avoids any connections for gestures within tolerance except when in wire-mode
                // or when over a port
                var connectionHandlerMouseUp = graph.connectionHandler.mouseUp;
                graph.connectionHandler.mouseUp = function(sender, me) {
                    if (this.first != null && this.previous != null) {
                        var point = mxUtils.convertPoint(this.graph.container, me.getX(), me.getY());
                        var dx = Math.abs(point.x - this.first.x);
                        var dy = Math.abs(point.y - this.first.y);

                        if (dx < this.graph.tolerance && dy < this.graph.tolerance) {
                            // Selects edges in non-wire mode for single clicks, but starts
                            // connecting for non-edges regardless of wire-mode
                            if (this.graph.getModel().isEdge(this.previous.cell)) {
                                this.reset();
                            }

                            return;
                        }
                    }

                    connectionHandlerMouseUp.apply(this, arguments);
                };

                mxEvent.disableContextMenu(container);

                // @Adhitya: Add focus to a mxCell
                if (mxClient.IS_NS) {
                    mxEvent.addListener(graph.container, 'mousedown', function(evt) {
                        if (!graph.isEditing()) {
                            graph.container.setAttribute('tabindex', '-1');
                            graph.container.focus();
                        }
                    });
                }

            }
        };


        function showPropertiesWindow(graph, cell) {

            var defaultProperties = {
                nbr_curves: ["Number of curves", 1],
                clrs: ["color (>0) or mark (<0)", [1, 2, 3, 4, 5, 6, 7, 13]],
                siz: ["line or mark size", [1, 1, 1, 1, 1, 1, 1, 1]],
                win: ["Output window number (-1 for automatic)", -1],
                wpos: ["Output window position", [-1, -1]],
                wdim: ["Output window sizes", [-1, -1]],
                vec_x: ["Xmin and Xmax", [-15, 15]],
                vec_y: ["Ymin and Ymax", [-15, 15]],
                vec_z: ["Zmin and Zmax", [-15, 15]],
                param3ds: ["Alpha and Theta", [50, 280]],
                N: ["Buffer size", 2]
            };

            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "contentProperties");

            // Heading of content
            var heading = document.createElement('h2');
            heading.innerHTML = "Set Scope Parameters";
            heading.id = "headingProperties"
            content.appendChild(heading);

            // Add Form
            var myform = document.createElement("form");
            myform.method = "post";
            myform.id = "formProperties";

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            for (var key in defaultProperties) {
                if (defaultProperties.hasOwnProperty(key)) {

                    // Input Title
                    var fieldName = defaultProperties[key];
                    var namelabel = document.createElement('label');
                    namelabel.innerHTML = defaultProperties[key][0];
                    myform.appendChild(namelabel);

                    // Input
                    var input = document.createElement("input");
                    input.name = key;
                    input.value = defaultProperties[key][1];
                    input.setAttribute("id", key.toString());
                    input.setAttribute("class", "fieldInput");
                    myform.appendChild(input);

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);
                }
            }

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Submit';
            btn.type = "button";
            btn.name = "submit";

            // Executes when button 'btn' is clicked
            btn.onclick = function() {
                var propertiesObject = {
                    id: cell.id
                };

                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        propertiesObject[key] = document.getElementById(key.toString()).value;
                    }
                }
            };
            myform.appendChild(btn);

            // Button - Reset
            var btn = document.createElement("button");
            btn.innerHTML = 'Reset';
            btn.type = "button";
            btn.name = "submit";
            btn.id = "resetButtonProperties";
            btn.onclick = function() {
                // Reset
                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        var element = document.getElementById(key.toString());
                        element.value = defaultProperties[key][1];
                    }
                }
            };

            myform.appendChild(btn);
            // Base height without fields : 135 px
            height = 135 + 26 * defaultProperties.length + 15;

            content.appendChild(myform);
            showModalWindow(graph, 'Properties', content, 450, height);
        };



        function showColorWheel(graph, cell, selectProperty) {

            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "colorProperties");

            // Add Form
            var myform = document.createElement("form");
            myform.method = "";
            myform.setAttribute("id", "formProperties");

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Input Title
            var fieldName = 'Color';
            var namelabel = document.createElement('label');
            namelabel.innerHTML = fieldName;
            myform.appendChild(namelabel);

            // Input
            var input = document.createElement("input");
            input.name = fieldName;
            input.value = 0;
            input.style.cssText = 'float: right;';
            input.setAttribute("id", "color");
            myform.appendChild(input);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);
            var picker = document.createElement('div');
            picker.setAttribute("id", "picker");
            myform.appendChild(picker);
            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Submit';
            btn.type = "button";
            btn.name = "submit";
            btn.style.cssText = 'margin-left: 75px';

            // Executes when button 'btn' is clicked
            btn.onclick = function() {
                var input = document.getElementById('color').value;
                if (selectProperty == "edgeStrokeColor") {
                    var style = graph.getModel().getStyle(cell);
                    if (style == null) {
                        style = 'strokeColor=' + input;
                        graph.getModel().setStyle(cell, style);
                    } else {
                        style = style.replace(/strokeColor=#[a-fA-F0-9]{6,}/g, "strokeColor=" + input);
                        graph.getModel().setStyle(cell, style);
                    }
                } else if (selectProperty == "bgColor") {
                    graph.container.style.backgroundColor = input;
                } else if (selectProperty == "vertexStrokeColor") {
                    var style = graph.getModel().getStyle(cell);
                    if (style.indexOf('strokeColor') > -1) {
                        style = style.replace(/strokeColor=#[a-fA-F0-9]{6,}/g, "strokeColor=" + input);
                        graph.getModel().setStyle(cell, style);
                    } else {
                        style = style + ';' + 'strokeColor=' + input;
                        graph.getModel().setStyle(cell, style);
                    }
                } else if (selectProperty == "vertexFillColor") {
                    var style = graph.getModel().getStyle(cell);
                    if (style.indexOf('fillColor') > -1) {
                        style = style.replace(/fillColor=#[a-fA-F0-9]{6,}/g, "fillColor=" + input);
                        graph.getModel().setStyle(cell, style);
                    } else {
                        style = style + ';' + 'fillColor=' + input;
                        graph.getModel().setStyle(cell, style);
                    }
                }



            };
            myform.appendChild(btn);

            content.appendChild(myform);
            showModalWindow(graph, 'Diagram background...', content, 285, 340);
            // Invokes the farbtastic functionality 
            $(document).ready(function() {
                $('#picker').farbtastic('#color');
            });
        };

        function createButtonImage(button, image) {
            if (image != null) {
                var img = document.createElement('img');
                img.setAttribute('src', image);
                img.style.width = '16px';
                img.style.height = '16px';
                img.style.verticalAlign = 'middle';
                img.style.marginRight = '2px';
                button.appendChild(img);
            }
        }

        function addIcons(graph, sidebar) {
            var req = mxUtils.load('palettes/palettes.xml');
            var root = req.getDocumentElement();
            var x = root.getElementsByTagName('node')[0];
            var categories = x.getElementsByTagName('node');
            for (var i = 0, nodeLength = categories.length; i < nodeLength; i++) {
                var categoryName = categories[i].getAttribute('name');
                var title = document.createElement('h3');
                title.setAttribute('class', 'accordion-header ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all');
                var span = document.createElement('span');
                span.setAttribute('class', 'ui-accordion-header-icon ui-icon ui-icon-triangle-1-e');
                var titleName = document.createTextNode(categoryName);
                title.appendChild(span);
                title.appendChild(titleName);
                sidebar.appendChild(title);
                var newImages = document.createElement('div');
                newImages.setAttribute('class', 'ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom');
                var blocks = categories[i].getElementsByTagName('block');
                for (var j = 0, blockLength = blocks.length; j < blockLength; j++) {
                    var name = blocks[j].getAttribute('name');
                    var icon = blocks[j].getElementsByTagName('icon')[0];
                    var iconPath = icon.getAttribute('path');
                    addSidebarIcon(graph, newImages, name, iconPath);
                }
                sidebar.appendChild(newImages);
            }
        }

        function getImgHTML(name) {
            return '<img src="' + 'blocks/' + name + '.svg' + '" height="80" width="80">';
        }

        function addToolbarButton(editor, toolbar, action, label, image, isTransparent) {
            var button = document.createElement('button');
            button.style.fontSize = '10';
            createButtonImage(button, image);
            if (isTransparent) {
                button.style.background = 'transparent';
                button.style.color = '#FFFFFF';
                button.style.border = 'none';
            }
            mxEvent.addListener(button, 'click', function(evt) {
                editor.execute(action);
            });
            mxUtils.write(button, label);
            button.setAttribute('id', action);
            toolbar.appendChild(button);
        };

        function showModalWindow(graph, title, content, width, height) {
            var background = document.createElement('div');
            background.style.position = 'absolute';
            background.style.left = '0px';
            background.style.top = '0px';
            background.style.right = '0px';
            background.style.bottom = '0px';
            background.style.background = 'black';
            mxUtils.setOpacity(background, 50);
            document.body.appendChild(background);

            if (mxClient.IS_IE) {
                new mxDivResizer(background);
            }

            var x = Math.max(0, document.body.scrollWidth / 2 - width / 2);
            var y = Math.max(10, (document.body.scrollHeight || document.documentElement.scrollHeight) / 2 - height * 2 / 3);
            var wnd = new mxWindow(title, content, x, y, width, height, false, true);
            wnd.setClosable(true);

            // Fades the background out after after the window has been closed
            wnd.addListener(mxEvent.DESTROY, function(evt) {
                graph.setEnabled(true);
                mxEffects.fadeOut(background, 50, true, 10, 30, true);
            });

            graph.setEnabled(false);
            graph.tooltipHandler.hide();
            wnd.setVisible(true);
        };

        function addSidebarIcon(graph, sidebar, name, image) {

            // Function that is executed when the image is dropped on
            // the graph. The cell argument points to the cell under
            // the mousepointer if there is one.
            var funct = function(graph, evt, cell, x, y) {
                var parent = graph.getDefaultParent();
                var model = graph.getModel();
                var v1 = null;
                var doc = mxUtils.createXmlDocument();
                model.beginUpdate();
                try {
                    var label = getImgHTML(name); // Will not exist for all blocks

                    if (name == 'ANDBLK') {
                        var details = ANDBLK("define");
                        var enc = new mxCodec(mxUtils.createXmlDocument());
                        var node = enc.encode(details);
                        //node.setAttribute('label',label);
                        v1 = graph.insertVertex(parent, null, node, x, y, 80, 80, 'ANDBLK');
                        createPorts(graph, v1, [], ['CONTROL', 'CONTROL'], [], ['COMMAND']);
                    } else if (name == 'CMSCOPE') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'CMSCOPE');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], ['CONTROL'], [], []);
                    } else if (name == 'CONST_m') {
                        var details = CONST_m("define");
                        var enc = new mxCodec(mxUtils.createXmlDocument());
                        var node = enc.encode(details);
                        v1 = graph.insertVertex(parent, null, node, x, y, 80, 80, 'CONST_m');
                        createPorts(graph, v1, [], [], ['EXPLICIT'], []);
                    } else if (name == 'CONVERT') {
                        v1 = graph.insertVertex(parent, null, 'Convert to', x, y, 80, 80, 'CONVERT');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'CSCOPXY') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'CSCOPXY');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], ['CONTROL'], [], []);
                    } else if (name == 'DEMUX') {
                        v1 = graph.insertVertex(parent, null, '', x, y, 80, 80, 'DEMUX');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT', 'EXPLICIT'], []);
                    } else if (name == 'IN_f') {
                        v1 = graph.insertVertex(parent, null, '1', x, y, 80, 80, 'IN_f');
                        createPorts(graph, v1, [], [], ['EXPLICIT'], []);
                    } else if (name == 'LOGICAL_OP') {
                        v1 = graph.insertVertex(parent, null, 'AND', x, y, 80, 80, 'LOGICAL_OP');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'MUX') {
                        v1 = graph.insertVertex(parent, null, '', x, y, 80, 80, 'MUX');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'NRMSOM_f') {
                        v1 = graph.insertVertex(parent, null, '', x, y, 80, 80, 'NRMSOM_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'OUT_f') {
                        v1 = graph.insertVertex(parent, null, '1', x, y, 80, 80, 'OUT_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], [], []);
                    } else if (name == 'RELATIONALOP') {
                        v1 = graph.insertVertex(parent, null, '<FONT SIZE="6"><</FONT>', x, y, 80, 80, 'RELATIONALOP');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SWITCH2_m') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'SWITCH2_m');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    }

                    // CONTINUOUS
                    else if (name == 'CLINDUMMY_f') {
                        v1 = graph.insertVertex(parent, null, 'DUMMY<BR>CLSS', x, y, 80, 80, 'CLINDUMMY_f');
                        createPorts(graph, v1, [], [], [], []);
                    } else if (name == 'CLR') {
                        v1 = graph.insertVertex(parent, null, '1<BR><HR>1 + s', x, y, 80, 80, 'CLR');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'CLSS') {
                        v1 = graph.insertVertex(parent, null, '<TABLE><TR><TD ALIGN="RIGHT">xd</TD><TD>=</TD><TD>Ax+Bu</TD></TR><TR><TD ALIGN="RIGHT">y</TD><TD>=</TD><TD>Cx+Du</TD></TR></TABLE>', x, y, 130, 80, 'CLSS');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'DERIV') {
                        v1 = graph.insertVertex(parent, null, 'du / dt', x, y, 80, 80, 'DERIV');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'INTEGRAL_f') {
                        v1 = graph.insertVertex(parent, null, '1/s', x, y, 80, 80, 'INTEGRAL_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'INTEGRAL_m') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'INTEGRAL_m');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'PID') {
                        v1 = graph.insertVertex(parent, null, 'PID', x, y, 80, 80, 'PID');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'TCLSS') {
                        v1 = graph.insertVertex(parent, null, 'Jump<BR>(A,B,C,D)', x, y, 80, 80, 'TCLSS');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'TIME_DELAY') {
                        v1 = graph.insertVertex(parent, null, 'Continuous<BR>fix delay', x, y, 80, 80, 'TIME_DELAY');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'VARIABLE_DELAY') {
                        v1 = graph.insertVertex(parent, null, 'Variable<BR>delay', x, y, 80, 80, 'VARIABLE_DELAY');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'PDE') {
                        v1 = graph.insertVertex(parent, null, 'PDE', x, y, 80, 80, 'PDE');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT', 'EXPLICIT', 'EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT', 'EXPLICIT'], []);
                    }

                    // DISCONTINUOUS
                    else if (name == 'BACKLASH') {
                        v1 = graph.insertVertex(parent, null, 'Backlash', x, y, 80, 80, 'BACKLASH');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'DEADBAND') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'DEADBAND');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'DELAYV_f') {
                        v1 = graph.insertVertex(parent, null, 'Variable<BR>delay', x, y, 80, 80, 'DELAYV_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], ['CONTROL'], ['EXPLICIT'], ['COMMAND', 'COMMAND']);
                    } else if (name == 'HYSTHERESIS') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'HYSTHERESIS');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'RATELIMITER') {
                        v1 = graph.insertVertex(parent, null, 'Rate limiter', x, y, 80, 80, 'RATELIMITER');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'QUANT_f') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'QUANT_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SATURATION') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'SATURATION');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    }

                    // DISCRETE
                    else if (name == 'AUTOMAT') {
                        v1 = graph.insertVertex(parent, null, 'Automaton<BR>nM=2, nX=1', x, y, 80, 80, 'AUTOMAT');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT', 'EXPLICIT'], ['COMMAND']);
                    } else if (name == 'DELAY_f') {
                        v1 = graph.insertVertex(parent, null, 'Delay', x, y, 80, 80, 'DELAYV_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'DLR') {
                        v1 = graph.insertVertex(parent, null, '1<BR><HR>1 + z', x, y, 80, 80, 'DLR');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'DLRADAPT_f') {
                        v1 = graph.insertVertex(parent, null, 'N(z,p)<BR><HR>D(z,p)', x, y, 80, 80, 'DLRADAPT_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'DLSS') {
                        v1 = graph.insertVertex(parent, null, '<TABLE><TR><TD ALIGN="RIGHT">x</TD><TD ALIGN="CENTER">+=</TD><TD>Ax+Bu</TD></TR><TR><TD ALIGN="RIGHT">y</TD><TD ALIGN="CENTER">=</TD><TD>Cx+Du</TD></TR></TABLE>', x, y, 80, 80, 'DLSS');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'DOLLAR_f') {
                        v1 = graph.insertVertex(parent, null, '1/z', x, y, 80, 80, 'DOLLAR_f');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'DOLLAR') {
                        v1 = graph.insertVertex(parent, null, '1/z', x, y, 80, 80, 'DOLLAR');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'DOLLAR_m') {
                        v1 = graph.insertVertex(parent, null, '1/z', x, y, 80, 80, 'DOLLAR_m');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'SAMPHOLD_m') {
                        v1 = graph.insertVertex(parent, null, 'S / H', x, y, 80, 80, 'SAMPHOLD_m');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'REGISTER') {
                        v1 = graph.insertVertex(parent, null, 'Shift<BR>register', x, y, 80, 80, 'REGISTER');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], ['EXPLICIT'], []);
                    }

                    // EVENTS
                    else if (name == 'CLOCK_c') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'CLOCK_c');
                        createPorts(graph, v1, [], [], [], ['COMMAND']);
                    } else if (name == 'SampleCLK') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'SampleCLK');
                        createPorts(graph, v1, [], [], [], ['COMMAND']);
                    } else if (name == 'VirtualCLK0') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'VirtualCLK0');
                        createPorts(graph, v1, [], ['CONTROL'], [], []);
                    }
                    // ANDBLK to come here
                    else if (name == 'ANDLOG_f') {
                        v1 = graph.insertVertex(parent, null, 'LOGICAL<BR>AND', x, y, 80, 80, 'ANDLOG_f');
                        createPorts(graph, v1, [], ['CONTROL', 'CONTROL'], ['EXPLICIT'], []);
                    } else if (name == 'CEVENTSCOPE') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'CEVENTSCOPE');
                        createPorts(graph, v1, [], ['CONTROL'], [], []);
                    } else if (name == 'CLKFROM') {
                        v1 = graph.insertVertex(parent, null, 'A', x, y, 80, 80, 'CLKFROM');
                        createPorts(graph, v1, [], [], [], ['COMMAND']);
                    } else if (name == 'CLKGOTO') {
                        v1 = graph.insertVertex(parent, null, 'A', x, y, 80, 80, 'CLKGOTO');
                        createPorts(graph, v1, [], ['CONTROL'], [], []);
                    } else if (name == 'CLKGotoTagVisibility') {
                        v1 = graph.insertVertex(parent, null, '{A}', x, y, 80, 80, 'CLKGotoTagVisibility');
                        createPorts(graph, v1, [], [], [], []);
                    } else if (name == 'CLKOUTV_f') {
                        v1 = graph.insertVertex(parent, null, '1', x, y, 80, 80, 'CLKOUTV_f');
                        createPorts(graph, v1, [], ['CONTROL'], [], []);
                    } else if (name == 'CLKSOMV_f') {
                        v1 = graph.insertVertex(parent, null, '+', x, y, 80, 80, 'CLKSOMV_f');
                        createPorts(graph, v1, [], ['CONTROL', 'CONTROL', 'CONTROL'], [], ['COMMAND']);
                    } else if (name == 'EDGE_TRIGGER') {
                        v1 = graph.insertVertex(parent, null, 'Edge<BR>trigger', x, y, 80, 80, 'EDGE_TRIGGER');
                        createPorts(graph, v1, ['EXPLICIT'], [], [], ['COMMAND']);
                    } else if (name == 'ENDBLK') {
                        v1 = graph.insertVertex(parent, null, 'END', x, y, 80, 80, 'ENDBLK');
                        createPorts(graph, v1, [], [], [], []);
                    } else if (name == 'END_c') {
                        v1 = graph.insertVertex(parent, null, 'END', x, y, 80, 80, 'END_c');
                        createPorts(graph, v1, [], ['CONTROL'], [], ['COMMAND']);
                    } else if (name == 'ESELECT_f') {
                        v1 = graph.insertVertex(parent, null, 'Event select', x, y, 80, 80, 'ESELECT_f');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], [], ['COMMAND', 'COMMAND']);
                    } else if (name == 'EVTDLY_c') {
                        v1 = graph.insertVertex(parent, null, 'Delay: 0.1', x, y, 80, 80, 'EVTDLY_c');
                        createPorts(graph, v1, [], ['CONTROL'], [], ['COMMAND']);
                    } else if (name == 'EVTGEN_f') {
                        v1 = graph.insertVertex(parent, null, 'Event at<BR>time 0', x, y, 80, 80, 'EVTGEN_f');
                        createPorts(graph, v1, [], [], [], ['COMMAND']);
                    } else if (name == 'EVTVARDLY') {
                        v1 = graph.insertVertex(parent, null, 'Event<BR>delay', x, y, 80, 80, 'EVTVARDLY');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], [], ['COMMAND']);
                    } else if (name == 'Extract_Activation') {
                        v1 = graph.insertVertex(parent, null, 'Extract<BR>activation', x, y, 80, 80, 'Extract_Activation');
                        createPorts(graph, v1, ['EXPLICIT'], [], [], ['COMMAND']);
                    } else if (name == 'HALT_f') {
                        v1 = graph.insertVertex(parent, null, 'HALT', x, y, 80, 80, 'HALT_f');
                        createPorts(graph, v1, [], ['CONTROL'], [], []);
                    } else if (name == 'IFTHEL_f') {
                        v1 = graph.insertVertex(parent, null, 'if in>0<BR>then else', x, y, 80, 80, 'IFTHEL_f');
                        createPorts(graph, v1, ['EXPLICIT'], ['CONTROL'], [], ['COMMAND', 'COMMAND']);
                    } else if (name == 'M_freq') {
                        v1 = graph.insertVertex(parent, null, 'Multiple<BR>frequency', x, y, 80, 80, 'M_freq');
                        createPorts(graph, v1, [], ['CONTROL'], [], ['COMMAND', 'COMMAND', 'COMMAND']);
                    } else if (name == 'MCLOCK_f') {
                        v1 = graph.insertVertex(parent, null, '2freq clock<BR>f/n f', x, y, 80, 80, 'MCLOCK_f');
                        createPorts(graph, v1, [], [], [], ['COMMAND', 'COMMAND']);
                    } else if (name == 'MFCLCK_f') {
                        v1 = graph.insertVertex(parent, null, 'M. freq<BR>clock', x, y, 80, 80, 'MFCLCK_f');
                        createPorts(graph, v1, [], ['CONTROL'], [], ['COMMAND', 'COMMAND']);
                    } else if (name == 'freq_div') {
                        v1 = graph.insertVertex(parent, null, 'Frequency<BR>division', x, y, 80, 80, 'freq_div');
                        createPorts(graph, v1, [], ['CONTROL'], [], ['COMMAND']);
                    }
                    // LOOKUP TABLES
                    else if (name == 'INTRP2BLK_f') {
                        v1 = graph.insertVertex(parent, null, 'Interp 2', x, y, 80, 80, 'INTRP2BLK_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'INTRPLBLK_f') {
                        v1 = graph.insertVertex(parent, null, 'Interp', x, y, 80, 80, 'INTRPLBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'LOOKUP_f') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'LOOKUP_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    }
                    // MATHEMATICAL OPERATIONS
                    else if (name == 'ABS_VALUE') {
                        v1 = graph.insertVertex(parent, null, 'ABS', x, y, 80, 80, 'ABS_VALUE');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'BIGSOM_f') {
                        v1 = graph.insertVertex(parent, null, label, x, y, 80, 80, 'BIGSOM_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'COSBLK_f') {
                        v1 = graph.insertVertex(parent, null, 'COS', x, y, 80, 80, 'COSBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'EXPBLK_m') {
                        v1 = graph.insertVertex(parent, null, 'a^u', x, y, 80, 80, 'EXPBLK_m');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'GAINBLK_f') {
                        v1 = graph.insertVertex(parent, null, '1', x, y, 80, 80, 'GAINBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'GAINBLK') {
                        v1 = graph.insertVertex(parent, null, '1', x, y, 80, 80, 'GAINBLK');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'GAIN_f') {
                        v1 = graph.insertVertex(parent, null, '1', x, y, 80, 80, 'GAIN_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'INVBLK') {
                        v1 = graph.insertVertex(parent, null, '1/u', x, y, 80, 80, 'INVBLK');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'LOGBLK_f') {
                        v1 = graph.insertVertex(parent, null, 'LOG', x, y, 80, 80, 'LOGBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'MATMAGPHI') {
                        v1 = graph.insertVertex(parent, null, 'Mag & Phi', x, y, 80, 80, 'MATMAGPHI');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT', 'EXPLICIT'], []);
                    } else if (name == 'MATZREIM') {
                        v1 = graph.insertVertex(parent, null, 'Re & Im', x, y, 80, 80, 'MATZREIM');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT', 'EXPLICIT'], []);
                    } else if (name == 'MAXMIN') {
                        v1 = graph.insertVertex(parent, null, 'MAX', x, y, 80, 80, 'MAXMIN');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'MAX_f') {
                        v1 = graph.insertVertex(parent, null, 'MAX', x, y, 80, 80, 'MAX_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'MIN_f') {
                        v1 = graph.insertVertex(parent, null, 'MIN', x, y, 80, 80, 'MIN_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'POWBLK_f') {
                        v1 = graph.insertVertex(parent, null, 'u^a', x, y, 80, 80, 'POWBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'PRODUCT') {
                        v1 = graph.insertVertex(parent, null, '<TABLE><TR><TD>*</TD><TD ROWSPAN="2"><FONT SIZE="6">∏</FONT><TD></TR><TR><TD>÷</TD><TD/></TR></TABLE>', x, y, 80, 80, 'PRODUCT');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'PROD_f') {
                        v1 = graph.insertVertex(parent, null, 'X', x, y, 80, 80, 'PROD_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SIGNUM') {
                        v1 = graph.insertVertex(parent, null, 'SIGN', x, y, 80, 80, 'SIGNUM');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SINBLK_f') {
                        v1 = graph.insertVertex(parent, null, 'SIN', x, y, 80, 80, 'SINBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SQRT') {
                        v1 = graph.insertVertex(parent, null, 'SQRT', x, y, 80, 80, 'SQRT');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SUMMATION') {
                        v1 = graph.insertVertex(parent, null, '<TABLE><TR><TD>+</TD> <TD ROWSPAN="2"><FONT SIZE="6">∑</FONT><TD></TR><TR><TD>-</TD> <TD/></TR></TABLE>', x, y, 80, 80, 'SUMMATION');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SUM_f') {
                        v1 = graph.insertVertex(parent, null, '+', x, y, 80, 80, 'SUM_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'SOM_f') {
                        v1 = graph.insertVertex(parent, null, '+', x, y, 80, 80, 'SOM_f');
                        createPorts(graph, v1, ['EXPLICIT', 'EXPLICIT', 'EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'TANBLK_f') {
                        v1 = graph.insertVertex(parent, null, 'TAN', x, y, 80, 80, 'TANBLK_f');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    } else if (name == 'TrigFun') {
                        v1 = graph.insertVertex(parent, null, 'Trig function', x, y, 80, 80, 'TrigFun');
                        createPorts(graph, v1, ['EXPLICIT'], [], ['EXPLICIT'], []);
                    }
                    // MATRIX
                    else if (name == 'OpAmp') {
                        v1 = graph.insertVertex(parent, null, '<table><tr><td>+</td><td></td></tr><tr><td></td><td>OP</td></tr><tr><td>-</td><td></td></tr></table>', x, y, 80, 80, 'OpAmp');
                        createPorts(graph, v1, ['IMPLICIT', 'IMPLICIT'], [], ['IMPLICIT'], []);
                    } else if (name == 'TEXT_f') {
                        v1 = graph.insertVertex(parent, null, '', x, y, 80, 80, 'TEXT_f');
                        createPorts(graph, v1, [], [], [], []);
                    }

                    v1.setConnectable(false);

                } finally {
                    model.endUpdate();
                }

                graph.setSelectionCell(v1);
            }

            var para = document.createElement('p');
            var blockFigure = document.createElement('figure');
            var img = document.createElement('img');
            img.setAttribute('src', image);
            var caption = document.createElement('figcaption');
            var blockName = document.createTextNode(name);
            caption.appendChild(blockName);
            blockFigure.appendChild(img);
            blockFigure.appendChild(caption);
            para.appendChild(blockFigure);
            sidebar.appendChild(para);

            var dragElt = document.createElement('div');
            dragElt.style.border = 'dashed black 1px';
            dragElt.style.width = '80px';
            dragElt.style.height = '80px';

            // Creates the image which is used as the drag icon (preview)
            var ds = mxUtils.makeDraggable(img, graph, funct, dragElt, 0, 0, true, true);
            ds.setGuidesEnabled(true);
        };

        // Create ports
        function createPorts(graph, block, left, top, right, bottom) {
            createInputPorts(graph, block, left, top);
            createOutputPorts(graph, block, right, bottom);
        }

        function createInputPorts(graph, block, leftArray, topArray) {
            var topNumber = topArray.length;
            var leftNumber = leftArray.length;
            if (leftNumber != 0) {
                for (var i = 1; i <= leftNumber; i++) {
                    var x = 0;
                    var y = (i / (leftNumber + 1)).toFixed(4);
                    var portType = leftArray[i - 1];
                    createInputPort(graph, block, x, y, portType, 'left');
                }
            }
            if (topNumber != 0) {
                for (var i = 1; i <= topNumber; i++) {
                    var x = (i / (topNumber + 1)).toFixed(4);
                    var y = 0;
                    var portType = topArray[i - 1];
                    createInputPort(graph, block, x, y, portType, 'top');
                }
            }
        };

        function createOutputPorts(graph, block, rightArray, bottomArray) {
            var bottomNumber = bottomArray.length;
            var rightNumber = rightArray.length;
            if (rightNumber != 0) {
                for (var i = 1; i <= rightNumber; i++) {
                    var x = 1;
                    var y = (i / (rightNumber + 1)).toFixed(4);
                    var portType = rightArray[i - 1];
                    createOutputPort(graph, block, x, y, portType, 'right');
                }
            }
            if (bottomNumber != 0) {
                for (var i = 1; i <= bottomNumber; i++) {
                    var x = (i / (bottomNumber + 1)).toFixed(4);
                    var y = 1;
                    var portType = bottomArray[i - 1];
                    createOutputPort(graph, block, x, y, portType, 'bottom');
                }
            }
        };

        function createInputPort(graph, block, x, y, portType, position) {
            var port = null;
            if (portType == 'COMMAND') {
                port = graph.insertVertex(block, null, 'CommandPort', x, y, 10, 10, 'CommandPort', true);
            } else if (portType == 'CONTROL') {
                port = graph.insertVertex(block, null, 'ControlPort', x, y, 10, 10, 'ControlPort', true);
            } else if (portType == 'IMPLICIT') {
                port = graph.insertVertex(block, null, 'ImplicitInputPort', x, y, 10, 10, 'ImplicitInputPort', true);
            } else if (portType == 'EXPLICIT') {
                port = graph.insertVertex(block, null, 'ExplicitInputPort', x, y, 10, 10, 'ExplicitInputPort', true);
            }
            if (port != null) {
                if (position == 'top') {
                    port.geometry.offset = new mxPoint(-6, -10);
                } else if (position == 'left') {
                    port.geometry.offset = new mxPoint(-10, -6);
                }
            }
        };

        function createOutputPort(graph, block, x, y, portType, position) {
            var port = null;
            if (portType == 'COMMAND') {
                port = graph.insertVertex(block, null, 'CommandPort', x, y, 10, 10, 'CommandPort', true);
            } else if (portType == 'CONTROL') {
                port = graph.insertVertex(block, null, 'ControlPort', x, y, 10, 10, 'ControlPort', true);
            } else if (portType == 'IMPLICIT') {
                port = graph.insertVertex(block, null, 'ImplicitOutputPort', x, y, 10, 10, 'ImplicitOutputPort', true);
            } else if (portType == 'EXPLICIT') {
                port = graph.insertVertex(block, null, 'ExplicitOutputPort', x, y, 10, 10, 'ExplicitOutputPort', true);
            }
            if (port != null) {
                if (position == 'bottom') {
                    port.geometry.offset = new mxPoint(-6, 0);
                }
                if (position == 'right') {
                    port.geometry.offset = new mxPoint(0, -6);
                }
            }
        };

        function configureStylesheet(graph) {
            var req = mxUtils.load('styles/Xcos-style.xml');
            var root = req.getDocumentElement();
            var dec = new mxCodec(root.ownerDocument);
            dec.decode(root, graph.stylesheet);
            var style = graph.getStylesheet().getDefaultEdgeStyle();
            style['edgeStyle'] = 'wireEdgeStyle';
        };
    </script>
    <!--
    	Updates connection points before the routing is called.
    -->
    <script type="text/javascript">
        // Computes the position of edge to edge connection points.
        mxGraphView.prototype.updateFixedTerminalPoint = function(edge, terminal, source, constraint) {
            var pt = null;

            if (constraint != null) {
                pt = this.graph.getConnectionPoint(terminal, constraint);
            }

            if (source) {
                edge.sourceSegment = null;
            } else {
                edge.targetSegment = null;
            }

            if (pt == null) {
                var s = this.scale;
                var tr = this.translate;
                var orig = edge.origin;
                var geo = this.graph.getCellGeometry(edge.cell);
                pt = geo.getTerminalPoint(source);

                // Computes edge-to-edge connection point
                if (pt != null) {
                    pt = new mxPoint(s * (tr.x + pt.x + orig.x),
                        s * (tr.y + pt.y + orig.y));

                    // Finds nearest segment on edge and computes intersection
                    if (terminal != null && terminal.absolutePoints != null) {
                        var seg = mxUtils.findNearestSegment(terminal, pt.x, pt.y);

                        // Finds orientation of the segment
                        var p0 = terminal.absolutePoints[seg];
                        var pe = terminal.absolutePoints[seg + 1];
                        var horizontal = (p0.x - pe.x == 0);

                        // Stores the segment in the edge state
                        var key = (source) ? 'sourceConstraint' : 'targetConstraint';
                        var value = (horizontal) ? 'horizontal' : 'vertical';
                        edge.style[key] = value;

                        // Keeps the coordinate within the segment bounds
                        if (horizontal) {
                            pt.x = p0.x;
                            pt.y = Math.min(pt.y, Math.max(p0.y, pe.y));
                            pt.y = Math.max(pt.y, Math.min(p0.y, pe.y));
                        } else {
                            pt.y = p0.y;
                            pt.x = Math.min(pt.x, Math.max(p0.x, pe.x));
                            pt.x = Math.max(pt.x, Math.min(p0.x, pe.x));
                        }
                    }
                }
                // Computes constraint connection points on vertices and ports
                else if (terminal != null && terminal.cell.geometry.relative) {
                    pt = new mxPoint(this.getRoutingCenterX(terminal),
                        this.getRoutingCenterY(terminal));
                }
            }

            edge.setAbsoluteTerminalPoint(pt, source);
        };
    </script>

    <!--
      Overrides methods to preview and create new edges.
    -->
    <script type="text/javascript">
        // Sets source terminal point for edge-to-edge connections.
        mxConnectionHandler.prototype.createEdgeState = function(me) {
            var edge = this.graph.createEdge();

            if (this.sourceConstraint != null && this.previous != null) {
                edge.style = mxConstants.STYLE_EXIT_X + '=' + this.sourceConstraint.point.x + ';' +
                    mxConstants.STYLE_EXIT_Y + '=' + this.sourceConstraint.point.y + ';';
            } else if (this.graph.model.isEdge(me.getCell())) {
                var scale = this.graph.view.scale;
                var tr = this.graph.view.translate;
                var pt = new mxPoint(this.graph.snap(me.getGraphX() / scale) - tr.x,
                    this.graph.snap(me.getGraphY() / scale) - tr.y);
                edge.geometry.setTerminalPoint(pt, true);
            }

            return this.graph.view.createState(edge);
        };

        mxConnectionHandler.prototype.isStopEvent = function(me) {
            return me.getState() != null || mxEvent.isRightMouseButton(me.getEvent());
        };

        // Updates target terminal point for edge-to-edge connections.
        mxConnectionHandlerUpdateCurrentState = mxConnectionHandler.prototype.updateCurrentState;
        mxConnectionHandler.prototype.updateCurrentState = function(me) {
            mxConnectionHandlerUpdateCurrentState.apply(this, arguments);

            if (this.edgeState != null) {
                this.edgeState.cell.geometry.setTerminalPoint(null, false);

                if (this.shape != null && this.currentState != null &&
                    this.currentState.view.graph.model.isEdge(this.currentState.cell)) {
                    var scale = this.graph.view.scale;
                    var tr = this.graph.view.translate;
                    var pt = new mxPoint(this.graph.snap(me.getGraphX() / scale) - tr.x,
                        this.graph.snap(me.getGraphY() / scale) - tr.y);
                    this.edgeState.cell.geometry.setTerminalPoint(pt, false);
                }
            }
        };

        // Updates the terminal and control points in the cloned preview.
        mxEdgeSegmentHandler.prototype.clonePreviewState = function(point, terminal) {
            var clone = mxEdgeHandler.prototype.clonePreviewState.apply(this, arguments);
            clone.cell = clone.cell.clone();

            if (this.isSource || this.isTarget) {
                clone.cell.geometry = clone.cell.geometry.clone();

                // Sets the terminal point of an edge if we're moving one of the endpoints
                if (this.graph.getModel().isEdge(clone.cell)) {
                    clone.cell.geometry.setTerminalPoint(point, this.isSource);
                } else {
                    clone.cell.geometry.setTerminalPoint(null, this.isSource);
                }
            }

            return clone;
        };

        var mxEdgeHandlerConnect = mxEdgeHandler.prototype.connect;
        mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me) {
            var result = null;
            var model = this.graph.getModel();
            var parent = model.getParent(edge);

            model.beginUpdate();
            try {
                result = mxEdgeHandlerConnect.apply(this, arguments);
                var geo = model.getGeometry(result);

                if (geo != null) {
                    geo = geo.clone();
                    var pt = null;

                    if (model.isEdge(terminal)) {
                        pt = this.abspoints[(this.isSource) ? 0 : this.abspoints.length - 1];
                        pt.x = pt.x / this.graph.view.scale - this.graph.view.translate.x;
                        pt.y = pt.y / this.graph.view.scale - this.graph.view.translate.y;

                        var pstate = this.graph.getView().getState(
                            this.graph.getModel().getParent(edge));

                        if (pstate != null) {
                            pt.x -= pstate.origin.x;
                            pt.y -= pstate.origin.y;
                        }

                        pt.x -= this.graph.panDx / this.graph.view.scale;
                        pt.y -= this.graph.panDy / this.graph.view.scale;
                    }

                    geo.setTerminalPoint(pt, isSource);
                    model.setGeometry(edge, geo);
                }
            } finally {
                model.endUpdate();
            }

            return result;
        };
    </script>
    <!--
	    Adds in-place highlighting for complete cell area (no hotspot).
    -->
    <script type="text/javascript">
        mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
        mxConnectionHandler.prototype.createMarker = function() {
            var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);

            // Uses complete area of cell for new connections (no hotspot)
            marker.intersects = function(state, evt) {
                return true;
            };

            return marker;
        };

        mxEdgeHandlerCreateMarker = mxEdgeHandler.prototype.createMarker;
        mxEdgeHandler.prototype.createMarker = function() {
            var marker = mxEdgeHandlerCreateMarker.apply(this, arguments);

            // Adds in-place highlighting when reconnecting existing edges
            marker.highlight.highlight = this.graph.connectionHandler.marker.highlight.highlight;

            return marker;
        }
    </script>
    <!--
	   Implements a custom resistor shape. Direction currently ignored here.
    -->
    <script type="text/javascript">
        mxEdgeStyle.WireConnector = function(state, source, target, hints, result) {
            // Creates array of all way- and terminalpoints
            var pts = state.absolutePoints;
            var horizontal = true;
            var hint = null;

            // Gets the initial connection from the source terminal or edge
            if (source != null && state.view.graph.model.isEdge(source.cell)) {
                horizontal = state.style['sourceConstraint'] == 'horizontal';
            } else if (source != null) {
                horizontal = source.style['portConstraint'] != 'vertical';

                // Checks the direction of the shape and rotates
                var direction = source.style[mxConstants.STYLE_DIRECTION];

                if (direction == 'north' || direction == 'south') {
                    horizontal = !horizontal;
                }
            }

            // Adds the first point
            var pt = pts[0];

            if (pt == null && source != null) {
                pt = new mxPoint(state.view.getRoutingCenterX(source), state.view.getRoutingCenterY(source));
            } else if (pt != null) {
                pt = pt.clone();
            }

            var first = pt;

            // Adds the waypoints
            if (hints != null && hints.length > 0) {
                for (var i = 0; i < hints.length; i++) {
                    horizontal = !horizontal;
                    hint = state.view.transformControlPoint(state, hints[i]);

                    if (horizontal) {
                        if (pt.y != hint.y) {
                            pt.y = hint.y;
                            result.push(pt.clone());
                        }
                    } else if (pt.x != hint.x) {
                        pt.x = hint.x;
                        result.push(pt.clone());
                    }
                }
            } else {
                hint = pt;
            }

            // Adds the last point
            pt = pts[pts.length - 1];

            if (pt == null && target != null) {
                pt = new mxPoint(state.view.getRoutingCenterX(target), state.view.getRoutingCenterY(target));
            }

            if (horizontal) {
                if (pt.y != hint.y && first.x != pt.x) {
                    result.push(new mxPoint(pt.x, hint.y));
                }
            } else if (pt.x != hint.x && first.y != pt.y) {
                result.push(new mxPoint(hint.x, pt.y));
            }
        };

        mxStyleRegistry.putValue('wireEdgeStyle', mxEdgeStyle.WireConnector);

        // This connector needs an mxEdgeSegmentHandler
        mxGraphCreateHandler = mxGraph.prototype.createHandler;
        mxGraph.prototype.createHandler = function(state) {
            var result = null;

            if (state != null) {
                if (this.model.isEdge(state.cell)) {
                    var style = this.view.getEdgeStyle(state);

                    if (style == mxEdgeStyle.WireConnector) {
                        return new mxEdgeSegmentHandler(state);
                    }
                }
            }

            return mxGraphCreateHandler.apply(this, arguments);
        };
    </script>

</head>

<!-- Page passes the container for the graph to the program -->

<body onload="main(document.getElementById('graphContainer'),
			document.getElementById('outlineContainer'),
		 	document.getElementById('toolbarContainer'),
			document.getElementById('sidebarContainer'),
			document.getElementById('statusContainer'));" style="margin:0px;">

    <!-- Creates a container for the splash screen -->
    <div id="splash" style="position:absolute;top:0px;left:0px;width:100%;height:100%;background:white;z-index:1;">
        <center id="splash" style="padding-top:230px;">
            <img src="images/loading.gif">
        </center>
    </div>

    <!-- Creates a container for the sidebar -->
    <div id="toolbarContainer" style="position:absolute;white-space:nowrap;overflow:hidden;top:0px;left:0px;max-height:24px;height:36px;right:0px;padding:6px;background-image:url('images/toolbar_bg.gif');">
    </div>

    <!-- Creates a container for the toolbox -->
    <div id="sidebarContainer" class="ui-accordion ui-widget ui-helper-reset" style="position:absolute;overflow:scroll;top:36px;left:0px;bottom:36px;max-width:266px;width:270px;padding-top:10px;padding-left:4px;">
    </div>

    <!-- Creates a container for the graph -->
    <div id="graphContainer" style="position:absolute;overflow:hidden;top:36px;left:270px;bottom:36px;right:0px;background-image:url('images/grid.gif');cursor:default;">
    </div>

    <!-- Creates a container for the outline -->
    <div id="outlineContainer" style="position:absolute;overflow:hidden;top:36px;right:0px;width:200px;height:140px;background:transparent;border-style:solid;border-color:black;">
    </div>

    <!-- Creates a container for the sidebar -->
    <div id="statusContainer" style="text-align:right;position:absolute;overflow:hidden;bottom:0px;left:0px;max-height:24px;height:36px;right:0px;color:white;padding:6px;background-image:url('images/toolbar_bg.gif');">
        <div style="font-size:10pt;float:left;">
            <a href="http://fossee.in/" target="_tab">FOSSEE</a>
        </div>
    </div>

    <!-- Secret -->
    <p class="accordion-expand-holder" style="display:none">
        <a id='toggleBlocks' class="accordion-expand-all">Expand All</a>
    </p>

</body>
<!-- It's good if this part happens after the entire page has loaded-->
<script type="text/javascript">
    // Preload all images
    var dir = ["blocks", "images"];
    var fileextension = ".";
    var blockImages = [];
    $.each(dir, function(index, value) {
        $.ajax({ // http://stackoverflow.com/a/18480589
            url: value,
            success: function(data) {
                $(data).find("a:contains(" + fileextension + ")").each(function() {
                    var filename = this.href.replace(window.location.host, "");
                    filename = filename.replace("https://", value);
                    filename = filename.replace("http://", value);
                    blockImages.push(filename);
                });
                // Prevent multi-threading and have function within call!
                function preload(sources) {
                    var images = [];
                    for (var i = 0, length = sources.length; i < length; ++i) {
                        images[i] = new Image();
                        images[i].src = sources[i];
                    }
                }
                preload(blockImages);
            }
        });
    });
    //Find out more here: http://stackoverflow.com/questions/12843418/jquery-ui-accordion-expand-collapse-all
    $(window).load(function() {
        var headers = $('#sidebarContainer .accordion-header');
        var contentAreas = $('#sidebarContainer .ui-accordion-content ').hide();
        var expandLink = $('.accordion-expand-all');

        // add the accordion functionality
        headers.click(function() {
            var panel = $(this).next();
            var isOpen = panel.is(':visible');

            // open or close as necessary
            panel[isOpen ? 'slideUp' : 'slideDown']()
                // trigger the correct custom event
                .trigger(isOpen ? 'hide' : 'show');

            // stop the link from causing a pagescroll
            return false;
        });

        // hook up the expand/collapse all
        expandLink.click(function() {
            var isAllOpen = $(this).data('isAllOpen');

            contentAreas[isAllOpen ? 'hide' : 'show']()
                .trigger(isAllOpen ? 'hide' : 'show');
        });

        // when panels open or close, check to see if they're all open
        contentAreas.on({
            // whenever we open a panel, check to see if they're all open
            // if all open, swap the button to collapser
            show: function() {
                var isAllOpen = !contentAreas.is(':hidden');
                if (isAllOpen) {
                    expandLink.text('Collapse All')
                        .data('isAllOpen', true);
                }
            },
            // whenever we close a panel, check to see if they're all open
            // if not all open, swap the button to expander
            hide: function() {
                var isAllOpen = !contentAreas.is(':hidden');
                if (!isAllOpen) {
                    expandLink.text('Expand All')
                        .data('isAllOpen', false);
                }
            }
        });
    });
</script>

</html>