function layoutScrollFix() {
    var windowWidth = getPageSize().window.width;
    var isIE7 = ($.browser.msie && $('html').hasClass('ie7'));

    // hide star at right edge if window.width > page_paper.width; append to html as ie7 bugfix
    $(isIE7 ? 'html' : 'body').css({
        'overflow-x':   (windowWidth > $('.page_paper').width()) ? 'hidden' : 'scroll'
    });
    if (isIE7) {
        $('body').css({
            'overflow': 'hidden'
        })
    }
}

$.fn.createPano = function(uri) {
    $(this).click(function() {
        var pageSize = getPageSize();
        $('#page_spinner_max').css({
            width:  pageSize.page.width + 'px',
            height: pageSize.page.height + 'px'
        }).show().click(function () {
            $(this).hide();
        });

        var pageScroll = getPageScroll();
        new Panorama('page_spinner_max_inner', uri, 900);

        var inner = $('#page_spinner_max_inner');
        inner.css({
            left:   (pageScroll.xScroll + (pageSize.window.width - 900) / 2) + 'px',
            top:    (pageScroll.yScroll + (pageSize.window.height - 800) / 2) + 'px'
        });
    });
};

function globalPrepareDisplay() {
    // main page - no actions

    // photos
    $('a.link_photo_reports_page').movePage({
        new_page_url:   global_settings.url.photo_reports_page,
        horizontal:     'left',
        vertical:       'none',
        beforeSend:     layoutScrollFix
    });

    // news
    $('a.link_news_list').movePage({
        new_page_url:   global_settings.url.news_list_page,
        horizontal:     'right',
        vertical:       'none',
        beforeSend:     layoutScrollFix
    });

    // about page
    $('a.link_about_page').movePage({
        new_page_url:   global_settings.url.about_page,
        horizontal:     'left',
        vertical:       'top',
        beforeSend:     layoutScrollFix
    });

    // menu page
    $('a.link_menu_page').movePage({
        new_page_url:   global_settings.url.menu_page,
        horizontal:     'right',
        vertical:       'top',
        beforeSend:     layoutScrollFix
    });

    // vacancy page
    $('a.link_vacancy_page').movePage({
        new_page_url:   global_settings.url.vacancy_page,
        horizontal:     'right',
        vertical:       'bottom',
        beforeSend:     layoutScrollFix
    });

    // contacts page
    $('a.link_contacts_page').movePage({
        new_page_url:   global_settings.url.contacts_page,
        horizontal:     'none',
        vertical:       'top'
    });


    // photo reports links
    $('a.link_photo_report').each(function() {
        $(this).movePage({
            new_page_url:   $(this).attr('href'),
            horizontal:     'left',
            vertival:       'bottom',
            beforeSend:     layoutScrollFix
        });
    });


    // pano
    $('#show_pano1').createPano(global_settings.panorama_images.pano1);
    $('#show_pano2').createPano(global_settings.panorama_images.pano2);
    $('#show_pano3').createPano(global_settings.panorama_images.pano3);

    // news displaying (all => one)
    $('.this_week a.news_preview_link').click(function() {
        $('.this_week a.news_preview_link').removeClass('news_preview_selected');
        $(this).addClass('news_preview_selected');

        var fullNewsElement = $(this).parent().parent().next('.news_prepared_view');
        $('.announcement').html(fullNewsElement.html());
    }).filter(':first').click();

    /*
     Temporary no flaer
    // flaer
    $('#flaer_link').click(function () {
        $('#flaer_itself').toggle();
    });*/

    $(window).resize(layoutScrollFix);
    layoutScrollFix();
};

