$slideshow = {
    context: false,
    tabs: false,
    timeout: 240000,   // time before next slide appears (in ms) //default was  5000 
    slideSpeed:300,   // time it takes to slide in each slide (in ms) //default was 300
    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 = $('#slideshow');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('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
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true,  
			//next: '#slideshow', //this will bring in the next piece on click
			//pause: 1, //this will pause on rollover
			prev:   '#prev',
			next: '#next'		    
        });            
    },
    

         
    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 = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        			
			$('#slideshow').cycle('pause');
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');

        }       

    }            
};

//get first tab set on initialization
$(function() {
    // add a 'js' class to the body
    $('body').addClass('js');
    
    // initialise the slideshow when the DOM is ready
    $slideshow.init();
});    
   
/*


		function getTop() {
			// get the top of the content
			var top = $('#scroll-content').css('top');
			return trimPx(top);
		}

		function getHeight(id) {
			// get the height, including padding
			var height = $(id).height();
			var paddingTop = trimPx($(id).css("padding-top"));
			var paddingBottom = trimPx($(id).css("padding-bottom"));

			return height + paddingTop + paddingBottom;
		}

		function trimPx(value) {
			// remove "px" from values
			var pos = value.indexOf("px");
			if (pos != 0)
				return parseInt(value.substring(0, pos));
			else
				return 0;
		}

		var container;
		var content;
		var hidden;	// # of pixels hidden by the container

		function setScrollerDimensions() {
			container = getHeight("#scroll-container");
			content = getHeight("#scroll-content");
			hidden = content - container;
		}

		function resetScroller() {
			setScrollerDimensions();
			$('#scroll-content').css('top', 0);
		}

		$(document).ready(function() {

			setScrollerDimensions();

			$('#scroll-controls a.up-arrow').click(function() {
				return false;
			});

			$('#scroll-controls a.down-arrow').click(function() {
				return false;
			});

			$('#scroll-controls a.down-arrow').hover(
				function() {
					if (hidden > 0) {
						var current = getTop();
						$('#scroll-content').animate({ top: -hidden }, Math.abs(current - hidden) * 5);
					}
				},
				function() {
					$('#scroll-content').stop();
				}
			);

			$('#scroll-controls a.up-arrow').hover(
				function() {
					if (hidden > 0) {
						var current = getTop();
						$('#scroll-content').animate({ top: "0" }, Math.abs(current) * 5);
					}
				},
				function() {
					$('#scroll-content').stop();
				}
			);
		});
	

*/
//get control the text scroll...
		/*function getTop() {
			// get the top of the content
			var top = $('.scroll-content').css('top');
			return trimPx(top);
		}

		function getHeight(id) {
			// get the height, including padding
			var height = $(class).height();
			var paddingTop = trimPx($(class).css("padding-top"));
			var paddingBottom = trimPx($(class).css("padding-bottom"));

			return height + paddingTop + paddingBottom;
		}

		function trimPx(value) {
			// remove "px" from values
			var pos = value.indexOf("px");
			if (pos != 0)
				return parseInt(value.substring(0, pos));
			else
				return 0;
		}

		var container;
		var content;
		var hidden;	// # of pixels hidden by the container

		function setScrollerDimensions() {
			container = getHeight(".scroll-container");
			content = getHeight(".scroll-content");
			hidden = content - container;
		}

		function resetScroller() {
			setScrollerDimensions();
			$('.scroll-content').css('top', 0);
		}

		$(document).ready(function() {

			setScrollerDimensions();

			$('.scroll-controls a.up-arrow').click(function() {
				return false;
			});

			$('.scroll-controls a.down-arrow').click(function() {
				return false;
			});

			$('.scroll-controls a.down-arrow').hover(
				function() {
					if (hidden > 0) {
						var current = getTop();
						$('.scroll-content').animate({ top: -hidden }, Math.abs(current - hidden) * 5);
					}
				},
				function() {
					$('.scroll-content').stop();
				}
			);

			$('.scroll-controls a.up-arrow').hover(
				function() {
					if (hidden > 0) {
						var current = getTop();
						$('.scroll-content').animate({ top: "0" }, Math.abs(current) * 5);
					}
				},
				function() {
					$('.scroll-content').stop();
				}
			);
		});
	*/
