﻿var SHMMSF = {

    attachMenu: function(menu_id, nav_top_id, nav_down_id, mov_speed, time_speed) {
        var menu = document.getElementById(menu_id);

        if(menu == null){ return ;}
        
        menu.style.position = 'relative';
        menu.style.overflow = 'hidden';

        menu.content = menu.childNodes[0];
        menu.content.top = 0;
        menu.content.style.position = 'relative';

        //menu.navtop = document.getElementById(nav_top_id);
        //menu.navdown = document.getElementById(nav_down_id);

        //menu.navtop.onclick = function(e){ SHMCORE.cancelBubble(e); };
        //menu.navtop.onmousedown = function() { SHMMSF.moveStop(menu); SHMMSF.moveUp(menu); };
        //menu.navtop.onmouseup = function() { SHMMSF.moveStop(menu); };
        //menu.navtop.style.cursor = 'pointer';

        //menu.navdown.onclick = function(e){ SHMCORE.cancelBubble(e); };
        //menu.navdown.onmousedown = function() { SHMMSF.moveStop(menu); SHMMSF.moveDown(menu); };
        //menu.navdown.onmouseup = function() { SHMMSF.moveStop(menu); };
        //menu.navdown.style.cursor = 'pointer';

        menu.ms = (mov_speed) == undefined ? 15 : mov_speed; /* moving speed */
        menu.ts = (time_speed) == undefined ? 100 : time_speed; /* move per second */
        menu.mt = null; /* moving time timer */
      
    },

    moveUp: function(menu) {
        menu.mt = setInterval(function() { SHMMSF.move(menu, -1); }, menu.ts);
    },

    moveDown: function(menu) {
        menu.mt = setInterval(function() { SHMMSF.move(menu, 1); }, menu.ts);
    },

    moveStop: function(menu) {
        clearInterval(menu.mt);
    },

    move: function(menu, direction) {

        var content = menu.content;
        var remainder = 0;

        if (direction < 0) {
            remainder = (content.offsetTop + content.offsetHeight) - menu.offsetHeight;
            if (remainder <= 0) { clearInterval(menu.mt); return; }
        }
        else {
            remainder = content.offsetTop;
            if (remainder >= 0) { clearInterval(menu.mt); return; }
        }

        remainder = Math.abs(remainder);

        content.top += ((menu.ms > remainder) ? remainder : menu.ms) * direction;
        content.style.top = content.top + 'px';

    },

    getMenuContent: function(menu) {
        return menu.content;
    }
};

var SHMCORE = {

    isIE: function() {
        return (navigator.appName == 'Microsoft Internet Explorer');
    },
    
    cancelBubble: function(e){
    
        if(this.isIE())
            window.event.cancelBubble = true;
        else
            e.stopPropagation();
    }
};