var tOut = null;
var changed = '#d8f7a1';

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

function submenu_toggle (id) {
	var id;
	$('div[@id^=sub_]').not('#' + id).hide();
	$('#' + id).toggle();
	$('#menu a').blur();
}

function make_mail_link (user, host) {
	var user, host;
	return '<a href="mailto:' + user + '@' + host + '">' + user + '@' + host + '</a>';
}

function make_mail_links () {
	$('.mailink').each( function () {
		var obj = $(this).text().split(',');
		if (!obj[0] && !obj[1]) return;
		$(this).html( make_mail_link(obj[0], obj[1]) ).show();
	});
}

function default_phone (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 () {

    make_mail_links();

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

    // for Safari
    if($.browser.safari || $.browser.chrome) { $( function() {
        $('#main-menu .enter').css('width', '395px');
        $('td.content-left-column').css('width', '285px');
    });}

	//$('#main-menu').dropdownmenu();

	//if (location.pathname.indexOf('admin') == -1) $(function() { $('.gallery a').lightBox(); });

    $('#review-add').click( function () {
        $('#review-form').show();
        $(this).hide();
    });
    $('#review-close').click( function () {
        $('#review-form').hide();
        $('#review-add').show();
        $('input[@name=name], input[@name=email], textarea[@name=body]').val('');
    });

    $('div.cutting a').click( function () {
        $(this).parents('.cutting').children().toggle();
    });

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

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

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

});
