JS-MenĂ¼: Scrollbalken "etwas" gefixt.
[kivitendo-erp.git] / js / dhtmlsuite / menu-for-applications.js
1 /************************************************************************************************************
2         @fileoverview
3         DHTML Suite for Applications.
4         Copyright (C) 2006  Alf Magne Kalleland(post@dhtmlgoodies.com)<br>
5         <br>
6         This library is free software; you can redistribute it and/or<br>
7         modify it under the terms of the GNU Lesser General Public<br>
8         License as published by the Free Software Foundation; either<br>
9         version 2.1 of the License, or (at your option) any later version.<br>
10         <br>
11         This library is distributed in the hope that it will be useful,<br>
12         but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU<br>
14         Lesser General Public License for more details.<br>
15         <br>
16         You should have received a copy of the GNU Lesser General Public<br>
17         License along with this library; if not, write to the Free Software<br>
18         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA<br>
19         <br>
20         <br>
21         www.dhtmlgoodies.com<br>
22         Alf Magne Kalleland<br>
23
24 ************************************************************************************************************/
25
26
27 /**
28  *
29  * @package DHTMLSuite for applications
30  * @copyright Copyright &copy; 2006, www.dhtmlgoodies.com
31  * @author Alf Magne Kalleland <post@dhtmlgoodies.com>
32  */
33
34
35 /************************************************************************************************************
36 *
37 * Global variables
38 *
39 ************************************************************************************************************/
40
41
42 // {{{ DHTMLSuite.createStandardObjects()
43 /**
44  * Create objects used by all scripts
45  *
46  * @public
47  */
48
49
50 var DHTMLSuite = new Object();
51
52 var standardObjectsCreated = false;     // The classes below will check this variable, if it is false, default help objects will be created
53 DHTMLSuite.eventElements = new Array(); // Array of elements that has been assigned to an event handler.
54
55 DHTMLSuite.createStandardObjects = function()
56 {
57         DHTMLSuite.clientInfoObj = new DHTMLSuite.clientInfo(); // Create browser info object
58         DHTMLSuite.clientInfoObj.init();
59         if(!DHTMLSuite.configObj){      // If this object isn't allready created, create it.
60                 DHTMLSuite.configObj = new DHTMLSuite.config(); // Create configuration object.
61                 DHTMLSuite.configObj.init();
62         }
63         DHTMLSuite.commonObj = new DHTMLSuite.common(); // Create configuration object.
64         DHTMLSuite.variableStorage = new DHTMLSuite.globalVariableStorage();;   // Create configuration object.
65         DHTMLSuite.commonObj.init();
66         window.onunload = function() { DHTMLSuite.commonObj.__clearGarbage(); }
67
68         standardObjectsCreated = true;
69
70
71 }
72
73
74
75
76 /************************************************************************************************************
77 *       Configuration class used by most of the scripts
78 *
79 *       Created:                        August, 19th, 2006
80 *       Update log:
81 *
82 ************************************************************************************************************/
83
84
85 /**
86 * @constructor
87 * @class Store global variables/configurations used by the classes below. Example: If you want to
88 *                change the path to the images used by the scripts, change it here. An object of this
89 *                class will always be available to the other classes. The name of this object is
90 *               "DHTMLSuite.configObj". <br><br>
91 *
92 *               If you want to create an object of this class manually, remember to name it "DHTMLSuite.configObj"
93 *               This object should then be created before any other objects. This is nescessary if you want
94 *               the other objects to use the values you have put into the object. <br>
95 * @version                              1.0
96 * @version 1.0
97 * @author       Alf Magne Kalleland(www.dhtmlgoodies.com)
98 **/
99 DHTMLSuite.config = function()
100 {
101         var imagePath;  // Path to images used by the classes.
102         var cssPath;    // Path to CSS files used by the DHTML suite.
103 }
104
105
106 DHTMLSuite.config.prototype = {
107         // {{{ init()
108         /**
109          *
110          * @public
111          */
112         init : function()
113         {
114                 this.imagePath = '../images_dhtmlsuite/';       // Path to images
115                 this.cssPath = '../css_dhtmlsuite/';    // Path to images
116         }
117         // }}}
118         ,
119         // {{{ setCssPath()
120     /**
121      * This method will save a new CSS path, i.e. where the css files of the dhtml suite are located.
122      *
123      * @param string newCssPath = New path to css files
124      * @public
125      */
126
127         setCssPath : function(newCssPath)
128         {
129                 this.cssPath = newCssPath;
130         }
131         // }}}
132         ,
133         // {{{ setImagePath()
134     /**
135      * This method will save a new image file path, i.e. where the image files used by the dhtml suite ar located
136      *
137      * @param string newImagePath = New path to image files
138      * @public
139      */
140         setImagePath : function(newImagePath)
141         {
142                 this.imagePath = newImagePath;
143         }
144         // }}}
145 }
146
147
148
149 DHTMLSuite.globalVariableStorage = function()
150 {
151         var menuBar_highlightedItems;   // Array of highlighted menu bar items
152         this.menuBar_highlightedItems = new Array();
153
154         var arrayOfDhtmlSuiteObjects;   // Array of objects of class menuItem.
155         this.arrayOfDhtmlSuiteObjects = new Array();
156 }
157
158 DHTMLSuite.globalVariableStorage.prototype = {
159
160 }
161
162
163 /************************************************************************************************************
164 *       A class with general methods used by most of the scripts
165 *
166 *       Created:                        August, 19th, 2006
167 *       Purpose of class:       A class containing common method used by one or more of the gui classes below,
168 *                                               example: loadCSS.
169 *                                               An object("DHTMLSuite.commonObj") of this  class will always be available to the other classes.
170 *       Update log:
171 *
172 ************************************************************************************************************/
173
174
175 /**
176 * @constructor
177 * @class A class containing common method used by one or more of the gui classes below, example: loadCSS. An object("DHTMLSuite.commonObj") of this  class will always be available to the other classes.
178 * @version 1.0
179 * @author       Alf Magne Kalleland(www.dhtmlgoodies.com)
180 **/
181
182 DHTMLSuite.common = function()
183 {
184         var loadedCSSFiles;     // Array of loaded CSS files. Prevent same CSS file from being loaded twice.
185         var cssCacheStatus;     // Css cache status
186         var eventElements;
187
188         this.cssCacheStatus = true;     // Caching of css files = on(Default)
189         this.eventElements = new Array();
190 }
191
192 DHTMLSuite.common.prototype = {
193
194         // {{{ init()
195     /**
196      * This method initializes the DHTMLSuite_common object.
197      *
198      * @public
199      */
200
201         init : function()
202         {
203                 this.loadedCSSFiles = new Array();
204         }
205         // }}}
206         ,
207         // {{{ loadCSS()
208     /**
209      * This method loads a CSS file(Cascading Style Sheet) dynamically - i.e. an alternative to <link> tag in the document.
210      *
211      * @param string cssFileName = New path to image files
212      * @public
213      */
214
215         loadCSS : function(cssFileName)
216         {
217
218                 if(!this.loadedCSSFiles[cssFileName]){
219                         this.loadedCSSFiles[cssFileName] = true;
220                         var linkTag = document.createElement('LINK');
221                         if(!this.cssCacheStatus){
222                                 if(cssFileName.indexOf('?')>=0)cssFileName = cssFileName + '&'; else cssFileName = cssFileName + '?';
223                                 cssFileName = cssFileName + 'rand='+ Math.random();     // To prevent caching
224                         }
225                         linkTag.href = DHTMLSuite.configObj.cssPath + cssFileName;
226                         linkTag.rel = 'stylesheet';
227                         linkTag.media = 'screen';
228                         linkTag.type = 'text/css';
229                         document.getElementsByTagName('HEAD')[0].appendChild(linkTag);
230
231                 }
232         }
233         // }}}
234         ,
235         // {{{ getTopPos()
236     /**
237      * This method will return the top coordinate(pixel) of an object
238      *
239      * @param Object inputObj = Reference to HTML element
240      * @public
241      */
242         getTopPos : function(inputObj)
243         {
244           var returnValue = inputObj.offsetTop;
245           while((inputObj = inputObj.offsetParent) != null){
246                 if(inputObj.tagName!='HTML'){
247                         returnValue += (inputObj.offsetTop - inputObj.scrollTop);
248                         if(document.all)returnValue+=inputObj.clientTop;
249                 }
250           }
251           return returnValue;
252         }
253         // }}}
254         ,
255         // {{{ setCssCacheStatus()
256     /**
257      * Specify if css files should be cached or not.
258      *
259      *  @param Boolean cssCacheStatus = true = cache on, false = cache off
260      *
261      * @public
262      */
263         setCssCacheStatus : function(cssCacheStatus)
264         {
265           this.cssCacheStatus = cssCacheStatus;
266         }
267         // }}}
268         ,
269         // {{{ getLeftPos()
270     /**
271      * This method will return the left coordinate(pixel) of an object
272      *
273      * @param Object inputObj = Reference to HTML element
274      * @public
275      */
276         getLeftPos : function(inputObj)
277         {
278           var returnValue = inputObj.offsetLeft;
279           while((inputObj = inputObj.offsetParent) != null){
280                 if(inputObj.tagName!='HTML'){
281                         returnValue += inputObj.offsetLeft;
282                         if(document.all)returnValue+=inputObj.clientLeft;
283                 }
284           }
285           return returnValue;
286         }
287         // }}}
288         ,
289         // {{{ cancelEvent()
290     /**
291      *
292      *  This function only returns false. It is used to cancel selections and drag
293      *
294      *
295      * @public
296      */
297
298         cancelEvent : function()
299         {
300                 return false;
301         }
302         // }}}
303         ,
304         // {{{ addEvent()
305     /**
306      *
307      *  This function adds an event listener to an element on the page.
308      *
309      *  @param Object whichObject = Reference to HTML element(Which object to assigne the event)
310      *  @param String eventType = Which type of event, example "mousemove" or "mouseup"
311      *  @param functionName = Name of function to execute.
312      *
313      * @public
314      */
315         addEvent : function(whichObject,eventType,functionName)
316         {
317           if(whichObject.attachEvent){
318             whichObject['e'+eventType+functionName] = functionName;
319             whichObject[eventType+functionName] = function(){whichObject['e'+eventType+functionName]( window.event );}
320             whichObject.attachEvent( 'on'+eventType, whichObject[eventType+functionName] );
321           } else
322             whichObject.addEventListener(eventType,functionName,false);
323           this.__addEventElement(whichObject);
324           delete(whichObject);
325           // whichObject = null;
326         }
327         // }}}
328         ,
329         // {{{ removeEvent()
330     /**
331      *
332      *  This function removes an event listener from an element on the page.
333      *
334      *  @param Object whichObject = Reference to HTML element(Which object to assigne the event)
335      *  @param String eventType = Which type of event, example "mousemove" or "mouseup"
336      *  @param functionName = Name of function to execute.
337      *
338      * @public
339      */
340         removeEvent : function(whichObject,eventType,functionName)
341         {
342           if(whichObject.detachEvent){
343             whichObject.detachEvent('on'+eventType, whichObject[eventType+functionName]);
344             whichObject[eventType+functionName] = null;
345           } else
346             whichObject.removeEventListener(eventType,functionName,false);
347         }
348         ,
349         // {{{ __clearGarbage()
350     /**
351      *
352      *  This function is used for Internet Explorer in order to clear memory when the page unloads.
353      *
354      *
355      * @private
356      */
357     __clearGarbage : function()
358     {
359                 /* Example of event which causes memory leakage in IE
360
361                 DHTMLSuite.commonObj.addEvent(expandRef,"click",function(){ window.refToMyMenuBar[index].__changeMenuBarState(this); })
362
363                 We got a circular reference.
364
365                 */
366
367         if(!DHTMLSuite.clientInfoObj.isMSIE)return;
368
369         for(var no in DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects){
370                 DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[no] = false;
371         }
372
373         for(var no=0;no<DHTMLSuite.eventElements.length;no++){
374                 DHTMLSuite.eventElements[no].onclick = null;
375                 DHTMLSuite.eventElements[no].onmousedown = null;
376                 DHTMLSuite.eventElements[no].onmousemove = null;
377                 DHTMLSuite.eventElements[no].onmouseout = null;
378                 DHTMLSuite.eventElements[no].onmouseover = null;
379                 DHTMLSuite.eventElements[no].onmouseup = null;
380                 DHTMLSuite.eventElements[no].onfocus = null;
381                 DHTMLSuite.eventElements[no].onblur = null;
382                 DHTMLSuite.eventElements[no].onkeydown = null;
383                 DHTMLSuite.eventElements[no].onkeypress = null;
384                 DHTMLSuite.eventElements[no].onkeyup = null;
385                 DHTMLSuite.eventElements[no].onselectstart = null;
386                 DHTMLSuite.eventElements[no].ondragstart = null;
387                 DHTMLSuite.eventElements[no].oncontextmenu = null;
388                 DHTMLSuite.eventElements[no].onscroll = null;
389
390         }
391         window.onunload = null;
392         DHTMLSuite = null;
393
394     }
395
396     ,
397         // {{{ __addEventElement()
398     /**
399      *
400      *  Add element to garbage collection array. The script will loop through this array and remove event handlers onload in ie.
401      *
402      *
403      * @private
404      */
405     __addEventElement : function(el)
406     {
407         DHTMLSuite.eventElements[DHTMLSuite.eventElements.length] = el;
408     }
409
410     ,
411         // {{{ getSrcElement()
412     /**
413      *
414      *  Returns a reference to the element which triggered an event.
415      *  @param Event e = Event object
416      *
417      *
418      * @private
419      */
420     getSrcElement : function(e)
421     {
422         var el;
423                 // Dropped on which element
424                 if (e.target) el = e.target;
425                         else if (e.srcElement) el = e.srcElement;
426                         if (el.nodeType == 3) // defeat Safari bug
427                                 el = el.parentNode;
428                 return el;
429     }
430
431 }
432
433
434 /************************************************************************************************************
435 *       Client info class
436 *
437 *       Created:                        August, 18th, 2006
438 *       Update log:
439 *
440 ************************************************************************************************************/
441
442 /**
443 * @constructor
444 * @class Purpose of class: Provide browser information to the classes below. Instead of checking for
445 *                browser versions and browser types in the classes below, they should check this
446 *                easily by referncing properties in the class below. An object("DHTMLSuite.clientInfoObj") of this
447 *                class will always be accessible to the other classes. * @version 1.0
448 * @author       Alf Magne Kalleland(www.dhtmlgoodies.com)
449 **/
450
451
452 DHTMLSuite.clientInfo = function()
453 {
454         var browser;                    // Complete user agent information
455
456         var isOpera;                    // Is the browser "Opera"
457         var isMSIE;                             // Is the browser "Internet Explorer"
458         var isFirefox;                  // Is the browser "Firefox"
459         var navigatorVersion;   // Browser version
460 }
461
462 DHTMLSuite.clientInfo.prototype = {
463
464         /**
465         *       Constructor
466         *       Params:                 none:
467         *       return value:   none;
468         **/
469         // {{{ init()
470     /**
471      *
472          *
473      *  This method initializes the script
474      *
475      *
476      * @public
477      */
478
479         init : function()
480         {
481                 this.browser = navigator.userAgent;
482                 this.isOpera = (this.browser.toLowerCase().indexOf('opera')>=0)?true:false;
483                 this.isFirefox = (this.browser.toLowerCase().indexOf('firefox')>=0)?true:false;
484                 this.isMSIE = (this.browser.toLowerCase().indexOf('msie')>=0)?true:false;
485                 this.isSafari = (this.browser.toLowerCase().indexOf('safari')>=0)?true:false;
486                 this.navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1;
487         }
488         // }}}
489 }
490
491 /************************************************************************************************************
492 *       DHTML menu model item class
493 *
494 *       Created:                                                October, 30th, 2006
495 *       @class Purpose of class:                Save data about a menu item.
496 *
497 *
498 *
499 *       Update log:
500 *
501 ************************************************************************************************************/
502
503 DHTMLSuite.menuModelItem = function()
504 {
505         var id;                                 // id of this menu item.
506         var itemText;                   // Text for this menu item
507         var itemIcon;                   // Icon for this menu item.
508         var url;                                // url when click on this menu item
509         var parentId;                   // id of parent element
510         var separator;                  // is this menu item a separator
511         var jsFunction;                 // Js function to call onclick
512         var depth;                              // Depth of this menu item.
513         var hasSubs;                    // Does this menu item have sub items.
514         var type;                               // Menu item type - possible values: "top" or "sub".
515         var helpText;                   // Help text for this item - appear when you move your mouse over the item.
516         var state;
517         var submenuWidth;               // Width of sub menu items.
518         var visible;                    // Visibility of menu item.
519         var frameTarget;
520
521         this.state = 'regular';
522 }
523
524 DHTMLSuite.menuModelItem.prototype = {
525
526         setMenuVars : function(id,itemText,itemIcon,url,parentId,helpText,jsFunction,type,submenuWidth,frameTarget)
527         {
528                 this.id = id;
529                 this.itemText = itemText;
530                 this.itemIcon = itemIcon;
531                 this.url = url;
532                 this.parentId = parentId;
533                 this.jsFunction = jsFunction;
534                 this.separator = false;
535                 this.depth = false;
536                 this.hasSubs = false;
537                 this.helpText = helpText;
538                 this.submenuWidth = submenuWidth;
539                 this.visible = true;
540                 this.frameTarget = frameTarget;
541                 if(!type){
542                         if(this.parentId)this.type = 'top'; else this.type='sub';
543                 }else this.type = type;
544
545
546         }
547         // }}}
548         ,
549         // {{{ setState()
550     /**
551      *  Update the state attribute of a menu item.
552      *
553      *  @param String newState New state of this item
554      * @public
555      */
556         setAsSeparator : function(id,parentId)
557         {
558                 this.id = id;
559                 this.parentId = parentId;
560                 this.separator = true;
561                 this.visible = true;
562                 if(this.parentId)this.type = 'top'; else this.type='sub';
563         }
564         // }}}
565         ,
566         // {{{ setState()
567     /**
568      *  Update the visible attribute of a menu item.
569      *
570      *  @param Boolean visible true = visible, false = hidden.
571      * @public
572      */
573         setVisibility : function(visible)
574         {
575                 this.visible = visible;
576         }
577         // }}}
578         ,
579         // {{{ getState()
580     /**
581      *  Return the state attribute of a menu item.
582      *
583      * @public
584      */
585         getState : function()
586         {
587                 return this.state;
588         }
589         // }}}
590         ,
591         // {{{ setState()
592     /**
593      *  Update the state attribute of a menu item.
594      *
595      *  @param String newState New state of this item
596      * @public
597      */
598         setState : function(newState)
599         {
600                 this.state = newState;
601         }
602         // }}}
603         ,
604         // {{{ setSubMenuWidth()
605     /**
606      *  Specify width of direct subs of this item.
607      *
608      *  @param int newWidth Width of sub menu group(direct sub of this item)
609      * @public
610      */
611         setSubMenuWidth : function(newWidth)
612         {
613                 this.submenuWidth = newWidth;
614         }
615         // }}}
616         ,
617         // {{{ setIcon()
618     /**
619      *  Specify new menu icon
620      *
621      *  @param String iconPath Path to new menu icon
622      * @public
623      */
624         setIcon : function(iconPath)
625         {
626                 this.itemIcon = iconPath;
627         }
628         // }}}
629         ,
630         // {{{ setText()
631     /**
632      *  Specify new text for the menu item.
633      *
634      *  @param String newText New text for the menu item.
635      * @public
636      */
637         setText : function(newText)
638         {
639                 this.itemText = newText;
640         }
641 }
642
643 /************************************************************************************************************
644 *       DHTML menu model class
645 *
646 *       Created:                                                October, 30th, 2006
647 *       @class Purpose of class:                Saves menu item data
648 *
649 *
650 *       Demos of this class:                    demo-menu-strip.html
651 *
652 *       Update log:
653 *
654 ************************************************************************************************************/
655
656
657 /**
658 * @constructor
659 * @class Purpose of class:      Organize menu items for different menu widgets. demos of menus: (<a href="../../demos/demo-menu-strip.html" target="_blank">Demo</a>)
660 * @version 1.0
661 * @author       Alf Magne Kalleland(www.dhtmlgoodies.com)
662 */
663
664
665 DHTMLSuite.menuModel = function()
666 {
667         var menuItems;                                  // Array of menuModelItem objects
668         var menuItemsOrder;                     // This array is needed in order to preserve the correct order of the array above. the array above is associative
669                                                                         // And some browsers will loop through that array in different orders than Firefox and IE.
670         var submenuType;                                // Direction of menu items(one item for each depth)
671         var mainMenuGroupWidth;                 // Width of menu group - useful if the first group of items are listed below each other
672         this.menuItems = new Array();
673         this.menuItemsOrder = new Array();
674         this.submenuType = new Array();
675         this.submenuType[1] = 'top';
676         for(var no=2;no<20;no++){
677                 this.submenuType[no] = 'sub';
678         }
679         if(!standardObjectsCreated)DHTMLSuite.createStandardObjects();
680 }
681
682 DHTMLSuite.menuModel.prototype = {
683         // {{{ addItem()
684     /**
685      *  Add separator (special type of menu item)
686      *
687          *
688      *
689      *  @param int id of menu item
690      *  @param string itemText = text of menu item
691      *  @param string itemIcon = file name of menu icon(in front of menu text. Path will be imagePath for the DHTMLSuite + file name)
692      *  @param string url = Url of menu item
693      *  @param int parent id of menu item
694      *  @param String jsFunction Name of javascript function to execute. It will replace the url param. The function with this name will be called and the element triggering the action will be
695      *                                  sent as argument. Name of the element which triggered the menu action may also be sent as a second argument. That depends on the widget. The context menu is an example where
696      *                                  the element triggering the context menu is sent as second argument to this function.
697      *
698      * @public
699      */
700         addItem : function(id,itemText,itemIcon,url,parentId,helpText,jsFunction,type,submenuWidth)
701         {
702                 if(!id)id = this.__getUniqueId();       // id not present - create it dynamically.
703                 this.menuItems[id] = new DHTMLSuite.menuModelItem();
704                 this.menuItems[id].setMenuVars(id,itemText,itemIcon,url,parentId,helpText,jsFunction,type,submenuWidth);
705                 this.menuItemsOrder[this.menuItemsOrder.length] = id;
706                 return this.menuItems[id];
707         }
708         ,
709         // {{{ addItemsFromMarkup()
710     /**
711      *  This method creates all the menuModelItem objects by reading it from existing markup on your page.
712      *  Example of HTML markup:
713      *<br>
714                 &nbsp;&nbsp;&nbsp;&nbsp;&lt;ul id="menuModel">
715                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="50000" itemIcon="../images/disk.gif">&lt;a href="#" title="Open the file menu">File&lt;/a>
716                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul width="150">
717                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500001" jsFunction="saveWork()" itemIcon="../images/disk.gif">&lt;a href="#" title="Save your work">Save&lt;/a>&lt;/li>
718                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500002">&lt;a href="#">Save As&lt;/a>&lt;/li>
719                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500004" itemType="separator">&lt;/li>
720                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500003">&lt;a href="#">Open&lt;/a>&lt;/li>
721                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul>
722                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/li>
723                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="50001">&lt;a href="#">View&lt;/a>
724                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul width="130">
725                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500011">&lt;a href="#">Source&lt;/a>&lt;/li>
726                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500012">&lt;a href="#">Debug info&lt;/a>&lt;/li>
727                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="500013">&lt;a href="#">Layout&lt;/a>
728                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul width="150">
729                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="5000131">&lt;a href="#">CSS&lt;/a>&nbsp;&nbsp;
730                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="5000132">&lt;a href="#">HTML&lt;/a>&nbsp;&nbsp;
731                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="5000133">&lt;a href="#">Javascript&lt;/a>&nbsp;&nbsp;
732                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul>
733                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/li>
734                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
735                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul>
736                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/li>
737                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="50003" itemType="separator">&lt;/li>
738                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li id="50002">&lt;a href="#">Tools&lt;/a>&lt;/li>
739                 <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul>&nbsp;&nbsp;
740      *
741      *  @param String ulId = ID of <UL> tag on your page.
742      *
743      * @public
744      */
745         addItemsFromMarkup : function(ulId)
746         {
747                 if(!document.getElementById(ulId)){
748                         alert('<UL> tag with id ' + ulId + ' does not exist');
749                         return;
750                 }
751                 var ulObj = document.getElementById(ulId);
752                 var liTags = ulObj.getElementsByTagName('LI');
753                 for(var no=0;no<liTags.length;no++){    // Walking through all <li> tags in the <ul> tree
754
755                         var id = liTags[no].id.replace(/[^0-9]/gi,'');  // Get id of item.
756                         if(!id)id = this.__getUniqueId();
757                         this.menuItems[id] = new DHTMLSuite.menuModelItem();    // Creating new menuModelItem object
758                         this.menuItemsOrder[this.menuItemsOrder.length] = id;
759                         // Get the attributes for this new menu item.
760
761                         var parentId = 0;       // Default parent id
762                         if(liTags[no].parentNode!=ulObj)parentId = liTags[no].parentNode.parentNode.id; // parent node exists, set parentId equal to id of parent <li>.
763
764                         /* Checking type */
765                         var type = liTags[no].getAttribute('itemType');
766                         if(!type)type = liTags[no].itemType;
767                         if(type=='separator'){  // Menu item of type "separator"
768                                 this.menuItems[id].setAsSeparator(id,parentId);
769                                 continue;
770                         }
771                         if(parentId)type='sub'; else type = 'top';
772
773                         var aTag = liTags[no].getElementsByTagName('A')[0];     // Get a reference to sub <a> tag
774                         if(!aTag){
775                                 continue;
776                         }
777                         if(aTag)var itemText = aTag.innerHTML;  // Item text is set to the innerHTML of the <a> tag.
778                         var itemIcon = liTags[no].getAttribute('itemIcon');     // Item icon is set from the itemIcon attribute of the <li> tag.
779                         var url = aTag.href;    // url is set to the href attribute of the <a> tag
780                         if(url=='#' || url.substr(url.length-1,1)=='#')url='';  // # = empty url.
781       var frameTarget = aTag.target;
782
783                         var jsFunction = liTags[no].getAttribute('jsFunction'); // jsFunction is set from the jsFunction attribute of the <li> tag.
784
785                         var submenuWidth = false;       // Not set from the <li> tag.
786                         var helpText = aTag.getAttribute('title');
787                         if(!helpText)helpText = aTag.title;
788
789                         this.menuItems[id].setMenuVars(id,itemText,itemIcon,url,parentId,helpText,jsFunction,type,submenuWidth,frameTarget);
790                 }
791                 var subUls = ulObj.getElementsByTagName('UL');
792                 for(var no=0;no<subUls.length;no++){
793                         var width = subUls[no].getAttribute('width');
794                         if(!width)width = subUls[no].width;
795                         if(width){
796                                 var id = subUls[no].parentNode.id.replace(/[^0-9]/gi,'');
797                                 this.setSubMenuWidth(id,width);
798                         }
799                 }
800                 ulObj.style.display='none';
801
802         }
803         // }}}
804         ,
805         // {{{ setSubMenuWidth()
806     /**
807      *  This method specifies the width of a sub menu group. This is a useful method in order to get a correct width in IE6 and prior.
808      *
809      *  @param int id = ID of parent menu item
810      *  @param String newWidth = Width of sub menu items.
811      * @public
812      */
813         setSubMenuWidth : function(id,newWidth)
814         {
815                 this.menuItems[id].setSubMenuWidth(newWidth);
816         }
817         ,
818         // {{{ setMainMenuGroupWidth()
819     /**
820      *  Add separator (special type of menu item)
821      *
822      *  @param String newWidth = Size of a menu group
823      *  @param int parent id of menu item
824      * @public
825      */
826         setMainMenuGroupWidth : function(newWidth)
827         {
828                 this.mainMenuGroupWidth = newWidth;
829         }
830         ,
831         // {{{ addSeparator()
832     /**
833      *  Add separator (special type of menu item)
834      *
835      *  @param int parent id of menu item
836      * @public
837      */
838         addSeparator : function(parentId)
839         {
840                 id = this.__getUniqueId();      // Get unique id
841                 if(!parentId)parentId = 0;
842                 this.menuItems[id] = new DHTMLSuite.menuModelItem();
843                 this.menuItems[id].setAsSeparator(id,parentId);
844                 this.menuItemsOrder[this.menuItemsOrder.length] = id;
845                 return this.menuItems[id];
846         }
847         ,
848         // {{{ init()
849     /**
850      *  Initilizes the menu model. This method should be called when all items has been added to the model.
851      *
852      *
853      * @public
854      */
855         init : function()
856         {
857                 this.__getDepths();
858                 this.__setHasSubs();
859
860         }
861         // }}}
862         ,
863         // {{{ setMenuItemVisibility()
864     /**
865      *  Save visibility of a menu item.
866      *
867      *  @param int id = Id of menu item..
868      *  @param Boolean visible = Visibility of menu item.
869      *
870      * @public
871      */
872         setMenuItemVisibility : function(id,visible)
873         {
874                 this.menuItems[id].setVisibility(visible);
875         }
876         // }}}
877         ,
878         // {{{ setSubMenuType()
879     /**
880      *  Set menu type for a specific menu depth.
881      *
882      *  @param int depth = 1 = Top menu, 2 = Sub level 1...
883      *  @param String newType = New menu type(possible values: "top" or "sub")
884      *
885      * @private
886      */
887         setSubMenuType : function(depth,newType)
888         {
889                 this.submenuType[depth] = newType;
890
891         }
892         // }}}
893         ,
894         // {{{ __getDepths()
895     /**
896      *  Create variable for the depth of each menu item.
897      *
898      *
899      * @private
900      */
901         getItems : function(parentId,returnArray)
902         {
903                 if(!parentId)return this.menuItems;
904                 if(!returnArray)returnArray = new Array();
905                 for(var no=0;no<this.menuItemsOrder.length;no++){
906                         var id = this.menuItemsOrder[no];
907                         if(!id)continue;
908                         if(this.menuItems[id].parentId==parentId){
909                                 returnArray[returnArray.length] = this.menuItems[id];
910                                 if(this.menuItems[id].hasSubs)return this.getItems(this.menuItems[id].id,returnArray);
911                         }
912                 }
913                 return returnArray;
914
915         }
916         // }}}
917         ,
918         // {{{ __getUniqueId()
919     /**
920      *  Returns a unique id for a menu item. This method is used by the addSeparator function in case an id isn't sent to the method.
921      *
922      *
923      * @private
924      */
925         __getUniqueId : function()
926         {
927                 var num = Math.random() + '';
928                 num = num.replace('.','');
929                 num = '99' + num;
930                 num = num /1;
931                 while(this.menuItems[num]){
932                         num = Math.random() + '';
933                         num = num.replace('.','');
934                         num = num /1;
935                 }
936                 return num;
937         }
938         // }}}
939         ,
940         // {{{ __getDepths()
941     /**
942      *  Create variable for the depth of each menu item.
943      *
944      *
945      * @private
946      */
947     __getDepths : function()
948     {
949         for(var no=0;no<this.menuItemsOrder.length;no++){
950                 var id = this.menuItemsOrder[no];
951                 if(!id)continue;
952                 this.menuItems[id].depth = 1;
953                 if(this.menuItems[id].parentId){
954                         this.menuItems[id].depth = this.menuItems[this.menuItems[id].parentId].depth+1;
955
956                 }
957                 this.menuItems[id].type = this.submenuType[this.menuItems[id].depth];   // Save menu direction for this menu item.
958         }
959     }
960     // }}}
961     ,
962     // {{{ __setHasSubs()
963     /**
964      *  Create variable for the depth of each menu item.
965      *
966      *
967      * @private
968      */
969     __setHasSubs : function()
970     {
971         for(var no=0;no<this.menuItemsOrder.length;no++){
972                 var id = this.menuItemsOrder[no];
973                 if(!id)continue;
974                 if(this.menuItems[id].parentId){
975                         this.menuItems[this.menuItems[id].parentId].hasSubs = 1;
976
977                 }
978         }
979     }
980     // }}}
981     ,
982         // {{{ __hasSubs()
983     /**
984      *  Does a menu item have sub elements ?
985      *
986      *
987      * @private
988      */
989         // }}}
990         __hasSubs : function(id)
991         {
992                 for(var no=0;no<this.menuItemsOrder.length;no++){
993                         var id = this.menuItemsOrder[no];
994                         if(!id)continue;
995                         if(this.menuItems[id].parentId==id)return true;
996                 }
997                 return false;
998         }
999         // }}}
1000         ,
1001         // {{{ __deleteChildNodes()
1002     /**
1003      *  Deleting child nodes of a specific parent id
1004      *
1005      *  @param int parentId
1006      *
1007      * @private
1008      */
1009         // }}}
1010         __deleteChildNodes : function(parentId,recursive)
1011         {
1012                 var itemsToDeleteFromOrderArray = new Array();
1013                 for(var prop=0;prop<this.menuItemsOrder.length;prop++){
1014                 var id = this.menuItemsOrder[prop];
1015                 if(!id)continue;
1016
1017                         if(this.menuItems[id].parentId==parentId && parentId){
1018                                 this.menuItems[id] = false;
1019                                 itemsToDeleteFromOrderArray[itemsToDeleteFromOrderArray.length] = id;
1020                                 this.__deleteChildNodes(id,true);       // Recursive call.
1021                         }
1022                 }
1023
1024                 if(!recursive){
1025                         for(var prop=0;prop<itemsToDeleteFromOrderArray;prop++){
1026                                 if(!itemsToDeleteFromOrderArray[prop])continue;
1027                                 this.__deleteItemFromItemOrderArray(itemsToDeleteFromOrderArray[prop]);
1028                         }
1029                 }
1030                 this.__setHasSubs();
1031         }
1032         // }}}
1033         ,
1034         // {{{ __deleteANode()
1035     /**
1036      *  Deleting a specific node from the menu model
1037      *
1038      *  @param int id = Id of node to delete.
1039      *
1040      * @private
1041      */
1042         // }}}
1043         __deleteANode : function(id)
1044         {
1045                 this.menuItems[id] = false;
1046                 this.__deleteItemFromItemOrderArray(id);
1047         }
1048         ,
1049         // {{{ __deleteItemFromItemOrderArray()
1050     /**
1051      *  Deleting a specific node from the menuItemsOrder array(The array controlling the order of the menu items).
1052      *
1053      *  @param int id = Id of node to delete.
1054      *
1055      * @private
1056      */
1057         // }}}
1058         __deleteItemFromItemOrderArray : function(id)
1059         {
1060                 for(var no=0;no<this.menuItemsOrder.length;no++){
1061                         var tmpId = this.menuItemsOrder[no];
1062                         if(!tmpId)continue;
1063                         if(this.menuItemsOrder[no]==id){
1064                                 this.menuItemsOrder.splice(no,1);
1065                                 return;
1066                         }
1067                 }
1068
1069         }
1070         // }}}
1071         ,
1072         // {{{ __appendMenuModel()
1073     /**
1074      *  Replace the sub items of a menu item with items from a new menuModel.
1075      *
1076      *  @param menuModel newModel = An object of class menuModel - the items of this menu model will be appended to the existing menu items.
1077      *  @param Int parentId = Id of parent element of the appended items.
1078      *
1079      * @private
1080      */
1081         // }}}
1082         __appendMenuModel : function(newModel,parentId)
1083         {
1084                 if(!newModel)return;
1085                 var items = newModel.getItems();
1086                 for(var no=0;no<newModel.menuItemsOrder.length;no++){
1087                         var id = newModel.menuItemsOrder[no];
1088                         if(!id)continue;
1089                         if(!items[id].parentId)items[id].parentId = parentId;
1090                         this.menuItems[id] = items[id];
1091                         for(var no2=0;no2<this.menuItemsOrder.length;no2++){    // Check to see if this item allready exists in the menuItemsOrder array, if it does, remove it.
1092                                 if(!this.menuItemsOrder[no2])continue;
1093                                 if(this.menuItemsOrder[no2]==items[id].id){
1094                                         this.menuItemsOrder.splice(no2,1);
1095                                 }
1096                         }
1097                         this.menuItemsOrder[this.menuItemsOrder.length] = items[id].id;
1098                 }
1099                 this.__getDepths();
1100                 this.__setHasSubs();
1101         }
1102         // }}}
1103 }
1104
1105 /* Class for menu items - a view */
1106
1107 /************************************************************************************************************
1108 *       DHTML menu item class
1109 *
1110 *       Created:                                                October, 21st, 2006
1111 *       @class Purpose of class:                Creates the HTML for a single menu item.
1112 *
1113 *       Css files used by this script:  menu-item.css
1114 *
1115 *       Demos of this class:                    demo-menu-strip.html
1116 *
1117 *       Update log:
1118 *
1119 ************************************************************************************************************/
1120
1121 /**
1122 * @constructor
1123 * @class Purpose of class:      Creates the div(s) for a menu item. This class is used by the menuBar class. You can
1124 *       also create a menu item and add it where you want on your page. the createItem() method will return the div
1125 *       for the item. You can use the appendChild() method to add it to your page.
1126 *
1127 * @version 1.0
1128 * @author       Alf Magne Kalleland(www.dhtmlgoodies.com)
1129 */
1130
1131
1132 DHTMLSuite.menuItem = function()
1133 {
1134         var layoutCSS;
1135         var divElement;                                                 // the <div> element created for this menu item
1136         var expandElement;                                              // Reference to the arrow div (expand sub items)
1137         var cssPrefix;                                                  // Css prefix for the menu items.
1138         var modelItemRef;                                               // Reference to menuModelItem
1139
1140         this.layoutCSS = 'menu-item.css';
1141         this.cssPrefix = 'DHTMLSuite_';
1142
1143         if(!standardObjectsCreated)DHTMLSuite.createStandardObjects();
1144
1145
1146         var objectIndex;
1147         this.objectIndex = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects.length;
1148
1149
1150 }
1151
1152 DHTMLSuite.menuItem.prototype =
1153 {
1154
1155         /*
1156         *       Create a menu item.
1157         *
1158         *       @param menuModelItem menuModelItemObj = An object of class menuModelItem
1159         */
1160         createItem : function(menuModelItemObj)
1161         {
1162                 DHTMLSuite.commonObj.loadCSS(this.layoutCSS);   // Load css
1163
1164                 DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[this.objectIndex] = this;
1165
1166                 this.modelItemRef = menuModelItemObj;
1167                 this.divElement = document.createElement('DIV');        // Create main div
1168                 this.divElement.id = 'DHTMLSuite_menuItem' + menuModelItemObj.id;       // Giving this menu item it's unque id
1169                 this.divElement.className = this.cssPrefix + 'menuItem_' + menuModelItemObj.type + '_regular';
1170                 this.divElement.onselectstart = function() { return DHTMLSuite.commonObj.cancelEvent(false,this) };
1171                 if(menuModelItemObj.helpText){  // Add "title" attribute to the div tag if helpText is defined
1172                         this.divElement.title = menuModelItemObj.helpText;
1173                 }
1174
1175                 // Menu item of type "top"
1176                 if(menuModelItemObj.type=='top'){
1177                         this.__createMenuElementsOfTypeTop(this.divElement);
1178                 }
1179
1180                 if(menuModelItemObj.type=='sub'){
1181                         this.__createMenuElementsOfTypeSub(this.divElement);
1182                 }
1183
1184                 if(menuModelItemObj.separator){
1185                         this.divElement.className = this.cssPrefix + 'menuItem_separator_' + menuModelItemObj.type;
1186                         this.divElement.innerHTML = '<span></span>';
1187                 }else{
1188                         /* Add events */
1189                         var tmpVar = this.objectIndex/1;
1190                         //this.divElement.onclick = function(e) { DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[tmpVar].__navigate(e); }
1191                         this.divElement.onmousedown = this.__clickMenuItem;                     // on mouse down effect
1192                         this.divElement.onmouseup = this.__rolloverMenuItem;            // on mouse up effect
1193                         this.divElement.onmouseover = this.__rolloverMenuItem;          // mouse over effect
1194                         this.divElement.onmouseout = this.__rolloutMenuItem;            // mouse out effect.
1195                         DHTMLSuite.commonObj.__addEventElement(this.divElement);
1196                 }
1197                 return this.divElement;
1198         }
1199         // }}}
1200         ,
1201         // {{{ setLayoutCss()
1202     /**
1203      *  Creates the different parts of a menu item of type "top".
1204      *
1205      *  @param String newLayoutCss = Name of css file used for the menu items.
1206      *
1207      * @public
1208      */
1209         setLayoutCss : function(newLayoutCss)
1210         {
1211                 this.layoutCSS = newLayoutCss;
1212
1213         }
1214         // }}}
1215         ,
1216         // {{{ __createMenuElementsOfTypeTop()
1217     /**
1218      *  Creates the different parts of a menu item of type "top".
1219      *
1220      *  @param menuModelItem menuModelItemObj = Object of type menuModelItemObj
1221      *  @param Object parentEl = Reference to parent element
1222      *
1223      * @private
1224      */
1225         __createMenuElementsOfTypeTop : function(parentEl){
1226                 if(this.modelItemRef.itemIcon){
1227                         var iconDiv = document.createElement('DIV');
1228                         iconDiv.innerHTML = '<img src="' + this.modelItemRef.itemIcon + '">';
1229                         iconDiv.id = 'menuItemIcon' + this.modelItemRef.id
1230                         parentEl.appendChild(iconDiv);
1231                 }
1232                 if(this.modelItemRef.itemText){
1233                         var div = document.createElement('DIV');
1234                         div.innerHTML = this.modelItemRef.itemText;
1235                         div.className = this.cssPrefix + 'menuItem_textContent';
1236                         div.id = 'menuItemText' + this.modelItemRef.id;
1237                         parentEl.appendChild(div);
1238                 }
1239                 /* Create div for the arrow -> Show sub items */
1240                 var div = document.createElement('DIV');
1241                 div.className = this.cssPrefix + 'menuItem_top_arrowShowSub';
1242                 div.id = 'DHTMLSuite_menuBar_arrow' + this.modelItemRef.id;
1243                 parentEl.appendChild(div);
1244                 this.expandElement = div;
1245                 if(!this.modelItemRef.hasSubs)div.style.display='none';
1246
1247         }
1248         // }}}
1249         ,
1250
1251         // {{{ __createMenuElementsOfTypeSub()
1252     /**
1253      *  Creates the different parts of a menu item of type "sub".
1254      *
1255      *  @param menuModelItem menuModelItemObj = Object of type menuModelItemObj
1256      *  @param Object parentEl = Reference to parent element
1257      *
1258      * @private
1259      */
1260         __createMenuElementsOfTypeSub : function(parentEl){
1261                 if(this.modelItemRef.itemIcon){
1262                         parentEl.style.backgroundImage = 'url(\'' + this.modelItemRef.itemIcon + '\')';
1263                         parentEl.style.backgroundRepeat = 'no-repeat';
1264                         parentEl.style.backgroundPosition = 'left center';
1265                 }
1266                 if(this.modelItemRef.itemText){
1267                   var div;
1268                   if( this.modelItemRef.url )
1269                   {
1270                           div = document.createElement('a');
1271                           div.href = this.modelItemRef.url;
1272                           div.target = this.modelItemRef.frameTarget;
1273                           div.style.display = 'block';
1274                         }
1275                         else
1276                           div = document.createElement('div');
1277
1278                         div.className = 'DHTMLSuite_textContent';
1279                         div.innerHTML = this.modelItemRef.itemText;
1280                         div.className = this.cssPrefix + 'menuItem_textContent';
1281                         div.id = 'menuItemText' + this.modelItemRef.id;
1282                         parentEl.appendChild(div);
1283                 }
1284
1285                 /* Create div for the arrow -> Show sub items */
1286                 var div = document.createElement('DIV');
1287                 div.className = this.cssPrefix + 'menuItem_sub_arrowShowSub';
1288                 parentEl.appendChild(div);
1289                 div.id = 'DHTMLSuite_menuBar_arrow' + this.modelItemRef.id;
1290                 this.expandElement = div;
1291
1292                 if(!this.modelItemRef.hasSubs){
1293                         div.style.display='none';
1294                 }else{
1295                         div.previousSibling.style.paddingRight = '15px';
1296                 }
1297         }
1298         // }}}
1299         ,
1300         // {{{ setCssPrefix()
1301     /**
1302      *  Set css prefix for the menu item. default is 'DHTMLSuite_'. This is useful in case you want to have different menus on a page with different layout.
1303      *
1304      *  @param String cssPrefix = New css prefix.
1305      *
1306      * @public
1307      */
1308         setCssPrefix : function(cssPrefix)
1309         {
1310                 this.cssPrefix = cssPrefix;
1311         }
1312         // }}}
1313         ,
1314         // {{{ setMenuIcon()
1315     /**
1316      *  Replace menu icon.
1317      *
1318      *  @param String newPath - Path to new icon (false if no icon);
1319      *
1320      * @public
1321      */
1322         setIcon : function(newPath)
1323         {
1324                 this.modelItemRef.setIcon(newPath);
1325                 if(this.modelItemRef.type=='top'){      // Menu item is of type "top"
1326                         var div = document.getElementById('menuItemIcon' + this.modelItemRef.id);       // Get a reference to the div where the icon is located.
1327                         var img = div.getElementsByTagName('IMG')[0];   // Find the image
1328                         if(!img){       // Image doesn't exists ?
1329                                 img = document.createElement('IMG');    // Create new image
1330                                 div.appendChild(img);
1331                         }
1332                         img.src = newPath;      // Set image path
1333                         if(!newPath)img.parentNode.removeChild(img);    // No newPath defined, remove the image.
1334                 }
1335                 if(this.modelItemRef.type=='sub'){      // Menu item is of type "sub"
1336                         this.divElement.style.backgroundImage = 'url(\'' + newPath + '\')';             // Set backgroundImage for the main div(i.e. menu item div)
1337                 }
1338         }
1339         // }}}
1340         ,
1341         // {{{ setText()
1342     /**
1343      *  Replace the text of a menu item
1344      *
1345      *  @param String newText - New text for the menu item.
1346      *
1347      * @public
1348      */
1349         setText : function(newText)
1350         {
1351                 this.modelItemRef.setText(newText);
1352                 document.getElementById('menuItemText' + this.modelItemRef.id).innerHTML = newText;
1353
1354
1355         }
1356
1357         // }}}
1358         ,
1359         // {{{ __clickMenuItem()
1360     /**
1361      *  Effect - click on menu item
1362      *
1363      *
1364      * @private
1365      */
1366         __clickMenuItem : function()
1367         {
1368                 this.className = this.className.replace('_regular','_click');
1369                 this.className = this.className.replace('_over','_click');
1370         }
1371         // }}}
1372         ,
1373         // {{{ __rolloverMenuItem()
1374     /**
1375      *  Roll over effect
1376      *
1377      *
1378      * @private
1379      */
1380         __rolloverMenuItem : function()
1381         {
1382                 this.className = this.className.replace('_regular','_over');
1383                 this.className = this.className.replace('_click','_over');
1384         }
1385         // }}}
1386         ,
1387         // {{{ __rolloutMenuItem()
1388     /**
1389      *  Roll out effect
1390      *
1391      *
1392      * @private
1393      */
1394         __rolloutMenuItem : function()
1395         {
1396                 this.className = this.className.replace('_over','_regular');
1397
1398         }
1399         // }}}
1400         ,
1401         // {{{ setState()
1402     /**
1403      *  Set state of a menu item.
1404      *
1405      *  @param String newState = New state for the menu item
1406      *
1407      * @public
1408      */
1409         setState : function(newState)
1410         {
1411                 this.divElement.className = this.cssPrefix + 'menuItem_' + this.modelItemRef.type + '_' + newState;
1412                 this.modelItemRef.setState(newState);
1413         }
1414         // }}}
1415         ,
1416         // {{{ getState()
1417     /**
1418      *  Return state of a menu item.
1419      *
1420      *
1421      * @public
1422      */
1423         getState : function()
1424         {
1425                 var state = this.modelItemRef.getState();
1426                 if(!state){
1427                         if(this.divElement.className.indexOf('_over')>=0)state = 'over';
1428                         if(this.divElement.className.indexOf('_click')>=0)state = 'click';
1429                         this.modelItemRef.setState(state);
1430                 }
1431                 return state;
1432         }
1433         // }}}
1434         ,
1435         // {{{ __setHasSub()
1436     /**
1437      *  Update the item, i.e. show/hide the arrow if the element has subs or not.
1438      *
1439      *
1440      * @private
1441      */
1442     __setHasSub : function(hasSubs)
1443     {
1444         this.modelItemRef.hasSubs = hasSubs;
1445         if(!hasSubs){
1446                 document.getElementById(this.cssPrefix +'menuBar_arrow' + this.modelItemRef.id).style.display='none';
1447         }else{
1448                 document.getElementById(this.cssPrefix +'menuBar_arrow' + this.modelItemRef.id).style.display='block';
1449         }
1450     }
1451     // }}}
1452     ,
1453         // {{{ hide()
1454     /**
1455      *  Hide the menu item.
1456      *
1457      *
1458      * @public
1459      */
1460     hide : function()
1461     {
1462         this.modelItemRef.setVisibility(false);
1463         this.divElement.style.display='none';
1464     }
1465     ,
1466         // {{{ show()
1467     /**
1468      *  Show the menu item.
1469      *
1470      *
1471      * @public
1472      */
1473     show : function()
1474     {
1475         this.modelItemRef.setVisibility(true);
1476         this.divElement.style.display='block';
1477     }
1478         // }}}
1479         ,
1480         // {{{ __hideGroup()
1481     /**
1482      *  Hide the group the menu item is a part of. Example: if we're dealing with menu item 2.1, hide the group for all sub items of 2
1483      *
1484      *
1485      * @private
1486      */
1487         __hideGroup : function()
1488         {
1489                 if(this.modelItemRef.parentId){
1490                         this.divElement.parentNode.style.visibility='hidden';
1491                         if(DHTMLSuite.clientInfoObj.isMSIE){
1492                                 try{
1493                                         var tmpId = this.divElement.parentNode.id.replace(/[^0-9]/gi,'');
1494                                         document.getElementById('DHTMLSuite_menuBarIframe_' + tmpId).style.visibility = 'hidden';
1495                                 }catch(e){
1496                                         // IFRAME hasn't been created.
1497                                 }
1498                         }
1499                 }
1500
1501         }
1502         // }}}
1503         ,
1504         // {{{ __navigate()
1505     /**
1506      *  Navigate after click on a menu item.
1507      *
1508      *
1509      * @private
1510      */
1511         __navigate : function(e)
1512         {
1513                 /* Check to see if the expand sub arrow is clicked. if it is, we shouldn't navigate from this click */
1514                 if(document.all)e = event;
1515                 if(e){
1516                         var srcEl = DHTMLSuite.commonObj.getSrcElement(e);
1517                         if(srcEl.id.indexOf('arrow')>=0)return;
1518                 }
1519                 if(this.modelItemRef.state=='disabled')return;
1520                 if(this.modelItemRef.url){
1521       if (this.modelItemRef.frameTarget == 'main_window')
1522         window.main_window.location = this.modelItemRef.url;
1523       else if (this.modelItemRef.frameTarget == '_top')
1524         window.location = this.modelItemRef.url;
1525       else if (this.modelItemRef.frameTarget)
1526         window.open(this.modelItemRef.url);
1527       else
1528         location.href = this.modelItemRef.url;
1529                 }
1530                 if(this.modelItemRef.jsFunction){
1531                         try{
1532                                 eval(this.modelItemRef.jsFunction);
1533                         }catch(e){
1534                                 alert('Defined Javascript code for the menu item( ' + this.modelItemRef.jsFunction + ' ) cannot be executed');
1535                         }
1536                 }
1537         }
1538 }
1539
1540
1541 /************************************************************************************************************
1542 *       DHTML menu bar class
1543 *
1544 *       Created:                                                October, 21st, 2006
1545 *       @class Purpose of class:                Creates a top bar menu
1546 *
1547 *       Css files used by this script:  menu-bar.css
1548 *
1549 *       Demos of this class:                    demo-menu-bar.html
1550 *
1551 *       Update log:
1552 *
1553 ************************************************************************************************************/
1554
1555
1556 /**
1557 * @constructor
1558 * @class Purpose of class:      Creates a top bar menu strip. Demos: <br>
1559 *       <ul>
1560 *       <li>(<a href="../../demos/demo-menu-bar-2.html" target="_blank">A menu with a detailed description on how it is created</a>)</li>
1561 *       <li>(<a href="../../demos/demo-menu-bar.html" target="_blank">Demo with lots of menus on the same page</a>)</li>
1562 *       <li>(<a href="../../demos/demo-menu-bar-custom-css.html" target="_blank">Two menus with different layout</a>)</li>
1563 *       <li>(<a href="../../demos/demo-menu-bar-custom-css-file.html" target="_blank">One menu with custom layout/css.</a>)</li>
1564 *       </ul>
1565 *
1566 *       <a href="../images/menu-bar-1.gif" target="_blank">Image describing the classes</a> <br><br>
1567 *
1568 * @version 1.0
1569 * @author       Alf Magne Kalleland(www.dhtmlgoodies.com)
1570 */
1571
1572 DHTMLSuite.menuBar = function()
1573 {
1574         var menuItemObj;
1575         var layoutCSS;                                  // Name of css file
1576         var menuBarBackgroundImage;             // Name of background image
1577         var menuItem_objects;                   // Array of menu items - html elements.
1578         var menuBarObj;                                 // Reference to the main dib
1579         var menuBarHeight;
1580         var menuItems;                                  // Reference to objects of class menuModelItem
1581         var highlightedItems;                   // Array of currently highlighted menu items.
1582         var menuBarState;                               // Menu bar state - true or false - 1 = expand items on mouse over
1583         var activeSubItemsOnMouseOver;  // Activate sub items on mouse over     (instead of onclick)
1584
1585
1586         var submenuGroups;                              // Array of div elements for the sub menus
1587         var submenuIframes;                             // Array of sub menu iframes used to cover select boxes in old IE browsers.
1588         var createIframesForOldIeBrowsers;      // true if we want the script to create iframes in order to cover select boxes in older ie browsers.
1589         var targetId;                                   // Id of element where the menu will be inserted.
1590         var menuItemCssPrefix;                  // Css prefix of menu items.
1591         var cssPrefix;                                  // Css prefix for the menu bar
1592         var menuItemLayoutCss;                  // Css path for the menu items of this menu bar
1593         var globalObjectIndex;                  // Global index of this object - used to refer to the object of this class outside
1594         this.cssPrefix = 'DHTMLSuite_';
1595         this.menuItemLayoutCss = false; // false = use default for the menuItem class.
1596         this.layoutCSS = 'menu-bar.css';
1597         this.menuBarBackgroundImage = 'menu_strip_bg.jpg';
1598         this.menuItem_objects = new Array();
1599         DHTMLSuite.variableStorage.menuBar_highlightedItems = new Array();
1600
1601         this.menuBarState = false;
1602
1603         this.menuBarObj = false;
1604         this.menuBarHeight = 26;
1605         this.submenuGroups = new Array();
1606         this.submenuIframes = new Array();
1607         this.targetId = false;
1608         this.activeSubItemsOnMouseOver = false;
1609         this.menuItemCssPrefix = false;
1610         this.createIframesForOldIeBrowsers = false;
1611         if(!standardObjectsCreated)DHTMLSuite.createStandardObjects();
1612
1613
1614 }
1615
1616
1617
1618
1619
1620 DHTMLSuite.menuBar.prototype = {
1621
1622         // {{{ init()
1623     /**
1624      *  Initilizes the script
1625      *
1626      *
1627      * @public
1628      */
1629         init : function()
1630         {
1631
1632                 DHTMLSuite.commonObj.loadCSS(this.layoutCSS);
1633                 this.__createDivs();    // Create general divs
1634                 this.__createMenuItems();       // Create menu items
1635                 this.__setBasicEvents();        // Set basic events.
1636                 window.refToThismenuBar = this;
1637         }
1638         // }}}
1639         ,
1640         // {{{ setTarget()
1641     /**
1642      *  Specify where this menu bar will be inserted. the element with this id will be parent of the menu bar.
1643      *
1644      *  @param String targetId = Id of element where the menu will be inserted.
1645      *
1646      * @public
1647      */
1648         setTarget : function(targetId)
1649         {
1650                 this.targetId = targetId;
1651
1652         }
1653         // }}}
1654         ,
1655         // {{{ setLayoutCss()
1656     /**
1657      *  Specify the css file for this menu bar
1658      *
1659      *  @param String layoutCSS = Name of new css file.
1660      *
1661      * @public
1662      */
1663         setLayoutCss : function(layoutCSS)
1664         {
1665                 this.layoutCSS = layoutCSS;
1666
1667         }
1668         // }}}
1669         ,
1670         // {{{ setMenuItemLayoutCss()
1671     /**
1672      *  Specify the css file for the menu items
1673      *
1674      *  @param String layoutCSS = Name of new css file.
1675      *
1676      * @public
1677      */
1678         setMenuItemLayoutCss : function(layoutCSS)
1679         {
1680                 this.menuItemLayoutCss = layoutCSS;
1681
1682         }
1683         // }}}
1684         ,
1685         // {{{ setCreateIframesForOldIeBrowsers()
1686     /**
1687      *  This method specifies if you want to the script to create iframes behind sub menu groups in order to cover eventual select boxes. This
1688      *  can be needed if you have users with older IE browsers(prior to version 7) and when there's a chance that a sub menu could appear on top
1689      *  of a select box.
1690      *
1691      *  @param Boolean createIframesForOldIeBrowsers = true if you want the script to create iframes to cover select boxes in older ie browsers.
1692      *
1693      * @public
1694      */
1695         setCreateIframesForOldIeBrowsers : function(createIframesForOldIeBrowsers)
1696         {
1697                 this.createIframesForOldIeBrowsers = createIframesForOldIeBrowsers;
1698
1699         }
1700         // }}}
1701         ,
1702         // {{{ addMenuItems()
1703     /**
1704      *  Add menu items
1705      *
1706      *  @param DHTMLSuite.menuModel menuModel Object of class DHTMLSuite.menuModel which holds menu data
1707      *
1708      * @public
1709      */
1710         addMenuItems : function(menuItemObj)
1711         {
1712                 this.menuItemObj = menuItemObj;
1713                 this.menuItems = menuItemObj.getItems();
1714         }
1715         // }}}
1716         ,
1717         // {{{ setActiveSubItemsOnMouseOver()
1718     /**
1719      *   Specify if sub menus should be activated on mouse over(i.e. no matter what the menuState property is).
1720      *
1721      *  @param Boolean activateSubOnMouseOver - Specify if sub menus should be activated on mouse over(i.e. no matter what the menuState property is).
1722      *
1723      * @public
1724      */
1725         setActiveSubItemsOnMouseOver : function(activateSubOnMouseOver)
1726         {
1727                 this.activeSubItemsOnMouseOver = activateSubOnMouseOver;
1728         }
1729         // }}}
1730         ,
1731         // {{{ setMenuItemState()
1732     /**
1733      *  This method changes the state of the menu bar(expanded or collapsed). This method is called when someone clicks on the arrow at the right of menu items.
1734      *
1735      *  @param Number menuItemId - ID of the menu item we want to switch state for
1736      *  @param String state - New state(example: "disabled")
1737      *
1738      * @public
1739      */
1740         setMenuItemState : function(menuItemId,state)
1741         {
1742                 this.menuItem_objects[menuItemId].setState(state);
1743         }
1744         // }}}
1745         ,
1746         // {{{ setMenuItemCssPrefix()
1747     /**
1748      *  Specify prefix of css classes used for the menu items. Default css prefix is "DHTMLSuite_". If you wish have some custom styling for some of your menus,
1749      *  create a separate css file and replace DHTMLSuite_ for the class names with your new prefix.  This is useful if you want to have two menus on the same page
1750      *  with different stylings.
1751      *
1752      *  @param String newCssPrefix - New css prefix for menu items.
1753      *
1754      * @public
1755      */
1756         setMenuItemCssPrefix : function(newCssPrefix)
1757         {
1758                 this.menuItemCssPrefix = newCssPrefix;
1759         }
1760         // }}}
1761         ,
1762         // {{{ setCssPrefix()
1763     /**
1764      *  Specify prefix of css classes used for the menu bar. Default css prefix is "DHTMLSuite_" and that's the prefix of all css classes inside menu-bar.css(the default css file).
1765      *  If you want some custom menu bars, create and include your own css files, replace DHTMLSuite_ in the class names with your own prefix and set the new prefix by calling
1766      *  this method. This is useful if you want to have two menus on the same page with different stylings.
1767      *
1768      *  @param String newCssPrefix - New css prefix for the menu bar classes.
1769      *
1770      * @public
1771      */
1772         setCssPrefix : function(newCssPrefix)
1773         {
1774                 this.cssPrefix = newCssPrefix;
1775         }
1776         // }}}
1777         ,
1778         // {{{ replaceSubMenus()
1779     /**
1780      *  This method replaces existing sub menu items with a new subset (To replace all menu items, pass 0 as parentId)
1781      *
1782      *
1783      *  @param Number parentId - ID of parent element ( 0 if top node) - if set, all sub elements will be deleted and replaced with the new menu model.
1784      *  @param menuModel newMenuModel - Reference to object of class menuModel
1785      *
1786      * @private
1787      */
1788         replaceMenuItems : function(parentId,newMenuModel)
1789         {
1790                 this.hideSubMenus();    // Hide all sub menus
1791                 this.__deleteMenuItems(parentId);       // Delete old menu items.
1792                 this.menuItemObj.__appendMenuModel(newMenuModel,parentId);      // Appending new menu items to the menu model.
1793                 this.__clearAllMenuItems();
1794                 this.__createMenuItems();
1795         }
1796
1797         // }}}
1798         ,
1799         // {{{ deleteMenuItems()
1800     /**
1801      *  This method deletes menu items from the menu dynamically
1802      *
1803      *  @param Number parentId - Parent id - where to append the new items.
1804      *  @param Boolean includeParent - Should parent element also be deleted, or only sub elements?
1805      *
1806      * @public
1807      */
1808         deleteMenuItems : function(parentId,includeParent)
1809         {
1810                 this.hideSubMenus();    // Hide all sub menus
1811                 this.__deleteMenuItems(parentId,includeParent);
1812                 this.__clearAllMenuItems();
1813                 this.__createMenuItems();
1814         }
1815         // }}}
1816         ,
1817         // {{{ appendMenuItems()
1818     /**
1819      *  This method appends menu items to the menu dynamically
1820      *
1821      *  @param Number parentId - Parent id - where to append the new items.
1822      *  @param menuModel newMenuModel - Object of type menuModel. This menuModel will be appended as sub elements of defined parentId
1823      *
1824      * @public
1825      */
1826         appendMenuItems : function(parentId,newMenuModel)
1827         {
1828                 this.hideSubMenus();    // Hide all sub menus
1829                 this.menuItemObj.__appendMenuModel(newMenuModel,parentId);      // Appending new menu items to the menu model.
1830                 this.__clearAllMenuItems();
1831                 this.__createMenuItems();
1832         }
1833         // }}}
1834         ,
1835         // {{{ hideMenuItem()
1836     /**
1837      *  This method doesn't delete menu items. it hides them only.
1838      *
1839      *  @param Number id - Id of the item you want to hide.
1840      *
1841      * @public
1842      */
1843         hideMenuItem : function(id)
1844         {
1845                 this.menuItem_objects[id].hide();
1846
1847         }
1848         // }}}
1849         ,
1850         // {{{ showMenuItem()
1851     /**
1852      *  This method shows a menu item. If the item isn't hidden, nothing is done.
1853      *
1854      *  @param Number id - Id of the item you want to show
1855      *
1856      * @public
1857      */
1858         showMenuItem : function(id)
1859         {
1860                 this.menuItem_objects[id].show();
1861         }
1862         // }}}
1863         ,
1864         // {{{ setText()
1865     /**
1866      *  Replace the text for a menu item
1867      *
1868      *  @param Integer id - Id of menu item.
1869      *  @param String newText - New text for the menu item.
1870      *
1871      * @public
1872      */
1873         setText : function(id,newText)
1874         {
1875                 this.menuItem_objects[id].setText(newText);
1876         }
1877         // }}}
1878         ,
1879         // {{{ setIcon()
1880     /**
1881      *  Replace menu icon for a menu item.
1882      *
1883      *  @param Integer id - Id of menu item.
1884      *  @param String newPath - Path to new menu icon. Pass blank or false if you want to clear the menu item.
1885      *
1886      * @public
1887      */
1888         setIcon : function(id,newPath)
1889         {
1890                 this.menuItem_objects[id].setIcon(newPath);
1891         }
1892         // }}}
1893         ,
1894         // {{{ __clearAllMenuItems()
1895     /**
1896      *  Delete HTML elements for all menu items.
1897      *
1898      * @private
1899      */
1900         __clearAllMenuItems : function()
1901         {
1902                 for(var prop=0;prop<this.menuItemObj.menuItemsOrder.length;prop++){
1903                         var id = this.menuItemObj.menuItemsOrder[prop];
1904                         if(this.submenuGroups[id]){
1905                                 this.submenuGroups[id].parentNode.removeChild(this.submenuGroups[id]);
1906                                 this.submenuGroups[id] = false;
1907                         }
1908                         if(this.submenuIframes[id]){
1909                                 this.submenuIframes[id].parentNode.removeChild(this.submenuIframes[id]);
1910                                 this.submenuIframes[id] = false;
1911                         }
1912                 }
1913                 this.menuBarObj.innerHTML = '';
1914         }
1915         // }}}
1916         ,
1917         // {{{ __deleteMenuItems()
1918     /**
1919      *  This method deletes menu items from the menu, i.e. menu model and the div elements for these items.
1920      *
1921      *  @param Number parentId - Parent id - where to start the delete process.
1922      *
1923      * @private
1924      */
1925         __deleteMenuItems : function(parentId,includeParent)
1926         {
1927                 if(includeParent)this.menuItemObj.__deleteANode(parentId);
1928                 if(!this.submenuGroups[parentId])return;        // No sub items exists.
1929                 this.menuItem_objects[parentId].__setHasSub(false);     // Delete existing sub menu divs.
1930                 this.menuItemObj.__deleteChildNodes(parentId);  // Delete existing child nodes from menu model
1931                 var groupBox = this.submenuGroups[parentId];
1932                 groupBox.parentNode.removeChild(groupBox);      // Delete sub menu group box.
1933                 if(this.submenuIframes[parentId]){
1934                         this.submenuIframes[parentId].parentNode.removeChild(this.submenuIframes[parentId]);
1935                 }
1936                 this.submenuGroups.splice(parentId,1);
1937                 this.submenuIframes.splice(parentId,1);
1938         }
1939         // }}}
1940         ,
1941         // {{{ __changeMenuBarState()
1942     /**
1943      *  This method changes the state of the menu bar(expanded or collapsed). This method is called when someone clicks on the arrow at the right of menu items.
1944      *
1945      *  @param Object obj - Reference to element triggering the action
1946      *
1947      * @private
1948      */
1949         __changeMenuBarState : function(){
1950                 var objectIndex = this.getAttribute('objectRef');
1951                 var obj = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[objectIndex];
1952                 var parentId = this.id.replace(/[^0-9]/gi,'');
1953                 var state = obj.menuItem_objects[parentId].getState();
1954                 if(state=='disabled')return;
1955                 obj.menuBarState = !obj.menuBarState;
1956                 if(!obj.menuBarState)obj.hideSubMenus();else{
1957                         obj.hideSubMenus();
1958                         obj.__expandGroup(parentId);
1959                 }
1960
1961         }
1962         // }}}
1963         ,
1964         // {{{ __createDivs()
1965     /**
1966      *  Create the main HTML elements for this menu dynamically
1967      *
1968      *
1969      * @private
1970      */
1971         __createDivs : function()
1972         {
1973                 window.refTomenuBar = this;     // Reference to menu strip object
1974
1975                 this.menuBarObj = document.createElement('DIV');
1976                 this.menuBarObj.className = this.cssPrefix + 'menuBar_' + this.menuItemObj.submenuType[1];
1977
1978                 if(!document.getElementById(this.targetId)){
1979                         alert('No target defined for the menu object');
1980                         return;
1981                 }
1982                 // Appending menu bar object as a sub of defined target element.
1983                 var target = document.getElementById(this.targetId);
1984                 target.appendChild(this.menuBarObj);
1985         }
1986         ,
1987         // {{{ hideSubMenus()
1988     /**
1989      *  Deactivate all sub menus ( collapse and set state back to regular )
1990      *  In case you have a menu inside a scrollable container, call this method in an onscroll event for that element
1991      *  example document.getElementById('textContent').onscroll = menuBar.__hideSubMenus;
1992      *
1993      *  @param Event e - this variable is present if this method is called from an event.
1994      *
1995      * @public
1996      */
1997         hideSubMenus : function(e)
1998         {
1999                 if(this && this.tagName){       /* Method called from event */
2000                         if(document.all)e = event;
2001                         var srcEl = DHTMLSuite.commonObj.getSrcElement(e);
2002                         if(srcEl.tagName.toLowerCase()=='img')srcEl = srcEl.parentNode;
2003                         if(srcEl.className && srcEl.className.indexOf('arrow')>=0){
2004                                 return;
2005                         }
2006                 }
2007                 for(var no=0;no<DHTMLSuite.variableStorage.menuBar_highlightedItems.length;no++){
2008                         DHTMLSuite.variableStorage.menuBar_highlightedItems[no].setState('regular');    // Set state back to regular
2009                         DHTMLSuite.variableStorage.menuBar_highlightedItems[no].__hideGroup();  // Hide eventual sub menus
2010                 }
2011                 DHTMLSuite.variableStorage.menuBar_highlightedItems = new Array();
2012         }
2013
2014         ,
2015         // {{{ __expandGroup()
2016     /**
2017      *  Expand a group of sub items.
2018      *  @param parentId - Id of parent element
2019      *
2020      * @private
2021      */
2022         __expandGroup : function(parentId)
2023         {
2024
2025                 var groupRef = this.submenuGroups[parentId];
2026                 var subDiv = groupRef.getElementsByTagName('DIV')[0];
2027
2028                 var numericId = subDiv.id.replace(/[^0-9]/g,'');
2029
2030                 groupRef.style.visibility='visible';    // Show menu group.
2031                 if(this.submenuIframes[parentId])this.submenuIframes[parentId].style.visibility = 'visible';    // Show iframe if it exists.
2032                 DHTMLSuite.variableStorage.menuBar_highlightedItems[DHTMLSuite.variableStorage.menuBar_highlightedItems.length] = this.menuItem_objects[numericId];
2033                 this.__positionSubMenu(parentId);
2034
2035                 if(DHTMLSuite.clientInfoObj.isOpera){   /* Opera fix in order to get correct height of sub menu group */
2036                         var subDiv = groupRef.getElementsByTagName('DIV')[0];   /* Find first menu item */
2037                         subDiv.className = subDiv.className.replace('_over','_over');   /* By "touching" the class of the menu item, we are able to fix a layout problem in Opera */
2038                 }
2039         }
2040
2041         ,
2042         // {{{ __activateMenuElements()
2043     /**
2044      *  Traverse up the menu items and highlight them.
2045      *
2046      *
2047      * @private
2048      */
2049         __activateMenuElements : function(inputObj,objectRef,firstIteration)
2050         {
2051                 if(!this.menuBarState && !this.activeSubItemsOnMouseOver)return;        // Menu is not activated and it shouldn't be activated on mouse over.
2052                 var numericId = inputObj.id.replace(/[^0-9]/g,'');      // Get a numeric reference to current menu item.
2053
2054                 var state = this.menuItem_objects[numericId].getState();        // Get state of this menu item.
2055                 if(state=='disabled')return;    // This menu item is disabled - return from function without doing anything.
2056
2057                 if(firstIteration && DHTMLSuite.variableStorage.menuBar_highlightedItems.length>0){
2058                         this.hideSubMenus();    // First iteration of this function=> Hide other sub menus.
2059                 }
2060                 // What should be the state of this menu item -> If it's the one the mouse is over, state should be "over". If it's a parent element, state should be "active".
2061                 var newState = 'over';
2062                 if(!firstIteration)newState = 'active'; // State should be set to 'over' for the menu item the mouse is currently over.
2063
2064                 this.menuItem_objects[numericId].setState(newState);    // Switch state of menu item.
2065                 if(this.submenuGroups[numericId]){      // Sub menu group exists. call the __expandGroup method.
2066                         this.__expandGroup(numericId);  // Expand sub menu group
2067                 }
2068                 DHTMLSuite.variableStorage.menuBar_highlightedItems[DHTMLSuite.variableStorage.menuBar_highlightedItems.length] = this.menuItem_objects[numericId];     // Save this menu item in the array of highlighted elements.
2069                 if(objectRef.menuItems[numericId].parentId){    // A parent element exists. Call this method over again with parent element as input argument.
2070                         this.__activateMenuElements(objectRef.menuItem_objects[objectRef.menuItems[numericId].parentId].divElement,objectRef,false);
2071                 }
2072         }
2073         // }}}
2074         ,
2075         // {{{ __createMenuItems()
2076     /**
2077      *  Creates the HTML elements for the menu items.
2078      *
2079      *
2080      * @private
2081      */
2082         __createMenuItems : function()
2083         {
2084                 if(!this.globalObjectIndex)this.globalObjectIndex = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects.length;;
2085                 var index = this.globalObjectIndex;
2086                 DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[index] = this;
2087
2088                 // Find first child of the body element. trying to insert the element before first child instead of appending it to the <body> tag, ref: problems in ie
2089                 var firstChild = false;
2090                 var firstChilds = document.getElementsByTagName('DIV');
2091                 if(firstChilds.length>0)firstChild = firstChilds[0]
2092
2093                 for(var no=0;no<this.menuItemObj.menuItemsOrder.length;no++){   // Looping through menu items
2094                         var indexThis = this.menuItemObj.menuItemsOrder[no];
2095                         if(!this.menuItems[indexThis].id)continue;
2096                         this.menuItem_objects[this.menuItems[indexThis].id] = new DHTMLSuite.menuItem();
2097                         if(this.menuItemCssPrefix)this.menuItem_objects[this.menuItems[indexThis].id].setCssPrefix(this.menuItemCssPrefix);     // Custom css prefix set
2098                         if(this.menuItemLayoutCss)this.menuItem_objects[this.menuItems[indexThis].id].setLayoutCss(this.menuItemLayoutCss);     // Custom css file name
2099
2100                         var ref = this.menuItem_objects[this.menuItems[indexThis].id].createItem(this.menuItems[indexThis]); // Create div for this menu item.
2101
2102                         // Actiave sub elements when someone moves the mouse over the menu item - exception: not on separators.
2103                         if(!this.menuItems[indexThis].separator)DHTMLSuite.commonObj.addEvent(ref,"mouseover",function(){ DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[index].__activateMenuElements(this,DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[index],true); });
2104
2105                         if(this.menuItem_objects[this.menuItems[indexThis].id].expandElement){  /* Small arrow at the right of the menu item exists - expand subs */
2106                                 var expandRef = this.menuItem_objects[this.menuItems[indexThis].id].expandElement;      /* Creating reference to expand div/arrow div */
2107                                 var parentId = DHTMLSuite.variableStorage.arrayOfDhtmlSuiteObjects[index].menuItems[indexThis].parentId + '';   // Get parent id.
2108                                 var tmpId = expandRef.id.replace(/[^0-9]/gi,'');
2109                                 expandRef.setAttribute('objectRef',index);      /* saving the index of this object in the DHTMLSuite.variableStorage array as a property of the tag - We need to do this in order to avoid circular references and thus memory leakage in IE */
2110                                 expandRef.objectRef = index;
2111                                 expandRef.onclick = this.__changeMenuBarState;
2112                         }
2113                         var target = this.menuBarObj;   // Temporary variable - target of newly created menu item. target can be the main menu object or a sub menu group(see below where target is updated).
2114
2115                         if(this.menuItems[indexThis].depth==1 && this.menuItemObj.submenuType[this.menuItems[indexThis].depth]!='top' && this.menuItemObj.mainMenuGroupWidth){  /* Main menu item group width set */
2116                                 var tmpWidth = this.menuItemObj.mainMenuGroupWidth + '';
2117                                 if(tmpWidth.indexOf('%')==-1)tmpWidth = tmpWidth + 'px';
2118                                 target.style.width = tmpWidth;
2119                         }
2120
2121                         if(this.menuItems[indexThis].depth=='1'){       /* Top level item */
2122                                 if(this.menuItemObj.submenuType[this.menuItems[indexThis].depth]=='top'){       /* Type = "top" - menu items side by side */
2123                                         ref.style.styleFloat = 'left';
2124                                         ref.style.cssText = 'float:left';
2125                                 }
2126                         }else{
2127                                 if(!this.menuItems[indexThis].depth){
2128                                         alert('Error in menu model(depth not defined for a menu item). Remember to call the init() method for the menuModel object.');
2129                                         return;
2130                                 }
2131                                 if(!this.submenuGroups[this.menuItems[indexThis].parentId]){    // Sub menu div doesn't exist - > Create it.
2132                                         this.submenuGroups[this.menuItems[indexThis].parentId] = document.createElement('DIV');
2133                                         this.submenuGroups[this.menuItems[indexThis].parentId].style.zIndex = 10000;
2134                                         this.submenuGroups[this.menuItems[indexThis].parentId].id = 'DHTMLSuite_menuBarSubGroup' + this.menuItems[indexThis].parentId;
2135                                         this.submenuGroups[this.menuItems[indexThis].parentId].style.visibility = 'hidden';     // Initially hidden.
2136                                         if(this.menuItemObj.submenuType[this.menuItems[indexThis].depth]=='sub')this.submenuGroups[this.menuItems[indexThis].parentId].className = this.cssPrefix + 'menuBar_sub';
2137                                         if(firstChild){
2138                                                 firstChild.parentNode.insertBefore(this.submenuGroups[this.menuItems[indexThis].parentId],firstChild);
2139                                         }else{
2140                                                 document.body.appendChild(this.submenuGroups[this.menuItems[indexThis].parentId]);
2141                                         }
2142
2143                                         if(DHTMLSuite.clientInfoObj.isMSIE && this.createIframesForOldIeBrowsers){      // Create iframe object in order to conver select boxes in older IE browsers(windows).
2144                                                 this.submenuIframes[this.menuItems[indexThis].parentId] = document.createElement('<IFRAME src="about:blank" frameborder=0>');
2145                                                 this.submenuIframes[this.menuItems[indexThis].parentId].id = 'DHTMLSuite_menuBarIframe_' + this.menuItems[indexThis].parentId;
2146                                                 this.submenuIframes[this.menuItems[indexThis].parentId].style.position = 'absolute';
2147                                                 this.submenuIframes[this.menuItems[indexThis].parentId].style.zIndex = 9000;
2148                                                 this.submenuIframes[this.menuItems[indexThis].parentId].style.visibility = 'hidden';
2149                                                 if(firstChild){
2150                                                         firstChild.parentNode.insertBefore(this.submenuIframes[this.menuItems[indexThis].parentId],firstChild);
2151                                                 }else{
2152                                                         document.body.appendChild(this.submenuIframes[this.menuItems[indexThis].parentId]);
2153                                                 }
2154                                         }
2155                                 }
2156                                 target = this.submenuGroups[this.menuItems[indexThis].parentId];        // Change target of newly created menu item. It should be appended to the sub menu div("A group box").
2157                         }
2158                         target.appendChild(ref); // Append menu item to the document.
2159
2160                         if(this.menuItems[indexThis].visible == false)this.hideMenuItem(this.menuItems[indexThis].id);  // Menu item hidden, call the hideMenuItem method.
2161                         if(this.menuItems[indexThis].state != 'regular')this.menuItem_objects[this.menuItems[indexThis].id].setState(this.menuItems[indexThis].state);  // Menu item hidden, call the hideMenuItem method.
2162
2163                 }
2164
2165
2166                 this.__setSizeOfAllSubMenus();  // Set size of all sub menu groups
2167                 this.__positionAllSubMenus();   // Position all sub menu groups.
2168                 if(DHTMLSuite.clientInfoObj.isOpera)this.__fixLayoutOpera();    // Call a function which fixes some layout issues in Opera.
2169         }
2170         // }}}
2171         ,
2172         // {{{ __fixLayoutOpera()
2173     /**
2174      *  A method used to fix the menu layout in Opera.
2175      *
2176      *
2177      * @private
2178      */
2179         __fixLayoutOpera : function()
2180         {
2181                 for(var no=0;no<this.menuItemObj.menuItemsOrder.length;no++){
2182                         var id = this.menuItemObj.menuItemsOrder[no];
2183                         if(!id)continue;
2184                         this.menuItem_objects[id].divElement.className = this.menuItem_objects[id].divElement.className.replace('_regular','_regular'); // Nothing is done but by "touching" the class of the menu items in Opera, we make them appear correctly
2185                 }
2186         }
2187
2188         // }}}
2189         ,
2190         // {{{ __setSizeOfAllSubMenus()
2191     /**
2192      *  *       Walk through all sub menu groups and call the positioning method for each one of them.
2193      *
2194      *
2195      * @private
2196      */
2197         __setSizeOfAllSubMenus : function()
2198         {
2199                 for(var prop in this.submenuGroups){
2200                         this.__setSizeOfSubMenus(prop);
2201                 }
2202         }
2203         // }}}
2204         ,
2205         // {{{ __positionAllSubMenus()
2206     /**
2207      *  Walk through all sub menu groups and call the positioning method for each one of them.
2208      *
2209      *
2210      * @private
2211      */
2212         __positionAllSubMenus : function()
2213         {
2214                 for(var prop in this.submenuGroups){
2215                         this.__positionSubMenu(prop);
2216                 }
2217
2218         }
2219         // }}}
2220         ,
2221         // {{{ __positionSubMenu(parentId)
2222     /**
2223      *  Position a sub menu group
2224      *
2225      *  @param parentId
2226      *
2227      * @private
2228      */
2229         __positionSubMenu : function(parentId)
2230         {
2231                 try{
2232                         var shortRef = this.submenuGroups[parentId];
2233
2234                         if( shortRef.style.visibility == 'hidden' )
2235                   {
2236                     shortRef.style.display = 'none';
2237                     return;
2238                   }
2239                         else
2240                           shortRef.style.display = 'block';
2241
2242                         var depth = this.menuItems[parentId].depth;
2243                         var dir = this.menuItemObj.submenuType[depth];
2244                         if(dir=='top'){
2245                                 shortRef.style.left = DHTMLSuite.commonObj.getLeftPos(this.menuItem_objects[parentId].divElement) + 'px';
2246                                 shortRef.style.top = (DHTMLSuite.commonObj.getTopPos(this.menuItem_objects[parentId].divElement) + this.menuItem_objects[parentId].divElement.offsetHeight) + 'px';
2247                         }else{
2248               var too_large = DHTMLSuite.commonObj.getLeftPos(this.menuItem_objects[parentId].divElement)
2249                             + this.menuItem_objects[parentId].divElement.offsetWidth
2250                             + shortRef.offsetWidth
2251                             > $('#main_menu_div').width();
2252               if (too_large)
2253                 shortRef.style.left = (DHTMLSuite.commonObj.getLeftPos(this.menuItem_objects[parentId].divElement) - shortRef.offsetWidth) + 'px';
2254               else
2255                                 shortRef.style.left = (DHTMLSuite.commonObj.getLeftPos(this.menuItem_objects[parentId].divElement) + this.menuItem_objects[parentId].divElement.offsetWidth) + 'px';
2256                                 shortRef.style.top = (DHTMLSuite.commonObj.getTopPos(this.menuItem_objects[parentId].divElement)) + 'px';
2257                         }
2258
2259                         if(DHTMLSuite.clientInfoObj.isMSIE){
2260                                 var iframeRef = this.submenuIframes[parentId]
2261                                 iframeRef.style.left = shortRef.style.left;
2262                                 iframeRef.style.top = shortRef.style.top;
2263                                 iframeRef.style.width = shortRef.clientWidth + 'px';
2264                                 iframeRef.style.height = shortRef.clientHeight + 'px';
2265                         }
2266
2267                 }catch(e){
2268
2269                 }
2270         }
2271         // }}}
2272         ,
2273         // {{{ __setSizeOfSubMenus(parentId)
2274     /**
2275      *  Set size of a sub menu group
2276      *
2277      *  @param parentId
2278      *
2279      * @private
2280      */
2281         __setSizeOfSubMenus : function(parentId)
2282         {
2283                 try{
2284                         var shortRef = this.submenuGroups[parentId];
2285                         var subWidth = Math.max(shortRef.offsetWidth,this.menuItem_objects[parentId].divElement.offsetWidth);
2286                         if(this.menuItems[parentId].submenuWidth)subWidth = this.menuItems[parentId].submenuWidth;
2287                         subWidth = subWidth + '';
2288                         if(subWidth.indexOf('%')==-1)subWidth = subWidth + 'px';
2289                         shortRef.style.width = subWidth;
2290
2291                         if(DHTMLSuite.clientInfoObj.isMSIE){
2292                                 this.submenuIframes[parentId].style.width = shortRef.style.width;
2293                                 this.submenuIFrames[parentId].style.height = shortRef.style.height;
2294                         }
2295                 }catch(e){
2296
2297                 }
2298
2299         }
2300         // }}}
2301         ,
2302         // {{{ __repositionMenu()
2303     /**
2304      *  Position menu items.
2305      *
2306      *
2307      * @private
2308      */
2309         __repositionMenu : function(inputObj)
2310         {
2311                 // self.status = this;
2312                 inputObj.menuBarObj.style.top = document.documentElement.scrollTop + 'px';
2313
2314         }
2315
2316         // }}}
2317         ,
2318         // {{{ __menuItemRollOver()
2319     /**
2320      *  Position menu items.
2321      *
2322      *
2323      * @private
2324      */
2325         __menuItemRollOver : function(inputObj)
2326         {
2327                 var numericId = inputObj.id.replace(/[^0-9]/g,'');
2328                 inputObj.className = 'DHTMLSuite_menuBar_menuItem_over_' + this.menuItems[numericId]['depth'];
2329         }
2330         // }}}
2331         ,
2332         // {{{ __menuItemRollOut()
2333     /**
2334      *  Position menu items.
2335      *
2336      *
2337      * @private
2338      */
2339         __menuItemRollOut : function(inputObj)
2340         {
2341                 var numericId = inputObj.id.replace(/[^0-9]/g,'');
2342                 inputObj.className = 'DHTMLSuite_menuBar_menuItem_' + this.menuItems[numericId]['depth'];
2343         }
2344         // }}}
2345         ,
2346         // {{{ __menuNavigate()
2347     /**
2348      *  Navigate by click on a menu item
2349      *
2350      *
2351      * @private
2352      */
2353         __menuNavigate : function(inputObj)
2354         {
2355                 var numericIndex = inputObj.id.replace(/[^0-9]/g,'');
2356                 var url = this.menuItems[numericIndex]['url'];
2357                 if(!url)return;
2358                 alert(this.menuItems[numericIndex]['url']);
2359
2360         }
2361         // }}}
2362         ,
2363     unsetMenuBarState : function() { this.menuBarState = false },
2364     changeMenuBarState: function (target) {
2365            var parentId = target.id.replace(/[^0-9]/gi,'');
2366            this.menuBarState = !this.menuBarState;
2367        this.hideSubMenus();
2368            if(this.menuBarState) {
2369                 this.__expandGroup(parentId);
2370        }
2371     },
2372         // {{{ __setBasicEvents()
2373     /**
2374      *  Set basic events for the menu widget.
2375      *
2376      *
2377      * @private
2378      */
2379         __setBasicEvents : function()
2380         {
2381         var menu = this;
2382         $('div.DHTMLSuite_menuBar_sub').click(function() { menu.hideSubMenus(); menu.unsetMenuBarState() });
2383         $('div.DHTMLSuite_menuBar_top > div > div[objectref!="0"]').click(function() { menu.changeMenuBarState(this) });
2384         $('div.DHTMLSuite_menuBar_top').click(function(e) {
2385           if ($(e.target).attr('class') == 'DHTMLSuite_menuBar_top') { menu.hideSubMenus(); menu.unsetMenuBarState() }
2386         });
2387         $('#win1').load(function(){
2388             $('#win1').contents().mousedown(function(){
2389                 menu.hideSubMenus();
2390                 menu.menuBarState = false;
2391             });
2392         })
2393         }
2394 }
2395
2396