/**
 * Index page PCO-13 site script
 * http://bright-side.ru/
 *
 * Copyright 2011 Andrew Abramov (http://forgiving.ru/)
 *
 * Date: Thu June 23 22:02 2011 +0400
 */

$(function() {
    var generalInfoPage = $('#general-info');
    var wallpaper = $('#wallpaper');

    $('html').whenContentReady().done(function() {
        wallpaper.height($('#layout').height());
        $(window).resize(function() {
            wallpaper.height($('#layout').height());
        });
        if(!$.browser.msie) {
            var header = $('div#layout > header');
            var footer = $('body > footer');
            var menu = $('nav#menu');
            var info = $('div#info');
            var minHeight = generalInfoPage.height() + 46;

            var h = header.height() + parseInt(header.css('padding-top').replace('px', ''))
                + parseInt(header.css('padding-bottom').replace('px', ''))
                + parseInt(header.css('margin-top').replace('px', ''))
                + parseInt(header.css('margin-bottom').replace('px', ''))

                + footer.height() + parseInt(footer.css('padding-top').replace('px', ''))
                + parseInt(footer.css('padding-bottom').replace('px', ''))
                + parseInt(footer.css('margin-top').replace('px', ''))
                + parseInt(footer.css('margin-bottom').replace('px', ''))

                + menu.height() + parseInt(menu.css('padding-top').replace('px', ''))
                + parseInt(menu.css('padding-bottom').replace('px', ''))
                + parseInt(menu.css('margin-top').replace('px', ''))
                + parseInt(menu.css('margin-bottom').replace('px', ''))

                + parseInt(info.css('margin-top').replace('px', ''))
                + parseInt(info.css('margin-bottom').replace('px', ''))
                + 2;

            var currentHeight = $(window).height() - h;
            info.height(minHeight > currentHeight ? minHeight : currentHeight);
            generalInfoPage.css({marginTop: (info.height() - generalInfoPage.height()) / 2 });
            $(window).resize(function() {
                var currentHeight = $(window).height() - h;
                info.height(minHeight > currentHeight ? minHeight : currentHeight);
                generalInfoPage.css({marginTop: (info.height() - generalInfoPage.height()) / 2 });
            });
        }
    });

    //Clients
    var clients = $('section#clients');
    $('div.wrap', clients).jCarouselLite({
        btnNext: "section#clients span.next",
        btnPrev: "section#clients span.prev",
        mouseWheel: true,
        scroll: 3,
        speed: 1000,
        visible: 3,
        easing: 'easeInOutQuad'
    });

    $('#gallery a').each(function() {
        var current = $(this);
        current.attr('href', current.attr('href').replace('?image', '#wallpaper'));
    });
});
