window.addEvent('domready', function() {
    var modules = ['module','moduletable', 'module-menu', 'module-hilite1', 'moduletable-hilite1', 'module-hilite2', 'moduletable-hilite2', 'module-hilite3', 'moduletable-hilite3', 'module-hilite4', 'moduletable-hilite4', 'module-hilite5', 'moduletable-hilite5', 'module-hilite6', 'moduletable-hilite6', 'module-hilite7', 'moduletable-hilite7', 'module-hilite8', 'moduletable-hilite8', 'module-hilite9', 'moduletable-hilite9', 'module-clean', 'moduletable-clean', 'submenu-block', 'moduletable_menu'];
    var header = "h3";
    RokBuildSpans(modules, header);
});

/**
 *  @author Olmo Maldonado, <http://olmo-maldonado.com
 *  
 *  Fixed resize issue - Djamil Legato <djamil [at] djamil.it>
 *  version 1.9
 */
var RokSlide = new Class({
    version: '1.9',
    options: {
        active: '',
        fx: {
            wait: false,
            duration: 350
        },
        scrollFX: {
            wait: false,
            transition: Fx.Transitions.Sine.easeInOut    
        },
        
        dimensions: {
            width: 722,
            height: 200
        },
        
        dynamic: false,
        tabsPosition: 'top',
        arrows: true
    },
    
    initialize: function(contents, options) {
        this.setOptions(options);
        this.content = $(contents);
        this.sections = this.content.getElements('.tab-pane');
        if(!this.sections.length) return;
    
        this.filmstrip = new Element('div').injectAfter(this.content);
        this.buildToolbar();
        this.buildFrame();
        if(window.ie) this.fixIE();
        
        this.scroller = $('scroller');
        this.startposition = $(this.sections[0].id.replace('-tab', '-pane')).getPosition().x;
        //this.scroller.fx = this.scroller.effects(this.options.fx);
        this.scroller.scrollFX = new Fx.Scroll(this.scroller, this.options.scrollFX);
        if(this.options.active) this.scrollSection(this.options.active.test(/-tab|-pane/) ? this.options.active : this.options.active + '-tab');
        else this.scrollSection(this.sectionptr[0]);

        if (this.options.tabsPosition == 'bottom') {
            this.filmstrip.getElement('hr').inject(this.filmstrip);
            var ul = this.filmstrip.getElement('ul'); ul.inject(this.filmstrip);
            var tab_height = ul.getSize().size.y, frame = $('frame');
            frame.setStyle('height', frame.getStyle('height').toInt() - tab_height);
        }
    },
    
    buildToolbar: function() {    
        var lis = [];
        var that = this;
        this.sectionptr = [];
        var h1, title;

        if (!!this.options.dynamic) this.width = $(this.options.dynamic).getCoordinates().width;
        else this.width = this.options.dimensions.width;
        var width = this.width;
        
        this.sections.each(function(el) {
            el.setStyles({
                width: width - ((!!this.options.dynamic) ? 0 : (!this.options.arrows) ? 0 : 142),
                height: this.options.dimensions.height
            });
            this.sectionptr.push(el.id.replace('-pane', '-tab'));
            h1 = el.getElement('.tab-title');
            title = h1.innerHTML;
            h1.empty().remove();
            lis.push(new Element('li', {
                id: el.id.replace('-pane', '-tab'),
                events: {
                    'click': function() {
                        this.addClass('active');    
                        
                        that.scrollSection(this);
                    },
                    'mouseover': function() {
                        this.addClass('hover');
                        this.addClass('active');
                    },
                    'mouseout': function() {
                        this.removeClass('hover');
                        this.removeClass('active');
                    }
                }
            }).setHTML(title));
        }, this);
        
        var length = lis.length - 1;
        lis[0].addClass('first');
        lis[length].addClass('last');
        
        this.filmstrip.adopt(new Element('ul', {
                    id: 'rokslide-toolbar',
                    styles: {
                        width: width
                    }
                }).adopt(lis), new Element('hr'));
    },
    
    buildFrame: function() {
        var width = this.width;
        
        var that = this, events = {
            'click': function() {
                that.scrollArrow(this)
            },
            'mouseover': function() {
                this.addClass('hover');
            },
            'mouseout': function() {
                this.removeClass('hover');
            }
        };
        
        var arrows = {
            'left': (this.options.arrows) ? new Element('div', {'class': 'button','id': 'left','events': events}) : '',
            'right': (this.options.arrows) ? new Element('div', {'class': 'button','id': 'right','events': events}) : ''
        };
        
        this.filmstrip.adopt(
            new Element('div', {
                id: 'frame', 
                styles: {
                    width: width,
                    height: this.options.dimensions.height
                }
            }).adopt(
                arrows.left,
                new Element('div', { 
                    id: 'scroller',
                    styles: {
                        width:     width - ((!!this.options.dynamic) ? 0 : (!this.options.arrows) ? 0 : 102),
                        height: this.options.dimensions.height
                    }
                }).adopt(this.content.setStyle('width', this.sections.length * 1600)),
                arrows.right
            )
        );    
    },
    
    fixIE: function() {
        // if(window.ie6) {
        //     this.sections.each(function(el) {
        //         el.setStyle('margin', '0px 10px');
        //     });
        // }
        
        this.filmstrip.getElement('hr').setStyle('display', 'none');
        
        // [$('frame'), this.scroller].merge(this.sections).merge($$('#frame div.button')).each(function(el) {
        //     if(el) el.setStyle('height', '75.5em');
        // });
    },
    
    scrollSection: function(element) {
        element = $($(element || this.sections[0]).id.replace('-pane', '-tab'));
        this.startposition = $(this.sections[0].id.replace('-tab', '-pane')).getPosition().x;
        
        var oldactive = element.getParent().getElement('.current');
        if(oldactive) oldactive.removeClass('current');
        element.addClass('current');
    
        var offset = $(element.id.replace('-tab', '-pane')).getPosition().x - this.startposition;
        this.scroller.scrollFX.scrollTo(offset, false);
        /*var that = this;
        this.scroller.fx.start({
            opacity: 0    
        }).chain(function() {
            that.scroller.fx.start({
                opacity: 1
            });
        });*/
    },
    
    scrollArrow: function(element) {
        var direction = Math.pow(-1, ['left','right'].indexOf(element.id) + 1);
        var current = this.sectionptr.indexOf(this.filmstrip.getElement('.current').id);
        var to = current + direction;
        this.scrollSection(this.sectionptr[to < 0 ? this.sectionptr.length - 1 : to % this.sectionptr.length]);
    }
});
RokSlide.implement(new Options);

