﻿$slideshow = {
	context: false,
	tabs: true,
	timeout: 3000,   // time before next slide appears (in ms)
	slideSpeed: 250, // time it takes to slide in each slide (in ms)
	tabSpeed: 100,   // time it takes to slide in each slide (in ms) when clicking through tabs
	fx: 'fade',      // the slide effect to use

	init: function() {
		this.context = $('#stSlider');
		this.tabs = $('#stTitleList li', this.context);
		this.prepareSlideshow();
	},
	prepareSlideshow: function() {
		// http://malsup.com/jquery/cycle/options.html
		$('div#stSlides', $slideshow.context).cycle({
			fx: $slideshow.fx,
			timeout: $slideshow.timeout,
			speed: $slideshow.slideSpeed,
			fastOnEvent: $slideshow.tabSpeed,
			pager: $('#stTitleList', $slideshow.context),
			pagerAnchorBuilder: $slideshow.prepareTabs,
			before: $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 $slideshow.tabs.eq(i);
	},
	activateTab: function(currentSlide, nextSlide) {
		var activeTab = $('li[name="' + nextSlide.id + '"]', $slideshow.context);
		if ( activeTab.length ) {
			$slideshow.tabs.removeClass('stSelected');
			activeTab.addClass('stSelected');
		}
	}
};

$('#stWrapper').ready(function(){
	$slideshow.init();
	$('#stSlides').css('display','block');
	$('#stTitleList > li:first').addClass('stSelected');
	// fix title links
	$('a.stEventLink').click(function(){ document.location.href = this.href; });
});

