// GLOBAL VARIABLES & OBJECTS

    if(document.id('home')){
    // Instantiate class if user is on the homepage

        /* NEWS CAROUSEL */
        /* REF: http://mootools.net/forge/p/tab */
        (function(){
            var news_selected_index;
            var news_tab = new Tab.Extra({
                    container: 'homepage-news-carousel',
                    selector: 'li', 
                    tabs: 'ul.homepage-featured-news-buttons li a',
                    activeClass: 'selected',
                    animation: 'Move',
                    interval: 5, 
                    params: {
                        circular: true,
                        useOpacity: false,
                        opacity: 0.7
                    },
                    fx: {
                        link: 'ignore',
                        duration: 300
                    },
                    onCreate: function(newPanel, index){
                        // When tabs had been created/initiated load the remainder images....
                        $$('#homepage-news-carousel li').each(function (el,index) {
                            if(index!=0){
                                var strContainer = el.getElement('a.target-zone span.hidden');
                                var img_obj = strContainer.get('text');
                                var image = Asset.image(img_obj.src, {
                                    width: img_obj.width,
                                    height: img_obj.height,
                                    alt: img_obj.alt,
                                    onLoad: function(image){
                                        image.replaces(strContainer);
                                    }
                                });
                            }                           
                        });

                    },
                    onChange: function(a,b,c,d){
                        news_selected_index = c;
                    }
                });
                
            $$('ul.homepage-featured-news-buttons li a').each(function (el) {
                el.addEvent('mouseenter', function () { 
                    news_tab.stop(); 
                });
                
                el.addEvent('mouseleave', function () { 
                    news_tab.start.delay(2 * 150); 
                });
            }); 
        })();
        /* END - NEWS CAROUSEL */
                
        /* NEWS TICKER */
        (function(){
            var news_ticker = new Tab.Extra({
                    container: 'homepage-news-ticker',
                    selector: 'li', 
                    animation: 'Move',
                    interval: 2.5, 
                    params: {
                        circular: true,
                        mode: 'vertical'
                    },
                    fx: {
                        link: 'ignore',
                        duration: 1000
                    },
                    onChange: function(newPanel, curPanel, index, current){
                        if(!(Browser.Platform.ios || Browser.Platform.android || Browser.Platform.webos)){
                            curPanel.fade('out');
                            newPanel.fade('in');
                        }
                    }
                });
                
            $$('ul#homepage-news-ticker li').each(function (el) {
                el.addEvent('mouseenter', function () { 
                    news_ticker.stop(); 
                });
                
                el.addEvent('mouseleave', function () { 
                    news_ticker.start(); 
                });
            });
                
            document.id('more-news-next').addEvents({
                'click': function (e) {
                    e.preventDefault();
                    news_ticker.next(); 
                },
                'mouseenter': function (e) {
                    news_ticker.stop(); 
                },
                'mouseleave': function (e) {
                    news_ticker.start();
                }
            });
            
            document.id('more-news-previous').addEvents({
                'click': function (e) {
                    e.preventDefault();
                    news_ticker.previous(); 
                },
                'mouseenter': function (e) {
                    news_ticker.stop(); 
                },
                'mouseleave': function (e) {
                    news_ticker.start();
                }
            });
                        
        })();
        /* END - NEWS TICKER */
/****************************************************
        * MEMBER ASSOCIATIONS NEWS TICKER
        * REF: http://mootools.net/forge/p/tab
        ****************************************************/
            (function(){
                // Instantiate class if homepage has more than or equals to 3 news articles.
                
                var state_posts = $$('ul.states-posts');
                
                if(state_posts.length > 0){
                        var state_container = state_posts[0];

                        var state_selected_index;
                        $$('ul.states-switch li').each(function (el,i) {
                            if(el.hasClass('selected')) {state_selected_index = i;}
                        });
                        
                        
                        var states_tab = new Tab.Extra({
                                container: state_container,
                                selector: 'li', 
                                tabs: 'ul.states-switch li',
                                activeClass: 'selected',
                                interval: 5, 
                                /* animation: 'Move', */
                                params: {
                                    circular: true,
                                    mode: 'vertical'
                                },
                                fx: {
/*                                  transitions: 'Fx.Transitions.Elastic.easeOut', */
                                    /* transition:  'elastic:out', */
                                    link: 'ignore',
                                    duration: 600
                                },
                                onCreate: function(newPanel, index){
                                                                    
                                    $$('ul.states-posts li').each(function (el,i) {
                                        el.removeClass('hidden');
                                    });
            
                                },
                                onChange: function(newPanel, curPanel, index, current){
                                    /*
                                    if(!(Browser.Platform.ios || Browser.Platform.android || Browser.Platform.webos)){
                                        curPanel.fade('out');
                                        newPanel.fade('in');
                                    }
                                    */
                                    
                                }
                            }).stop();
                            

                            states_tab.setSelectedIndex(state_selected_index);
/*                           states_tab.stop();
*/
                            
/*
                        $$('ul.news-ticker-controls-container li').each(function (el) {
                            el.addEvent('mouseover', function () { 
                                news_tab.stop();
                            });
                            
                            el.addEvent('mouseout', function () { 
                                news_tab.start.delay(2 * 100); 
                            });
                        }); 
*/
                }
                
            })();
        /****************************************************
        * END - MEMBER ASSOCIATIONS NEWS TICKER
        ****************************************************/
        
    }


        
    /****************************************************
    * STATE NEWS TICKER
    * REF: http://mootools.net/forge/p/tab
    ****************************************************/
    (function(){
        // Instantiate class if homepage has more than or equals to 3 news articles.
        if($$('ul.news-ticker-controls-container li').length >=3){
                var news_selected_index;
                var news_tab = new Tab.Extra({
                        container: 'test',
                        selector: 'li', 
                        tabs: 'ul.news-ticker-controls-container li',
                        activeClass: 'selected',
                        animation: 'Move',
                        interval: 5, 
                        params: {
                            circular: true,
                            useOpacity: false,
                            opacity: 0.7
                        },
                        fx: {
                            link: 'ignore',
                            duration: 300
                        }
                    });
                    
                $$('ul.news-ticker-controls-container li').each(function (el) {
                    el.addEvent('mouseover', function () { 
                        news_tab.stop();
                    });
                    
                    el.addEvent('mouseout', function () { 
                        news_tab.start.delay(2 * 100); 
                    });
                }); 
            }
    })();
    /****************************************************
    * END - STATE NEWS TICKER
    ****************************************************/
        