/**
 * rokSifr - A multicolor-sifr helper that let the first word be colored.
 * 
 * @version        1.5
 * 
 * @license        MIT-style license
 * @author        Djamil Legato <djamil [at] djamil.it>
 * @client        Andy Miller @ Rockettheme
 * @copyright    Author
 */
 eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2 9=m P({5:{\'k\':\'16\',\'8\':\'O/N.K\',\'4\':\'#D\',\'o\':\'#14\',\'n\':{}},T:3(a){6.M(a);l 6},q:3(){2 a=6;2 b=$p({F:a.5.k,C:a.5.8,A:a.5.4,z:a.5.o},6.5.n);x.13(11(b));l 6}});9.Z(m X);2 Q=3(d,e,f,g){(d.t).s(3(i){2 a="."+d[i]+" "+e;L(!$E(a))l;r(d,e,g);2 b=$p({\'k\':a,\'8\':f,\'4\':$E(a).7(\'4\'),\'o\':$E(a+\' h\').7(\'4\'),\'n\':{J:"",I:$E(a).7(\'H\'),G:c||""}},g);2 c=$$(a+\' a\').7(\'4\');R=m 9(b).q()})};2 r=3(e,f,g){(e.t).s(3(i){2 d="."+e[i]+" "+f;$$(d).S(3(a){a.B(\'U\',\'V\');2 b=a.W(),j=b.y(" ");u=j[0],w=j.12(1).10(" "),v=a.Y;2 c="<h>"+u+"</h> "+w;a.15(v.17(b,c,"g"))})})};',62,70,'||var|function|color|options|this|getStyle|movie|RokSifr||||||||span||temp|selector|return|new|sifr|firstword|merge|build|RokBuildSpans|times|length|first|html|rest|sIFR|split|sSpanColor|sColor|setStyle|sFlashSrc|444444||sSelector|sHoverColor|backgroundColor|sBgColor|sLinkColor|swf|if|setOptions|gsl|js|Class|RokStart|rok|each|initialize|visibility|visible|getText|Options|innerHTML|implement|join|named|slice|replaceElement|FF9900|setHTML|h3|replace'.split('|'),0,{}))
 
