/*
	Any site-specific scripts you might have.
	Note that <html> innately gets a class of "no-js".
	This is to allow you to react to non-JS users.
	Recommend removing that and adding "js" as one of the first things your script does.
	Note that if you are using Modernizr, it already does this for you. :-)
*/

$(document).ready(function() {
	
/*
	Animation of Expanding Fringe Booking Menu
*/	

	//Remove CSS based reveal, to give jQuery control
		$(".unshrouded .bookend a").width(0);
		
	//On hover toggle the booking menu
		$(".unshrouded #fringe-highlight").hover(
		  function () {
		    $(".bookend > .tonic").stop(true, true).animate({
			    width: 91
			  }, 200, 'linear', function() {
			  });
			
		    $(".bookend > .fringe").stop(true, true).animate({
			    width: 100
			  }, 200, 'linear', function() {
			    // Animation complete.
			  });
		  }, 
		  function () {
		    $(".bookend > .fringe").stop(true, true).animate({
			    width: 0
			  }, 400, 'linear', function() {
			  }); 
			
			$(".bookend > .tonic").stop(true, true).animate({
			    width: 0
			  }, 500, 'linear', function() {
			    // Animation complete.
			  });
			
		  }
		);

/*
	Facebook and Twitter Tabs
*/

	//animate reveal/hide
	$(".popper").hover(function() {
		$(this).children(".reveal").stop().animate({bottom: "0px"}, 300);
		$(this).children(".tab").stop().animate({bottom: "-50px"}, 300);
	}, function() {
		var height = $(this).children(".reveal").height() + 5;
		$(this).children(".reveal").stop().animate({bottom: "-"+height+"px"}, 600);
		$(this).children(".tab").stop().animate({bottom: "0px"}, 1500);
	});	 

/*
	Video Menu Controls
*/

	$("#video-menu-down").click(function() {
		//Take top child from negative-spill and put in list
		$("#video-list a:first").remove().appendTo("#video-list-spill");
		$("#video-list-spill a:first").remove().appendTo("#video-list");
	});
	
	$("#video-menu-up").click(function() {
		//Take top child from negative-spill and put in list
		$("#video-list a:last").remove().insertBefore("#video-list-spill a:first");
		$("#video-list-spill a:last").remove().insertBefore("#video-list a:first");
			
	});

/*
	Video Switcher
*/

	$("#video-list a").click(function(e) {
		e.preventDefault();
		var videoRef = $(this).attr("id");
		$(".video-focus").removeClass("video-focus");
		$(this).addClass("video-focus");
		
		$(".video-frame > article").remove();
		$.ajax({
			url: "http://wittank.wordpress/wp-content/themes/boilerplate/wittank-ajax.php?video=" + videoRef,
			cache: false,
			success: function(html){
				$(".video-frame").append(html);
			}
		});
	});

	
/*
	Show Switcher
*/	

	$(".future-shows a").click(function(e) {
		e.preventDefault();
		var requestURL = $(this).attr("href");
		
		//Switch Shows
		$.ajax({
			url: requestURL,
			cache: false,
			success: function(html){
				$(".show-container article").remove();
				$(".show-container").append(html);
			}
		});
		
		//Switch Menu focus
		$(".future-shows .selected").removeClass('selected');
		$(this).addClass('selected');
	});
	
	$(".mailchimp-submit-button").click(function() {		
		$(".locked-area").remove();
		$(".unlocked-area").removeClass("hide");
		// Create/write a cookie and store it for 1 day
		$.cookie('presstest', 'set', { expires: 60 });
	});
	
	if($.cookie('presstest') == 'set'){
		$(".locked-area").remove();
		$(".unlocked-area").removeClass("hide");
	};
	
});
