var popup = (function()
{
    var that = 
    {
        $popup: $('#popup'),
        left_shift: 150,
        top_shift: -40,
        right_shift: 60,
        width: 450,

        init: function() {
            var $popup = $('#popup');

            // li mouseover
            $('#catalog li').mouseover(function(e) {
                var text = $(this).find('.desc').html();
                if (text)
                {
                    that.text(text);
                    that.show(this);                    
                }

            });

            // li mouseout
            $('#catalog li').mouseout(function(e)  { $popup.hide(); });


            // popup mouseover
            $popup.mouseover(function() {
                $(this).show(); 
            });

            // popup mouseover
            $popup.mouseout(function() { 
                $(this).hide();
            });
            
            $('#catalog li').each(function(index, el) {
                var i = index+1;
                if (i % 4 == 0 || (i+1) % 4 == 0)
                    $(el).addClass('popup_right');
            });
        },

        show: function(li_element) {
            var pos = $(li_element).position();
            var li_width = $(li_element).width();


            var is_right = $(li_element).hasClass('popup_right') ? true : false;
            var top = Math.round(pos.top) + that.top_shift;
            var left = Math.round(pos.left) + that.left_shift;
            var right = $(document.body).width() - Math.round(pos.left + that.right_shift) - 20;

            $('#popup').css({
                top: top,
                display: 'block'
            });

            if (is_right)
            {
                $('#popup').addClass('is_right');
                $('#popup').css({
                    left: 'auto',
                    right: right
                });
            }
            else
            {
                $('#popup').removeClass('is_right');
                $('#popup').css({
                    left: left,
                    right: 'auto'
                });
            }
                
        },

        text: function(text) {
            $('#popup').find('.in').html(text);
        }
    }
    return that;
})();

var toggleDistribution = (function (def) 
{
    function init() {
        $('#regions a').click(function(e) {
            var href = $(this).attr('href');
            showHideMap(href);
        });
        
        showHideMap(def);
    }
    
    function showHideMap(el) {
        $(el).show().siblings().hide();
        $(el +'_addresses').show().siblings().hide();
        
        $('#regions a').removeClass('active');
        $('a[href="'+ el + '"]').addClass('active');
    }
    init();
});

var toggleSearch = (function (el) {
    if (el.value == "") el.value = "Найти";
});

function Selector()
{
    
}

Selector.prototype = {
    options: {
        id: 'selector'
    },

    init: function()
    {
        
    }
}


