/* Featured posts 2slider - Create a dynamic featured posts 2slider tutorial
/* Tutorial - http://new2wp.com/rookie/part-2-the-static-version-of-the-jquery-featured-post-2slider
/* ----------------------------------------------------------------------------------------------- */

$slider2 = {
    context: false,
    tabs: false,
    timeout: 4000,      // time before next 2slide appears (in ms)
    slideSpeed: 1000,   // time it takes to 2slide in each 2slide (in ms)
    tabSpeed: 300,      // time it takes to 2slide in each 2slide (in ms) when rotating through tabs
    fx: 'scrollLeft',   // 2slide control: fade, scrollLeft, right etc.
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slider2');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides2-nav li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare 2slider and jQuery cycle tabs
        this.prepareslideshow2();
    },
    
    prepareslideshow2: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $('div.slides2 > ul', $slider2.context).cycle({
            fx: $slider2.fx,
            timeout: $slider2.timeout,
            speed: $slider2.slideSpeed,
            fastOnEvent: $slider2.tabSpeed,
            pager: $('ul.slides2-nav', $slider2.context),
            pagerAnchorBuilder: $slider2.prepareTabs2,
            before: $slider2.activateTab2,
            pauseOnPagerHover: true,
            pause: true
        });            
    },
    prepareTabs2: function(i, slide2) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slider2.tabs.eq(i);
    },
    activateTab2: function(currentslide2, nextslide2) {
        // get the active tab
        var activeTab2 = $('a[href="#' + nextslide2.id + '"]', $slider2.context);
        
        // if there is an active tab
		if(activeTab2.length) {
            // remove active styling from all other tabs
            $slider2.tabs.removeClass('on');
            // add active styling to active button
            activeTab2.parent().addClass('on');
        }            
    }            
};

$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');    
    // initialise the 2slider when the DOM is ready
    $slider2.init();
});  

