var ZebraTable = new Class({

    Implements: [Options,Events],
    
    options: {
        elements: '#content table',
        cssEven: 'row-on',
        cssOdd: 'row-off',
        cssHighlight: 'row-hi',
        cssMouseEnter: 'row-hover'
    },
    
    initialize: function(options) {
        this.setOptions(options);
        $$(this.options.elements).each(function(table) {
            this.zebraize(table);
        }, this);
    },
    
    zebraize: function(table) {
        table.getElements('tr').each(function(tr, i) {
            if (tr.getFirst().get('tag') != 'th') {
                var options = this.options, klass = i % 2 ? options.cssEven : options.cssOdd;
                tr.addClass(klass);
            }
        }, this);
    }
});

var AraratForm = new Class({
    initialize: function() {
        $$('.zend_form dl dd').each(function(el) {
            new Element('div').setStyles({
                'clear': 'both',
                'height': '1px'
            }).inject(el, 'after');
        });
        $$('form select[class^=conditional-]').each(function(el) {
            el.conditional = new Hash();
            var conditionals = el.getProperty('class').split(' ');
            for (var loop = 0; loop < conditionals.length; loop++) {
                var value = conditionals[loop].split('-');
                var prefix = value.shift();
                if (prefix == 'conditional' && value.length >= 2) {
                    var id      = el.getProperty('id');
                    var cnd     = $(id);
                    var val     = value.shift();
                    var name    = value.join('-');
                    var tgt     = $(name);
                    if (tgt) {
                        tgt.fx = new Fx.Slide(tgt, {
                            link: 'chain'
                        });
                        if (tgt.hasClass('closed')) {
                            tgt.removeClass('closed');
                            tgt.fx.hide();
                        }
                        tgt.toggle = this.toggle;
                        if (!cnd.conditional[val]) {
                            el.conditional[val] = new Array();
                        }
                        el.conditional[val][el.conditional[val].length] = tgt;
                    }
                }
            }
            el.toggle = this.toggle;
            el.addEvent('change', el.toggle);
            el.fireEvent('change');
        }.bind(this));
    },
    
    toggle: function() {
        var value = this.get('value');
        this.conditional.each(function(val, key) {
            for (var loop = 0; loop < val.length; loop++) {
                if (value == key) {
                    val[loop].fx.slideIn();
                } else {
                    val[loop].fx.slideOut();
                }
            }
        });
    }
});

window.addEvent('domready', function() {
    $$('a.external').each(function(link) {
        link.target = '_blank';
    });
    var zebraTables = new ZebraTable();
    var araratForms = new AraratForm();
    new Element('a').set('href', '#').inject(new Element('li').addClass('last').setStyle('cursor', 'pointer').set('text', 'Print').addEvent('click', function() { window.print() }).inject($('toolbar').getElement('ul')));
    Cufon.refresh();
});

Cufon.replace('h1')('h2')('h3')('.introduction')('.list-link')('.list-publication')('dt label')('#tabs .tab')('#microsite')('#toolbar')('#footer');
Cufon.replace('h1.slideshow-title', {
    textShadow: '#333 1px 1px'
});

