// Brochure functionality
// Copyrights 2009, Loco (Loohuis Consulting)

// application initialization
document.observe('dom:loaded', function() {new Brochure('brochure');});

var Brochure = Class.create({
    currentPage: 1,

    initialize: function(id)
    {
        if ($(id)) {
            this.pages = $$('.brochure');
            this.pages[this.currentPage-1].show();
            $$('.next').each(function(a) {a.observe('click', this.nextPage.bindAsEventListener(this))}, this);
            $$('.prev').each(function(a) {a.observe('click', this.prevPage.bindAsEventListener(this))}, this);
        }
    },

    // make next page appear
    nextPage: function(e)
    {
        Event.stop(e);
        if (this.currentPage < this.pages.length) {
            this.currentPage++;
            Effect.Appear(this.pages[this.currentPage-1].id, {duration: 0.3});
            // hide 'next' 
            if (this.currentPage == this.pages.length)
                $$('.next').each(function(a) {a.hide()});
            // show 'prev' 
            if (this.currentPage > 1)
                $$('.prev').each(function(a) {a.show()});
        }
    },

    // make current page disappear
    prevPage: function(e)
    {
        Event.stop(e);
        if (this.currentPage > 1) {
            Effect.Fade(this.pages[this.currentPage-1].id, {duration: 0.3});
            this.currentPage--;
            // show 'next' 
            if (this.currentPage < this.pages.length)
                $$('.next').each(function(a) {a.show()});
            // hide 'prev' 
            if (this.currentPage == 1)
                $$('.prev').each(function(a) {a.hide()});
        }
    }

});

