/* Author: Swarley */

$(function() {
	
	$(".showImg-tn").click(function() {
		// add controls to imgSection	
		$("#imgSection img").attr("src", $(this).attr("src"));
		$("#videoSection").slideUp("slow", function() {
			$("#imgSection").slideDown("slow", function() {
				$('html,body').animate({ scrollTop: $("#imgSection").parent(".siteContainer").offset().top }, { duration: 'slow', easing: 'swing'});
				if ($("#detailsSection li.selected").text() == "Video & Audio") {
					$("#detailsSection li:first").click();
				}
			})
		});
	});
	$("#arrowLeft").click(function() {
		var prevImg = $(".showImg-tn[src=\"" + $('#imgSection img').attr('src') + "\"]").prev().attr("src");
		if (prevImg) {
			$("#imgSection").animate({opacity: 0}, function() {
				$("#imgSection img").attr("src", prevImg);
				$("#imgSection").animate({opacity: 1 });
			});
		}
	});
	$("#arrowRight").click(function() {
		var nextImg = $(".showImg-tn[src=\"" + $('#imgSection img').attr('src') + "\"]").next().attr("src");	
		if (nextImg) {
			$("#imgSection").animate({opacity: 0}, function() {
				$("#imgSection img").attr("src", nextImg);
				$("#imgSection").animate({opacity: 1 });
			});
		}
	});
	$("#close").click(function() {
		$("#imgSection").slideUp("slow");		
	});
	
	$("#detailsSection li").click(function() {
		if (!$(this).hasClass('selected')) {
			
			$("#detailsSection li.selected").removeClass("selected");
			$(this).addClass("selected");
			
			switch ($(this).text()) {
				case "Overview":
					$("#detailsSection div.selected").animate({opacity: 0}, function() {
						$(this).hide("slow").removeClass("selected");
						$("#overview").show("slow").addClass('selected').animate({opacity: 1});
					});
					break;
				case "Director\'s Notes":
					$("#detailsSection div.selected").animate({opacity: 0}, function() {
						$(this).hide("slow").removeClass("selected");
						$("#notes").show("slow").addClass('selected').animate({opacity: 1});
					});	
					break;
				case "Show Snippets":
					$("#detailsSection div.selected").animate({opacity: 0}, function() {
						$(this).hide("slow").removeClass("selected");
						$("#snippets").show("slow").addClass('selected').animate({opacity: 1});
					});
					break;
				case "Video & Audio":
					//if ($("#imgSection").is(":visible")) {
					$("#imgSection").slideUp("slow", function() {
						$("#videoSection").slideDown("slow", function() {
							$('html,body').animate({ scrollTop: $("#videoSection").parent(".siteContainer").offset().top }, { duration: 'slow', easing: 'swing'});	
						});
					});
					
					//$("#detailsSection div.selected").addClass('selected');
					
					
					break;
				case "Creative Team":
					$("#detailsSection div.selected").animate({opacity: 0}, function() {
						$(this).hide("slow").removeClass("selected");
						$("#team").show("slow").addClass('selected').animate({opacity: 1});
					});
					break;
				case "Reviews":
					$("#detailsSection div.selected").animate({opacity: 0}, function() {
						$(this).hide("slow").removeClass("selected");
						$("#reviews").show("slow").addClass('selected').animate({opacity: 1});
					});
					break;
				case "Ticket Info":
					$("#detailsSection div.selected").animate({opacity: 0}, function() {
						$(this).hide("slow").removeClass("selected");
						$("#tickets").show("slow").addClass('selected').animate({opacity: 1});
					});
					break;
			}
		}
	});
	$("#detailsSection div:last").addClass('selected');
	$("#detailsSection li:first").click();
});




















