﻿var leftmove = '+=50';
var opacity_val = 100;
var width_val = 120;
var height_val = 190;
var top_val = '+=1';



$(document).ready(function () {
    $('#scroller-container').hide();
    $('#book-detail').hide();
    $('#featured-books').hide();
    $('#book-summary1').hide();
    $('#book-summary2').hide();
    $('#book-summary3').hide();
    $('#book-summary4').show();

    $('#featured-books').fadeIn(1500);
    $('#scroller-container').fadeIn(1500);
    $('#book-detail').fadeIn(1500);

    $('#next_button').click(function () {
        $('#book-summary1').fadeOut(300);
        $('#book-summary2').fadeOut(300);
        $('#book-summary3').fadeOut(300);
        $('#book-summary4').fadeOut(300);
        $('#next_button').fadeOut(300);
        scrollBook("1");
        scrollBook("2");
        scrollBook("3");
        scrollBook("4");
        $('#next_button').fadeIn(300);
    });
});

function scrollBook(bookNum) {
    var zindexval_book1;

    zindexval_book1 = setAnimateVars($('#book' + bookNum).height());
    $('#book' + bookNum).animate({
        opacity: opacity_val,
        left: leftmove,
        width: width_val,
        height: height_val,
        top: top_val
    }, 800,
            function () {
                // Animation complete.
                if ($(this).height() == 150) {
                    $(this).css('z-index', '0');
                    $(this).css('opacity', '1');
                }
                else {
                    $(this).css('z-index', zindexval_book1);
                }
                if ($(this).height() == 250) {
                    $('#book-summary' + bookNum).fadeIn(400);
                }
            });
}

function setAnimateVars(currHeight, zindexval) {
    if (currHeight == 150) { // first position
        leftmove = '+=35';
        opacity_val = 100;
        width_val = 120;
        height_val = 190;
        top_val = '-=20';
        zindexval = '100';
    }
    else if (currHeight == 190) { // second position
        leftmove = '+=45';
        opacity_val = 100;
        width_val = 120;
        height_val = 210;
        top_val = '-=10';
        zindexval = '150';
    }
    else if (currHeight == 210) { // third position
        leftmove = '+=70';
        opacity_val = 100;
        width_val = 163;
        height_val = 250;
        top_val = '-=25';
        zindexval = '200';
    }
    else if (currHeight == 250) { // fourth position
        leftmove = '-=150';
        opacity_val = 0;
        width_val = 100;
        height_val = 150;
        top_val = '+=55';
        zindexval = '1';
    }
    return zindexval;
}
