$(function() {
    $('#menu_main ul.firstUl').mouseover(function() {
        $(this).children('li').removeAttr('id');
        $(this).children('li').children('ul').css('display', 'block');
    })
    .mouseout(function() {
        var id = $(this).attr('id');
        $(this).children('li').attr('id', 'act_menu');
        setTimeout(function(){
            if ($('#'+id).children('li').attr('id') == 'act_menu') {
                $('#'+id).children('li').children('ul').css('display', 'none');
                $('#'+id).children('li').removeAttr('id');
            }
        }, 200);
    });
    
    $('div.firstDiv').each(function() {
        marginTop = Math.round((50-$(this).children('div').height())/2);
        $(this).children('div').css('padding-top', marginTop);
    });
    
    $('#timeFrom').datepicker({showOn: 'button', buttonImage: '/img/calendar.gif', buttonImageOnly: true});
    $('#timeTo').datepicker({showOn: 'button', buttonImage: '/img/calendar.gif', buttonImageOnly: true});
    $('#timeFrom').datepicker('option', {dateFormat: 'dd.mm.yy'});
    $('#timeTo').datepicker('option', {dateFormat: 'dd.mm.yy'});
    $('#timeFrom').datepicker($.datepicker.regional['ru']);
    $('#timeTo').datepicker($.datepicker.regional['ru']);
    
    $('select#country').change(function() {
        if ($(this).val() != 0) {
            $.post('/select_hotels.php', {id:$(this).val()}, function(options) {
                $('select#hotel').html(options);
                $('select#hotel').removeAttr('disabled');
            });
        }
        else {
            $('select#hotel').html('<option value="0">---</option>');
            $('select#hotel').attr('disabled', 'disabled');
        }
        $('select#categ').removeAttr('disabled');
    });
    
    $('select#hotel').change(function() {
        if ($(this).val() == 0) {
            $('select#categ').removeAttr('disabled');
        }
        else {
            $('select#categ').attr('disabled', 'disabled');
        }
    });
    
    $("a[rel='gallery']").colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
    
});
