var tOut;
var changed = '#d8f7a1';
var mouseY = 0;
var globalMathRandom = Math.round(Math.random() * 10000);

function hider () {
    $('#alert').empty().hide();
    clearTimeout(tOut);
}

function cash_toggle (mode) {
    var mode;
    if (location.href.indexOf('cash') == -1) return;
    $('#cards').hide();
    $('#novoplat').hide();
    if (mode == 2) $('#cards').show();
    if (mode == 1) $('#novoplat').show();
}

function default_search (field, searchDef) {
	var field, searchDef;
    var curVal = $.trim( $('#' + field).val() );
    if (curVal == '' || curVal == searchDef) $('#' + field).val(searchDef).css('color', '#cccccc').css('font-weight', 'bold');
}

$(document).ready( function () {

    tOut = window.setTimeout('hider()', 8000);

    default_search('phone', 'XXXXXXXXXX');
    $('#phone').focus( function () {
        $(this).css('color', '#000000').css('font-weight', 'normal');
        if ($(this).val() == 'XXXXXXXXXX') $(this).val('');
    });
    $('#phone').blur( function () {
        default_search('phone', 'XXXXXXXXXX');
    });

    if (location.href.indexOf('cash') != -1) $('#cards').hide();

    $('.t_1, .t_2').hover( function () {
        changed = $(this).css('background-color');
        $(this).css('background-color', '#d8f7a1');
    }, function () {
        $(this).css('background-color', changed);
    });

    $('.showtip').hover( function () {
        var num = $(this).attr('id').substr(7);
        var offset = $(this).offset();
        var region = parseInt($(document).height() / 2);
        var direction = (mouseY && mouseY < region) ? 1 : -1;
        var height = $(this).height();
        if (direction == -1) height += $('#tip' + num).height();
        $('#tip' + num).show().css('top', (offset.top + direction * height) + 'px').css('left', offset.left + 'px');
    }, function () {
        $('.tooltip').hide();
    });

    $('form.mail').submit( function () {
        $('input.button').parent().html('<div class="bold red">Отправка сообщения...</div>');
        return true;
    });

}).mouseover( function (e) { mouseY = (e.pageY) ? e.pageY : e.clientY; });
