$(function(){
    $('html, body').bind('mousewheel', function(event, delta){

        $('html,body').stop();

    });
    $("#portfolio a,.fancybox").fancybox({
        'titleShow': false,
        'transitionIn': 'fade',
        'transitionOut': 'fade',
        'speedIn': 500
    });
    $('#input_background input').one("click", function(){
        $(this).val('');
    });
    $('#tel_button').click(function(){
        $('#input_background input').one("click", function(){
            $(this).val('');
        });
    });
    var height = $('#header').height();
    var margin = height;
    $('#header_screen').height(height);
    $('#header_screen').css({
        marginTop: -height
    });
    if (jQuery.browser.opera && parseFloat(jQuery.browser.version, 10) < 9.64) {
        height = 373;
        margin = 440;
    }
    var timeout = 600;
    $('#sale').click(function(){
        $('#header_screen_container').height(height);
        $('#header_screen').animate({
            marginTop: 0
        }, {
            easing: 'linear',
            duration: timeout,
            queue: true,
            step: function(){
                $('#header_screen_container').height(height);
            }
        });
        return false;
    });
    $('#header_screen').mouseleave(function(){
        $('#header_screen').animate({
            marginTop: -margin
        }, 1000, function(){
            $('#header_screen_container').css({
                height: 'auto'
            });
        });
    });
    $('.screen_close').click(function(){
        $('#header_screen').animate({
            marginTop: -margin
        }, 1000, function(){
            $('#header_screen_container').css({
                height: 'auto'
            });
        });
        return false;
    });
    $('#contacts_href').click(function(){
        if ($('#contacts_picture').is(':hidden')) {
            $('#contacts_href2').html('Скрыть схему проезда');
        }
        $('#contacts_picture').css({
            'display': 'block'
        });
        var target = $('#footer');
        if (target.length) {
            var top = target.offset().top;
            $('html,body').animate({
                scrollTop: top
            }, {
                duration: 1000,
                quene: false
            });
            return false;
        }
    });
    if (!jQuery.browser.opera) {
        $('#footer_top_arrow').click(function(){
            $('#contacts_picture').slideUp(1000);
            var target = $('#top_phone');
            if (target.length) {
                var top = target.offset().top;
                $('html,body').animate({
                    scrollTop: top
                }, {
                    duration: 600,
                    quene: false
                });
                return false;
            }
        });
    }

    $('#contacts_href2').click(function(){
        if ($('#contacts_picture').is(':hidden')) {
            $(this).html('Скрыть схему проезда');
            $('#contacts_picture').css({
                'display': 'block'
            });
            scroll_to('#contacts_picture', '300');
        }
        else {
            $(this).html('Как проехать?');
            $('#contacts_picture').slideUp(1000);
        }
        return false;
    });
    $('.contacts_close').click(function(){
        $('#contacts_picture').slideToggle(1000);
        return false;
    });
});
function scroll_to(target, duration){
    target = $(target);
    if (target.length) {
        var top = target.offset().top;

        if (jQuery.browser.opera) {
            $('html').animate({
                scrollTop: top
            }, {
                duration: duration,
                quene: false
            });
        }
		else {
			$('html,body').animate({
                scrollTop: top
            }, {
                duration: duration,
                quene: false
            });
		}

        return false;
    }
}

