$slideview = {
    context: false,
    tabs: false,
    timeout: 8000,      // time before the next slide plays/appears
    slideSpeed: 1000,   // sliding speed for each slide
    tabSpeed: 600,      // speed timing
    fx: 'scrollLeft',   // slide effect -- scroll left

    init: function() {
        // initilialize slideview context
        this.context = $('#slideview');

        // set tabs to current hard coded navigation items
        this.tabs = $('ul.paging li', this.context); 

        // remove hard coded navigation items from DOM
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();

        // prepare slideview and jQuery cycle tabs
        this.prepareslideview();
    },

    prepareslideview: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to:
        // http://malsup.com/jquery/cycle/options.html
        $("div.slides > ul", $slideview.context).cycle({
            fx: $slideview.fx,
            timeout: $slideview.timeout,
            speed: $slideview.slideSpeed,
            fastOnEvent: $slideview.tabSpeed,
            pager: $("ul.paging", $slideview.context),
            pagerAnchorBuilder: $slideview.prepareTabs,
            before: $slideview.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 $slideview.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideview.context);

        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideview.tabs.removeClass('on');

            // add active styling to active button
            activeTab.parent().addClass('on');
        }
    }
};


$(function() {
    // initialise the slideview when the DOM is ready
    $slideview.init();
});

$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');
	$('body').removeClass('js');

    // initialise the slideshow when the DOM is ready
    $slideview.init();
});


