var menuItems = new menuStore();

function pageInit() {
    jQuery(menuItems.ids).each(function() {
        var id = this;

        jQuery('#mi' + id).mouseover(function() {
            var pic = jQuery(this);
            var em = jQuery('#im' + id);

            pic.css('background', menuItems.getHighlight(id));

            em.slideToggle("slow", function() {
                jQuery.timer(100, function(timer) {
                    if (!isMouseInside(pic)) {
                        pic.css('background', menuItems.getOriginal(id));
                        em.slideToggle('slow');
                        timer.stop();
                    }
                });
            });
        });

        jQuery('#micell' + id).mousedown(function() {
            if (jQuery('#mi' + id).attr('href') != undefined)
                document.location.href = menuItems.getLink(id);
        });
    });
}

function isMouseInside(elem) {
    return tempX >= elem.offset().left && tempX <= elem.offset().left + 95 && tempY >= elem.offset().top && tempY <= elem.offset().top + 25;
}

function menuStore() {
    this.ids = new Array();
    this.originals = new Array();
    this.highlights = new Array();
    this.links = new Array();
    this.slides = new Array();

    this.getOriginal = function(in_id) {
        return this.originals[in_id];
    };

    this.getHighlight = function(in_id) {
        return this.highlights[in_id];
    };

    this.getLink = function(in_id) {
        return this.links[in_id];
    };

    this.getSlide = function(in_id) {
        return this.slides[in_id];
    };

    this.setItem = function(in_id, in_color, in_highlight, in_link) {
        if (typeof(in_id) != 'undefined' && typeof(in_color) != 'undefined' && typeof(in_highlight) != 'undefined' && typeof(in_link) != 'undefined') {
            this.ids.push(in_id);
            this.originals[in_id] = 'url(\'/images/' + in_color + '/mbgr.gif\') repeat-x 0 0';
            this.highlights[in_id] = 'url(\'/images/' + in_highlight + '/mbgr.gif\') repeat-x 0 0';
            this.links[in_id] = in_link;
            this.slides[in_id] = '/images/m0' + in_id + 'a.gif';
        }
    };
}
