﻿window.addEvent('domready',function(){hmcc.setup();});

var hmcc = {
    currentImage: -1,
    img: null,
    topPerson: 0,
    setup: function() {
        var el = $$('#nav a');

        el.set('morph', { duration: '100', transition: 'sine:in' });
        el.addEvent('mouseover', function(e) {
            e.target.morph({ 'background-position': '0 0' });
        });
        el.addEvent('mouseout', function(e) {
            if (!e.target.hasClass('selected'))
                e.target.morph({ 'background-position': '0 5px' });
        });

        hmcc.img = $$('#mainpics .img img');
        hmcc.img.set('tween', { duration: '1000', transition: 'sine:in' });
        hmcc.img.addEvent('click', function(e) {
            location.href = (e.target.getParent().getElements('h1 a')[0].getProperty('href'));

        }
                );
        hmcc.img.setOpacity(0);
        hmcc.img.setStyle('visibility', 'hidden');

        hmcc.cap = $$('#mainpics .imgcaption');
        hmcc.cap.set('tween', { duration: '1000', transition: 'sine:in' });
        hmcc.cap.setOpacity(0);
        hmcc.cap.setStyle('visibility', 'hidden');

        var nextImage = function() {
            if (this.currentImage >= 0) {
                this.img[this.currentImage].fade(0);
                this.cap[this.currentImage].fade(0);
            }
            this.currentImage++;
            if (this.currentImage >= this.img.length)
                this.currentImage = 0;

            this.img[this.currentImage].fade(1);
            this.cap[this.currentImage].fade(1);
        };
        if (hmcc.img.length > 0) {

            nextImage.apply(hmcc);
            if (hmcc.img.length > 1)
                nextImage.periodical(8000, hmcc);
        }

        if ($('people') != null) {
            var div = new Element('div', {
                'id': 'peoplenav'
            });
            div.inject($('people').getParent(), 'before');

            var el = new Element('img', {
                'src': 'images/smallnav_up.gif',
                'width': '12',
                'height': '10',
                'styles': {
                    'cursor': 'pointer'
                },
                'events': {
                    'click': function() {
                        hmcc.topPerson = hmcc.topPerson - 2;
                        if (hmcc.topPerson < 0)
                            hmcc.topPerson = 0;

                        var myFx = new Fx.Scroll('people').toElement($$('#people .person')[hmcc.topPerson]);
                    }
                }
            });

            el.inject(div);

            el = new Element('img', {
                'src': 'images/smallnav_down.gif',
                'width': '12',
                'height': '10',
                'styles': {
                    'cursor': 'pointer'
                },
                'events': {
                    'click': function() {
                        hmcc.topPerson = hmcc.topPerson + 2;

                        if (hmcc.topPerson >= $$('#people .person').length)
                            hmcc.topPerson = $$('#people .person').length - 2;


                        var myFx = new Fx.Scroll('people').toElement($$('#people .person')[hmcc.topPerson]);
                    }
                }
            });

            el.inject(div);
        }
    }
}