var timer;

function show_block(id)
{
    if(timer) {
        clearTimeout(timer);
        timer = null;
    }
    $('#domdiv').show();
    result(id)
}

function hide_block()
{
    timer=setTimeout(real_hide_block, 200);
}

function real_hide_block()
{
    if(timer) {
        clearTimeout(timer);
        timer = null;
    }
    timer = null;
     $('#domdiv').html('');
}

function result(id) {
    $('#domdiv').html($('#dom'+id).html());
}

function loadd(){
    var cText = {
        months: ["ЯНВАРЯ", "ФЕВРАЛЯ", "МАРТА", "АПРЕЛЯ", "МАЯ", "ИЮНЯ", "ИЮЛЯ", "АВГУСТА", "СЕНТЯБРЯ", "ОКТЯБРЯ", "НОЯБРЯ", "ДЕКАБРЯ"]
    };
    function formatDate() {
        var today = new Date();
        return today.getDate() + " " + cText.months[today.getMonth()];
    }

    var ele = document.getElementById("userdate");
    ele.innerHTML = formatDate();
}

var groups = {};

$(function() {
    var params = {
        showURL: false,
        track: true,
        opacity: 0.8
    };
    $('#lightBox a').tooltip(params);
    $('#box a').tooltip(params);
    $('.element a.tooltip').tooltip(params);
    params.bodyHandler = function() {
        return $(this).children('img').attr("alt");
    }
    $('.foto-object').tooltip(params);

    $('label.label_check').each(function(index, item) {
        var item = $(item);
        var input = item.children('input');

        if(input.attr('type') == 'radio') {
            if(!groups[item.attr('name')]) {
                groups[item.attr('name')] = new Array();
            }
            groups[item.attr('name')].push(item);
        }
        item.bind('click', {
            type: input.attr('type')
        }, triggerCheck);
    });
    $('#tooltip').hide();
});

function triggerCheck(event) {
    var item = $(this);
    var data = event.data;
    var input = item.children('input');

    if(input.is(':checked')) {
      //  if(data.type != 'radio') {
            item.removeClass('c_on');
            item.addClass('c_off');
            input.attr('checked', false);
   //     }
    } else {
        if(data.type == 'radio') {
            $(groups[item.attr('name')]).each(function(index, groupItem) {
                groupItem = $(groupItem);
                if(groupItem != item) {
                    groupItem.removeClass('c_on');
                    groupItem.addClass('c_off');
                }
            });
        }
        item.removeClass('c_off');
        item.addClass('c_on');
        input.attr('checked', true);
    }
    event.preventDefault();
}
