1/**
2 * Highlight the section when hovering over the appropriate section edit button
3 *
4 * @author Christophe Drevet <christophe.drevet@gmail.com>
5 */
6addInitEvent(function(){
7    // detect header and its level
8    var class_regexp = new RegExp('H([1-5])');
9    var btns = getElementsByClass('btn_secedit',document,'form');
10    for(var i=0; i<btns.length; i++){
11        // Remove existing mouseover events
12        var btnhdls = btns[i].events['mouseover'];
13        for(btnhdl in btnhdls){
14            removeEvent(btns[i],'mouseover',btnhdls[btnhdl]);
15        }
16        addEvent(btns[i],'mouseover',function(e){
17            var tgt = e.target.form.parentNode;
18            tgtlvl = '0';
19            // walk in all the nodes
20            while(tgt != null){
21                if(typeof tgt.className !== 'undefined') {
22                    //(class_regexp.test(tgt.className) == true)){
23                    if(tgtlvl === '0') {
24                        if (class_regexp.test(tgt.tagName) == true){
25                            // We get the starting level
26                            tgtlvl = class_regexp.exec(tgt.tagName)[1];
27                        }
28                    } else {
29                        if(JSINFO['es_order_type'] == 'flat'){
30                            // flat : stop at the next header
31                            if (class_regexp.test(tgt.tagName) == true) {
32                                break;
33                            }
34                        } else {
35                            // nested
36                            if(tgtlvl !== '0'){
37                                // Break the loop if the level is lower than the starting level
38                                if((class_regexp.test(tgt.tagName) == true)&&(class_regexp.exec(tgt.tagName)[1] <= tgtlvl)) {
39                                    break;
40                                }
41                            }
42                        }
43                    }
44                    // highlight this element
45                    tgt.className += ' section_highlight';
46                }
47                tgt = tgt.nextSibling;
48            }
49        });
50
51        addEvent(btns[i],'mouseout',function(e){
52            var secs = getElementsByClass('section_highlight');
53            for(var j=0; j<secs.length; j++){
54                secs[j].className = secs[j].className.replace(/ ?section_highlight/,'');
55            }
56            var secs = getElementsByClass('section_highlight');
57        });
58    }
59});
60