jQuery.noConflict();
var j$ = jQuery;

j$(function() {
    var duration    = 100;
    var actived     = false;
    var category_id = location.search.replace(/^\?/, '').match(/category_id=([\d]+)/) ? RegExp.$1: '';

    j$('a.leftmenu_subtitle_link').each(function(index) {
        j$(this).click(function() {
            location.href = j$(this).attr('href');
            return false;
        });

        var flg = category_id && j$(this).attr('href').match(/category_id=([\d]+)/) && category_id == RegExp.$1 ? true: false;

        if (flg)
            j$(this).children('img').addClass('active');

        if (!j$(this).attr('rel'))
            return true;

        var sc = 'ul.' + j$(this).attr('rel');

        if (!j$(sc))
            return true;

        if (flg) {
            j$(sc).addClass('active');
        } else if (!flg && category_id) {
            j$(sc + ' li').each(function(index2) {
                if (j$(this).children('a').attr('href').match(/category_id=([\d]+)/) && category_id == RegExp.$1) {
                    flg = true;
                    j$(this).addClass('active');
                    j$(this).children('a').click(function() {
                        return false;
                    });
                    return false;
                }
            });
            if (flg) {
                j$(this).children('img').addClass('active');
                j$(sc).addClass('active');
            }
        }

        j$(this).click(function() {
            var speed = duration * j$(sc + ' li').length;
                speed = speed > 500 ? 500: speed;

            if (j$(sc).is(":hidden")) {
                if (!j$.support.style)
                    j$(sc).show();
                else
                    j$(sc).slideDown(speed);

                if (category_id && j$(this).attr('href').match(/category_id=([\d]+)/) && category_id == RegExp.$1)
                    return false;

            } else {
                if (!j$.support.style)
                    j$(sc).hide();
                else
                    j$(sc).slideUp(speed);

                return false;
            }

            return true;
        });

        actived = flg ? true: actived;
    });

    if (category_id && !actived) {
        j$('a.leftmenu_brand_link').each(function(index) {
            if (category_id && j$(this).attr('href').match(/category_id=([\d]+)/) && category_id == RegExp.$1) {
                j$(this).children('img').addClass('active');
                actived = true;
                j$(this).click(function() {
                    return false;
                });
                return false;
            }
        });
    }

    if (!actived) {
        j$('ul.leftmenu_information_items li').each(function(index) {
            if (category_id && j$(this).children('a').attr('href').match(/category_id=([\d]+)/) && category_id == RegExp.$1) {
                j$(this).addClass('active');
                actived = true;
                j$(this).children('a').click(function() {
                    return false;
                });
                return false;

            } else if (location.href.match(j$(this).children('a').attr('href'))) {
                j$(this).addClass('active');
                actived = true;
                j$(this).children('a').click(function() {
                    return false;
                });
                return false;
            }
        });
    }
});

