$slideshow = {
    context:    false,
    tabs:       false,
    timeout:    5000,  // time before next slide appears (in ms)
    slideSpeed: 500,   // time it takes to slide in each slide (in ms)
    tabSpeed:   500,   // time it takes to slide in each slide (in ms) when clicking through tabs
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slides_cell');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('#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
        $('#slides', $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $('#slides_nav', $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true,
			height: '120px'
        });            
    },
    
    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);
        
        // 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');
        }            
    }            
};

$slideshowQuote = {
	init : function() {

		// Infinite scroller
		$('#right_scroll a').click(function() {
			$('#carousel_ul li:first').before($('#carousel_ul li:last'));        // Reverse the li's so that sliding left works
			$('#carousel_ul').css('left', -($('#carousel_inner').width() + 30)); // 30 = 10 pixel gutter between four icons
			$('#carousel_ul:not(:animated)').animate({'left': 0}, 500);			 
		});

		// Quotes section
		$('#carousel_ul li:first a:last').addClass('active');
		$("#quotes blockquote:last").show();
		
		$("#carousel_ul a").click(function() {
		
			$("#carousel_ul a").removeClass("active");
			$(this).addClass("active");
		
			$("#quotes blockquote").hide();
		
			var activeQuote = $(this).attr("href");
			$(activeQuote).fadeIn(250);
		
			return false;
		});
		
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$("ul.tabs li").click(function() {
	var section,
		activeTab,
		sectionPrefix = 'section-';
	
	$("ul.tabs li").removeClass("active"); //Remove any "active" class
	$(this).addClass("active"); //Add "active" class to selected tab
	$(".tab_content").hide(); //Hide all tab content
	
	activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
	window.location.hash = activeTab;
	
	// Find the section name without any #
	// so we can add the prefix
	section = activeTab.split('#')[1];
	section = '#' + sectionPrefix + section;
	$(section).fadeIn(); //Fade in the active ID content
	
	return false;
	});	
}
}

$(document).ready(function() {
	
    // Initialise slideshow
    $slideshow.init();

	// Initialise slide gallery + click to show quote
    $slideshowQuote.init();

	



});


