
$(document).ready(function() {

	// initialize the drop down menu
	$('ul.sf-menu').superfish();

	// show the first content block & image for the accordian/slider
	$(".SliderAccordianContent:first").show();
	$("#SliderPhotoContainer > div:first").show();
	
	// listen for click in the accordian heading
	$("#SliderNavigation ul li").click(function() {
		clickedIndex = $("#SliderNavigation ul li").index(this) + 1; // get the index of the accordian header we clicked
		if ($(this).children("div.SliderAccordianContent").is(":hidden")) { // don't animate if we're already on the one we clicked
			$(".SliderAccordianContent").slideUp("slow"); // hide all other accordian content
			$(this).children().slideDown("slow");  // show this one's content
			$("#SliderPhotoContainer > div").hide();  // hide the current photo
			$("#SliderPhotoContainer > div:nth-child("+clickedIndex+")").fadeIn(1000); // fade in the new photo
		}
	});
	
	// show the first content block for the Market Perspectives
	$("#MarketProspectivesContentWrap > div:first").show();
	$("#MarketProspectivesNav > ul > li:first").addClass("current"); // and set the class to current

	// listen for click in the Market Perspectives content area
	$("#MarketProspectivesNav > ul > li").click(function() {
		$("#MarketProspectivesNav > ul > li").removeClass("current"); // remove the current class from all nav items
		$(this).addClass("current");  // apply the current class to the active nav item
		clickedIndex = $("#MarketProspectivesNav > ul > li").index(this) + 1; // get the index of the content we clicked
		if ($("#MarketProspectivesContentWrap > div:nth-child("+clickedIndex+")").is(":hidden")) { // don't animate if we're already on the one we clicked
			$("#MarketProspectivesContentWrap > div").hide();  // hide the current content
			$("#MarketProspectivesContentWrap > div:nth-child("+clickedIndex+")").show('slow'); // fade in the new content
		}
	});
	
	// setup timer for autoplay on main content slider
	setInterval ( "_nextSlide()", 5000 );
		
});


function _nextSlide() {
	// figure out what current slide we're on (find the index of the visible div.SliderAccordianContent)
	$.each($("#SliderNavigation > ul > li"), function(index, value) {
		if (!$(this).children("div.SliderAccordianContent").is(":hidden")) {
			// what's the next one? (if last, next is the first)
			nextSlideIndex = index + 2;
			if (index == 5) nextSlideIndex = 1;
			$("#SliderNavigation > ul > li:nth-child("+nextSlideIndex+")").click(); // trigger the click event on the next slide nav
			return false;
		}
	});
}

