YAHOO.namespace('portal.modal');

YAHOO.portal.modal = function() {

    return {
            open: function() { var tag;
                if (navigator.userAgent.indexOf('MSIE') != -1) {
                    tag = document.all[1];
                } else {
                    tag = document.body;
                }
                YAHOO.util.Dom.setStyle(tag, "overflow", "hidden");
                var _height = YAHOO.util.Dom.getClientHeight();
                var _top = YAHOO.util.Dom.getDocumentScrollTop();
                var _width = YAHOO.util.Dom.getClientWidth();
                YAHOO.util.Dom.setStyle('faded', 'top', '0px');
                YAHOO.util.Dom.setStyle('faded', 'height', YAHOO.util.Dom.getDocumentHeight().toString()+'px');

                YAHOO.util.Dom.setStyle('popup_window', 'top', (_top+0.10*_height).toString()+'px');
                YAHOO.util.Dom.setStyle('popup_window', 'height', (_height-2*0.10*_height).toString()+'px');
                YAHOO.util.Dom.setStyle('popup_window', 'width', (0.80*_width).toString()+'px');

                YAHOO.util.Dom.setStyle('modal_scroll', 'height', (_height-2*0.10*_height-20).toString()+'px');
                YAHOO.util.Dom.setStyle('modal_scroll', 'overflow', 'auto');
                YAHOO.util.Dom.setStyle('modal_scroll', 'width', (_width*0.80*0.65-13).toString()+'px');

                YAHOO.util.Dom.setStyle('modal_comp', 'width', (_width*0.80*0.35-10).toString()+'px');
                
                YAHOO.util.Dom.setStyle("popup_window", "display", "block");
                
                YAHOO.util.Dom.setStyle("faded", "display", "block");
            },

            close: function() { var tag;
                if (navigator.userAgent.indexOf('MSIE') != -1) {
                    tag = document.all[1];
                } else {
                    tag = document.body;
                }
                YAHOO.util.Dom.setStyle(tag, "overflow", "auto");
                YAHOO.util.Dom.setStyle("popup_window", "display", "none");
                YAHOO.util.Dom.setStyle("faded", "display", "none");
            },

            highlight: function() {
                var lines = YAHOO.util.Dom.getElementsByClassName('hll', 'span');

                for (var i=0; i<lines.length; ++i) {


                    var line_num = YAHOO.util.Dom.getAttribute(YAHOO.util.Dom.getPreviousSibling(YAHOO.util.Dom.getPreviousSibling(lines[i])), 'name');
                    var line = YAHOO.util.Dom.get('line-' + line_num);
                    
                    YAHOO.util.Event.on(line, "mouseenter", function (e) {

                        var block_class = 'block_' + YAHOO.util.Dom.getAttribute(this, 'rel');

                        var elements = YAHOO.util.Dom.getElementsByClassName(block_class, 'div');


                        for (var j=0; j<elements.length; ++j){
                            YAHOO.util.Dom.addClass(elements[j], 'block_hl');
                            
                        }

                        var comment_id = YAHOO.util.Dom.getAttribute(this, 'id').replace('line-', 'comment-');
                        YAHOO.util.Dom.setStyle(comment_id, 'display', 'block');

                    });

                    YAHOO.util.Event.on(line, "mouseleave", function (e) {

                        var block_class = 'block_' + YAHOO.util.Dom.getAttribute(this, 'rel');

                        var elements = YAHOO.util.Dom.getElementsByClassName(block_class, 'div');

                        for (var j=0; j<elements.length; ++j){
                            YAHOO.util.Dom.removeClass(elements[j], 'block_hl');
                        }
                        var comment_id = YAHOO.util.Dom.getAttribute(this, 'id').replace('line-', 'comment-');
                        YAHOO.util.Dom.setStyle(comment_id, 'display', 'none');

                    });
                }

            }
    }
}();

    