﻿var rMenu = {
    menuShowed: false,
    menuItemEnter: function (e) {
        $('#mainMenu>.groupItem').hide();
        var jt = $(e.target);
        var id = jt.attr('id');
        id = id.replace(/[a-z]*/, '');
        var mm = $("#mainMenu");
        var jm = mm.find('.groupItem.grpid' + id);
        if (jm.length == 0) { $('#mainMenu').hide(); return; }
        var bw = $('body').width();
        var mw = 0;
        if (e.pageX > bw / 2) { mm.css('left', (jt.offset().left - jt.width()) + "px"); }
        else {
            mm.css('left', (jt.offset().left) + "px");
        }
        mm.find('.groupItem.grpid' + id).show();
        rMenu.menuShowed = true;
        $('#mainMenu').show();
    },
    listEnter: function (e) { },
    listExit: function (e) { $('#mainMenu').hide(); }

};
var romashka = {
    initDataTable: function () {
        $('.datatable').bind('scroll', function (e) { romashka.tableScroll(e); });
    },
    tableScroll: function (e) {
        $('tr.tableHead').css('top', $('.datatable').scrollTop() + 'px');
    },
    init: function () {
        romashka.processGroups();
        romashka.fixBtm();
        romashka.initMainMenu();
        romashka.initDataTable();
        if ($.browser.msie) { if ($.browser.version == '6.0') { return; } }
        var sth = $('#superTop').height();
        $('#container').prepend('<div style="height:' + sth + 'px;">&nbsp;</div>');
    },
    initMainMenu: function () {
        $('.rootLink').bind('mouseenter', function (e) { rMenu.menuItemEnter(e); });
        $('body').prepend('<div id="mainMenu"></div>');
        $('.groupItem').clone().appendTo('#mainMenu');
        $('#mainMenu .groupItem').removeAttr('style');
        $('#mainMenu').bind('mouseenter', function (e) { rMenu.listEnter(e); });
        $('#mainMenu').bind('mouseleave', function (e) { rMenu.listExit(e); });
    },
    processGroups: function () {
        var gid = $('#groupId').val();
        var pid = $('#pageId').val();
        if (gid == '0') {
            $('.groupItem').slideUp('slow');
            return;
        }
        $('.groupItem').toggle();
        if (gid != '0') {
            $('.groupItem.grpid' + gid).slideDown('slow');
        }
        $('.groupItem.grpid' + pid).slideDown('slow');
    },
    fixBtm: function () {
        var sh = screen.height;
        var bh = $('body').height();
        var ie6 = false;
        if ($.browser.msie) {
            if ($.browser.version == '6.0') {
                ie6 = true;
            }
        }
        if (bh < sh) {
            if (!ie6) {
                var jd = $('#subBtm');
                jd.css('position', 'static');
                jd.css('margin-top', (sh - bh - (ie6 ? 80 : 0)) + 'px');
                //$('body').height($('body').height() + (sh - bh));
            }
            else {
                if (ie6) { $('#contentLeft').height(600); }
            }
        }
    }
}
$(document).bind('ready', function () { romashka.init(); });
