jQuery.fn.downUp = function(options)
{
    var options = jQuery.extend
    (
        {
            downImgSrc: '',
            upImgSrc: '',
            arrowIdPrefix: '',
            downUpBlockIdPrefix: ''
        }, options
    );
        
    return this.each
    (
        function()
        {
            var arrow = jQuery(this);
            var id = arrow.attr('id').substr(options.arrowIdPrefix.length);
            var downUpBlock = jQuery('#' + options.downUpBlockIdPrefix + id);

            if (downUpBlock.is(':visible'))
            {
            arrow.toggle
            (
                function()
                {
                    this.src = options.downImgSrc;
                    downUpBlock.hide();
                    jQuery.cookie('du' + id, null, {path: '/'});
                },
                function()
                {
                    this.src = options.upImgSrc;
                    downUpBlock.show();
                    jQuery.cookie('du' + id, '1', {path: '/'});
                }
            );
            } else
            {
            arrow.toggle
            (
                function()
                {
                    this.src = options.upImgSrc;
                    downUpBlock.show();
                    jQuery.cookie('du' + id, '1', {path: '/'});
                },
                function()
                {
                    this.src = options.downImgSrc;
                    downUpBlock.hide();
                    jQuery.cookie('du' + id, null, {path: '/'});
                }
            );
            }
        }
    );
};

function allIni()
{
    jQuery('#leftBl > div.block > div.item img.arrow')
        .downUp({arrowIdPrefix: 'a1', downUpBlockIdPrefix: 'b1', downImgSrc: 'images/menu-item-arrow.png', upImgSrc: 'images/menu-item-arrow-up.png'});
};

jQuery(document).ready(allIni);
