$(document).ready(function() {

	$('.slider').advancedSlider({
        width:1000, 
        height:480, 
        effectType:'fade',
        sliceDuration: 750,
        sliceDelay: 500,
        navigationButtons: false,
        horizontalSlices:1, 
        verticalSlices:1,
        slideshow: true,
        shadow:false,
        captionPosition: 'custom',
        captionShowEffect: 'fade',
        captionLeft: 555,
        captionTop: 95,
        captionBackgroundColor: 'transparent',
        fadeNavigationArrows: false,
        slideshowControls:false,
        timerAnimation:false
	});
	
	//home gallery
	$(".slidetabs").tabs(".images > div", {
		effect: 'fade',
		interval: '500',
		autoplay: true,
		rotate: true
	}).slideshow();
	
	$("input, textarea, select, button").uniform();
	
	// Events table.
	(function() {
		var sections = [];
		
		/**
		 * Populate sections, set navigation, and show the first section.
		 */
		function init() {
			// Get all sections.
			sections = $('.post-type-archive-event table tbody');
			
			// Show the first section.
			if (sections.length) {
				show(sections[0]);
			
				// Set navigation.
				set_nav();
			}
		}
		
		/**
		 * Set navigation to display each section (drop-down menu).
		 */
		function set_nav() {
			// Build navigation.
			var select_nav = $('<select>');
			for (i = 0; i < sections.length; i++) {
				select_nav.append($('<option>', {
					value: i,
					html: get_section_title(sections[i])
				}));
			}
			
			// Set events.
			select_nav.change(function(evt) {
				var section_index = evt.target.value;
				show(sections[section_index]);
			});
			
			// Add navigation to DOM.
			$('aside').prepend(select_nav);
			
			// Eye-candy stuff.
			select_nav.uniform();
		}
		
		/**
		 * Show the given section, hide the others.
		 */
		function show(section) {
			for (i = 0; i < sections.length; i++) {
				if (sections[i] == section) {
					$(sections[i]).show();
				}
				else {
					$(sections[i]).hide();
				}
			}
		}
		
		/**
		 * Return the title of the section (the first <th>).
		 */
		function get_section_title(section) {
			var titles = $('th', section);
			if (titles) {
				return titles.html();
			}
			return '';
		}
		
		init();
	})();
});	


$.tools.tabs.addEffect("fadeInOut", function(i, done) {

	this.getPanes().hide();
	
	var nextPane = this.getPanes().eq(i);
	
	nextPane.fadeTo(500, .99, function() {
		done.call();
	});
});


