slideshow = {
    context: false,
    tabs: true,
    timeout: 5000,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 1000,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollLeft',   // the slide effect to use
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = ('#slideshow');
        
        // set tabs to current hard coded navigation items
        this.tabs = jQuery('ul.slides li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        jQuery('div.slides > ul', slideshow.context).cycle({
            fx: slideshow.fx,
            timeout: slideshow.timeout,
            speed: slideshow.slideSpeed,
            fastOnEvent: slideshow.tabSpeed,
            pager: jQuery('ul.slides-nav', slideshow.context),
            pagerAnchorBuilder: slideshow.prepareTabs,
            before: slideshow.activateTab,
            pauseOnPagerHover: false,
            pause: true
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = jQuery('a[href="#' + nextSlide.id + '"]', slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            slideshow.tabs.removeClass('active');
            
            // add active styling to active button
            activeTab.parent().addClass('active');
        }            
    }            
};
slideshow2 = {
    context: false,
    tabs: true,
    timeout: 5000,      // time before next slide appears (in ms)
    slideSpeed: 1000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 1000,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'scrollRight',   // the slide effect to use
    init: function() {
        this.context = ('#BotTabs');
        this.tabs = jQuery('ul.slides-nav2 li', this.context);
        this.tabs.remove();
        this.prepareSlideshow2();
    },
    prepareSlideshow2: function() {
        jQuery('div.slides2 > ul', slideshow2.context).cycle({
            fx: slideshow2.fx,
            timeout: slideshow2.timeout,
            speed: slideshow2.slideSpeed,
            fastOnEvent: slideshow2.tabSpeed,
            pager: jQuery('ul.slides-nav2', slideshow2.context),
            pagerAnchorBuilder: slideshow2.prepareTabs2,
            before: slideshow2.activateTab2,
            pauseOnPagerHover: true,
            pause: true
        });         
    },
    prepareTabs2: function(i, slide) {
        return slideshow2.tabs.eq(i);
    },
    activateTab2: function(currentSlide, nextSlide) {
        var activeTab2 = jQuery('a[href="#' + nextSlide.id + '"]', slideshow2.context);
        if(activeTab2.length) {
            slideshow2.tabs.removeClass('active');
            activeTab2.parent().addClass('active');
        }            
    }            
};


jQuery(function() {
    slideshow.init();
    slideshow2.init();
});  
