
$(document).ready(function(){
// Add the class 'js' to the body element on load
 $("body").addClass("js");

	$("div.accordion-box div.accordion-content").hide();
	$("div.accordion-box h3").click(function(){
		$(this).next("div.accordion-box div.accordion-content").slideToggle("fast");
		$(this).toggleClass("active");
	});
	
	$("div.accordion-box h3").hover(function(){
		$(this).addClass("hover");
	}, function() {
		$(this).removeClass("hover");	
	});

	// !rollover state functionality for dynamic buttons
	$('.story a').hover(function() {
		$(this).children().addClass('hover');
	}, function() {
		$(this).children().removeClass();
	});
	
	// !stories slideshow
		
	//adds an id to each slide	
	$('ul#slides>li').each(function(index, element) {
		$(element).attr('id', 'slide_'+index);
	});
	
	if ($('ul#slides>li').hasClass('selected')) {
	$('ul#slides>li.selected').show().siblings().hide();
	} else {
	//finds number of slides in deck and provides random number generator
	var totalNum = $('ul#slides>li').size();
	var randSlide = "slide_" + (Math.floor(Math.random() * totalNum));
	}
	//shows random slide while hiding all others
	$('ul#slides li#' + randSlide).show().siblings().hide();


	if ($('ul#slides>li').length> 1) {
	//creates trigger link for each slide (switcher)
	$('ul#slides').after('<ol id="switches"></ol>');
	$('ul#slides>li').each(function(i) {
		var start = 1;
		$('#switches').append('<li><a href="#">' + (start + i).toString() + '</a></li>');
	});
	//adds a class to each link generated above
	$('#switches li:first-child').addClass('active');
	$('#switches li a').each(function(index, element) {
			$(element).attr('class', 'switch_'+index);
		});
	} //end if
		
	//associates each link with corresponding slide & sets active state 
	$('#switches a').click(
		function(){
			$(this).parent().addClass('active').siblings().removeClass('active');
			var switchIndex = $(this).attr('class');
			var classChar = switchIndex.length;
			var slideIndex = switchIndex.charAt(classChar-1);
			$('#slide_' + slideIndex).fadeIn("slow").siblings().hide();
			return false;
		});
	
});
