//jQuery.noConflict();
//var j$ = jQuery;
j$slideshow = {
    context: false,
    tabs: false,
    timeout: 2000,      // time before next slide appears (in ms)
    slideSpeed: 10000,   // time it takes to slide in each slide (in ms)
    tabSpeed: 300,      // 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 = j$('#slideshow');
        
        // set tabs to current hard coded navigation items
        this.tabs = j$('ul.slides-nav 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
        j$('div.slides > div', j$slideshow.context).cycle({
            fx: j$slideshow.fx,
            timeout: j$slideshow.timeout,
            speed: j$slideshow.slideSpeed,
            fastOnEvent: j$slideshow.tabSpeed,
            pager: j$('ul.slides-nav', j$slideshow.context),
            pagerAnchorBuilder: j$slideshow.prepareTabs,
            before: j$slideshow.activateTab,
            pauseOnPagerHover: true,
            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 j$slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = j$('a[href="#' + nextSlide.id + '"]', j$slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            j$slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');
        }            
    }            
};


j$(function() {
    // add a 'js' class to the body
    j$('body').addClass('js');
    
    // initialise the slideshow when the DOM is ready
    j$slideshow.init();
});  
