var pitc = {
    categories: ['wedding', 'family', 'children'],
    sections: ['home', 'about', 'contact'],
    currentCategory: 'wedding',
    currentSection: '',
    defaultSection: 'home',
    pageViewer: undefined,
    activeLinkColor: '#5f85ce;',
    inactiveLinkColor: '#3a527e;',

    init: function() {
        this.pageViewer = new MultiPageViewer ({
            container: 'myPageViewer',
            pages: {
                page_home_wedding: ['homeWedding'],
                page_home_family: ['homeFamily'],
                page_home_children: ['homeChildren'],
                page_about_wedding: ['aboutWedding'],
                page_about_family: ['aboutFamily'],
                page_about_children: ['aboutChildren'],
                page_contact_wedding: ['contactWedding'],
                page_contact_family: ['contactFamily'],
                page_contact_children: ['contactChildren']
            }
        });

        pitc.currentSection = pitc.defaultSection;
        if (location.hash) {
            var targetSection = location.hash;
            targetSection = targetSection.substr(1);
            if (targetSection) {
                pitc.currentSection = targetSection;
            }
        }

        this.initPreFetch();

        $('a_wedding').addEvent('mouseover', function() {
            pitc.setCategory('wedding');
            pitc.pageViewer.show('page_' + pitc.currentSection + '_' + pitc.currentCategory);
        });
        $('a_wedding').addEvent('click', function() {
            window.location = "/gallery/wedding.php";
        });
        $('a_family').addEvent('mouseover', function() {
            pitc.setCategory('family');
            pitc.pageViewer.show('page_' + pitc.currentSection + '_' + pitc.currentCategory);
        });
        $('a_family').addEvent('click', function() {
            window.location = "/gallery/family.php";
        });
        $('a_children').addEvent('mouseover', function() {
            pitc.setCategory('children');
            pitc.pageViewer.show('page_' + pitc.currentSection + '_' + pitc.currentCategory);
        });
        $('a_children').addEvent('click', function() {
            window.location = "/gallery/children.php";
        });

        $('a_home').addEvent('click', function() { 
            pitc.setSection('home');
            pitc.pageViewer.show('page_' + pitc.currentSection + '_' + pitc.currentCategory);
            if (pitc.smoothGallery) {
                pitc.smoothGallery.destroySlideShow(pitc.smoothGallery.galleryElement);
                pitc.smoothGallery = undefined;
            }
        });
        $('a_about').addEvent('click', function() { 
            pitc.setSection('about');
            pitc.pageViewer.show('page_' + pitc.currentSection + '_' + pitc.currentCategory);
            if (pitc.smoothGallery) {
                pitc.smoothGallery.destroySlideShow(pitc.smoothGallery.galleryElement);
                pitc.smoothGallery = undefined;
            }
        });
        $('a_contact').addEvent('click', function() { 
            pitc.setSection('contact');
            pitc.pageViewer.show('page_' + pitc.currentSection + '_' + pitc.currentCategory);
            if (pitc.smoothGallery) {
                pitc.smoothGallery.destroySlideShow(pitc.smoothGallery.galleryElement);
                pitc.smoothGallery = undefined;
            }
        });

        $('a_' + this.currentSection).fireEvent('click');
        $('myPageViewer').fade(1);
    },

    setCategory: function(newCategory) {
        if (this.currentCategory === newCategory) {
            return;
        }

        this.currentCategory = newCategory;
    },

    setSection: function(newSection) {
        if (this.currentSection === newSection) {
            return;
        }

        this.currentSection = newSection;
    },

    initPreFetch: function() {

        /* load the main image first and then start the rest */
        new Asset.image('images/main_wedding.jpg', {
            'id': 'imgWedding',
            'class': 'pageView',
            'alt': 'Amanda McAlpine Wedding Photography',
            'onload': function() { 
                this.setOpacity(0);
                this.injectInside('homeWedding');
                this.fade(1);

                new Asset.image('images/main_family.jpg', {
                    'id': 'imgFamily',
                    'class': 'pageView',
                    'alt': 'Amanda McAlpine Family Photography',
                    onload: function() { 
                        this.setOpacity(0);
                        this.injectInside('homeFamily');
                        this.fade(1);
                    }
                });
                new Asset.image('images/main_children.jpg', {
                    id: 'imgChildren',
                    'class': 'pageView',
                    'alt': 'Amanda McAlpine Child Photography',
                    onload: function() { 
                        this.setOpacity(0);
                        this.injectInside('homeChildren');
                        this.fade(1);
                    }
                });
            }
        });
    }
};

window.addEvent('domready', function(){
    pitc.init();
});

