window.addEvent('domready', function() { Home.Setup() });

var Home = {
    CurrentTestimonial: 0,
    Testimonials: null,
    Setup: function() {
        var y = new Tab($('tabs'));
        Home.Testimonials = $$('.testimonials div');
        if (Home.Testimonials.length > 0) {
            Home.Testimonials.set('opacity', '0').removeClass('hidden').set('tween', { duration: 2000 });
            Home.NextTestimonial();

        }
        Home.Logos = $$('.logoinner img');
        if (Home.Logos.length > 0) {
            $$('.logoinner').removeClass('hidden');
            $$('.logoinner').fade(1);
            $$('.logoinner').setStyle('width', Home.Logos.length * 120 * 2 + 'px').set('tween', { transition: Fx.Transitions.linear, duration: Home.Logos.length * 6000, onComplete: function(z) {
                $$('.logoinner').setStyle('left', 0);
                $$('.logoinner').tween('left', -Home.Logos.length * 120);
            }
            });
            var y = $$('.logoinner a').clone();
            y.inject($$('.logoinner')[0]);

            $$('.logoinner')[0].set('left', 0);
            $$('.logoinner')[0].tween('left', -Home.Logos.length * 120);

        }

        if ($('tabcover') != null) {
            $('tabcover').addEvent('click', function(y) {
                $('tabcover').fade(0);
                $('tabs').set('opacity', 0).removeClass('hidden').fade(1);
            });

        }

        if ($('juicy-video') != null) {
            var mySwiff = new Swiff('/mjo/video.swf', { container: 'juicy-video', width: 230, height: 160 });
        }

        $$('.testimoniallink').addEvent('click', function(y) {
            y.stop();
            TB_show('hello', '#TB_inline?width=500&height=400&inlineId=testimonial' + y.target.get('rel'));

            $('TB_ajaxContent').setStyle('height', ($$('#TB_ajaxContent .popuptestimonial')[0].getSize().y + 10) + "px");

        });
        $('mayor').addEvent('click', function(y) {
            y.stop();
            TB_show('hello', '#TB_inline?width=500&height=600&inlineId=mayorendorsement');

        });
    },
    NextTestimonial: function() {
        if (Home.CurrentTestimonial > 0)
            Home.Testimonials[Home.CurrentTestimonial - 1].fade(0);

        Home.CurrentTestimonial++;

        if (Home.CurrentTestimonial > Home.Testimonials.length)
            Home.CurrentTestimonial = 1;

        Home.Testimonials[Home.CurrentTestimonial - 1].fade(1);

        Home.NextTestimonial.delay(5000);

    }

}

var Tab = new Class({
    element: null,
    tabs: null,
    content: null,
    currentTab: 0,
    initialize: function(element) {
        this.element = element;
        this.tabs = element.getElements('ul.tabnav a');
        this.content = element.getElements('div.tabitem');
        var y = 0;
        this.tabs.each(function(z) {
            if (z.hasClass('active'))
                this.currentTab = y;
            y++;
        });

        this.tabs[this.currentTab].addClass('active');
        this.content[this.currentTab].addClass('active');

        this.tabs.addEvent('click', this.TabClick.bind(this));
    },
    TabClick: function(ev) {
        ev.stop();
        for (var y = 0; y < this.tabs.length; y++) {
            if (this.tabs[y] == ev.target) {
                this.tabs[y].addClass('active');
                this.content[y].addClass('active');
            }
            else {
                this.tabs[y].removeClass('active');
                this.content[y].removeClass('active');
            }
        }
    }
});