function getBrowserInfo()
{
    var t, v = undefined;
    if (window.opera)
        t = 'Opera';
    else if (document.all)
    {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE')+5;
        v = nv.substring(s,s+1);
    }
    else if (navigator.appName)
        t = 'Netscape';
    
    return {type:t, version:v};
}

 
function bookmark(a)
{
    var url = window.document.location;
    var title = window.document.title;
    var b = getBrowserInfo();
    if (b.type == 'IE' && 7 > b.version && b.version >= 4)
        window.external.AddFavorite(url, title);
    else if (b.type == 'Opera')
    {
        a.href = url;
        a.rel = "sidebar";
        a.title = url+','+title;
        return true;
    }
    else if (b.type == "Netscape")
        window.sidebar.addPanel(title,url,"");
    else
        alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    
    return false;
}


function showOffice(id)
{
    $('#offices_list li').each(function(index, el)
    {
        var cur_id = $(el).attr('id').substr(6, $(el).attr('id').length);
        if (id == 'office'+cur_id)
        {
            $('#office_block' + cur_id).css('display', 'block');
            $('#office' + cur_id).addClass('active');
            
            var prev_office = parseInt(cur_id)-1;
            var next_office = parseInt(cur_id)+1;
            
            // стрелка "предыдущий офис"
            if (typeof(offices['office' + prev_office ]) != 'undefined')
            {
                $('#office_prev').addClass('active');
                $('#office_prev').bind('click', function() 
                {
                    showOffice('office' + prev_office);
                    return false;
                });
            }
            else 
            {
                $('#office_prev').removeClass('active');
                $('#office_prev').click(function() { return false; });
            }
            
            
            // стрелка "следующий офис"
            if (typeof(offices['office' + next_office ]) != 'undefined')
            {
                $('#office_next').addClass('active');
                $('#office_next').bind('click', function()
                {
                    showOffice('office' + next_office);
                    return false;
                });
            }
            else 
            {
                $('#office_next').removeClass('active');
                $('#office_next').click(function() { return false; });
            }
         }
        else
        {
            $('#office_block' + cur_id).css('display', 'none');
            $('#office' + cur_id).removeClass('active');
        }
    });
}
