function moveDiv() {
    var winHeight = $(window).height();
    var divHeight = 525/*del*/;
    if (winHeight > divHeight) {
        var marginTop = (winHeight - divHeight) / 2;
        $('#wrapper').css('padding-top', marginTop);
    } else {
        $('#index').css('margin-top', 0);
    }
    //alert('test');


}

$(document).ready(function(){
    var textId = 0;

    //вперед, вправо
    $('#index-next').click(function(){
        var $nextText = $('#index-text-' + (textId + 1));
        if ($nextText.length) {
            textId++;
            $('#index-hide').animate({ left: "-=430px" }, 'slow');
        }
        //а дальше?
        $nextText = $('#index-text-' + (textId + 1));
        if (!$nextText.length) {
            $('#index-next').css('visibility', 'hidden');
        }
        $('#index-prev').css('visibility', 'visible');
    });

    //назад, влево
    $('#index-prev').click(function(){
        var $nextText = $('#index-text-' + (textId - 1));
        if ($nextText.length) {
            textId--;
            $('#index-hide').animate({ left: "+=430px" }, 'slow');
        }

        //а до этого?
        $nextText = $('#index-text-' + (textId - 1));
        if (!$nextText.length) {
            $('#index-prev').css('visibility', 'hidden');
        }
        $('#index-next').css('visibility', 'visible');
    });



    $(window).resize(function(){ moveDiv(); });
    moveDiv();

    //скрыть кнопку назад
    //$('#index-prev').css('visibility', 'hidden');
});

var im = [];


$(document).ready(function(){
    $('#index-text a').each(function(){
        if ($(this).find('img').length) {
            $(this).attr('onclick', '');
            $(this).click(function(){
                window.myimg = new Image;
                window.myimg.src = $(this).attr('href');
                $(window.myimg).load(function(){
                    var w = window.myimg.width;
                    var h = window.myimg.height;
                    var left = ($(window).width() - w) / 2;
                    var top = ($(window).height() - h) / 2;
                    if (top < 0) top = 0;
                    if (left < 0) left = 0;
                    $.blockUI({
                        css: {
                            top:  top  + 'px',
                            left: left + 'px',
                            border: 0,
                            position: 'absolute',
                            background: 'transparent',
                            width: w + 'px',
                            height: h + 'px'
                        },
                        overlayCSS: {
                            opacity: .23
                        },
                        message: $('<div><img title="Закрыть" alt="" src="" onclick="$.unblockUI();" style="cursor: pointer;" /></div>').find('img').attr('src', window.myimg.src),
                        showOverlay: true
                    });
                });
                return false;
            });
        }
    });

    $(document).keydown(function(e){
        if (27 == e.which) {
            $.unblockUI();
        }
    });

});
