// This file controls the navigational elements of the page, mostly just open and closes on the main nav and the audio box
// It's relient on the globally declared clearGrid() from timeline.js



jQuery(document).ready(function($) 
{
	// Init Animations
	//fd.ca.init();
	//Now being triggered from 'showgrid' function in timeline.js

	// Check audio state
	currentPage = $.cookie('currentPage');
	if(currentPage == 'Home') {
	var audioPlaying = true;
	
	} else {
	
		var audioPlaying = false;
		
	};


	var closed;
	
	$('.dropdown a').click(function() 
	{
		
		var fadeIn = false;
		var $id = $(this).attr("id");
		
		$('.filters').children('.tertiary').hide();
		$('.filters').children('.' + $id).show();
		
		$(this).parent().siblings().children('a').removeClass('selected');
		
		$(this).addClass('selected');
				
	});
	
	
	
	$('.all li a').click(function() 
	{
		
		currentYear = $(this).attr('id');
		
		$.cookie('yearClicked', 'true');
			
		// Set cookie to remember on next page
		jQuery.cookie('currentYear', currentYear, { path: '/' });

			
		$(this).parent().siblings().children().removeClass('selected');
		$(this).addClass('selected');
			
		clearGrid(true);
		
		
			
	});
	
	
	
	
	// ******* Filters/Nav scripts **** //
	$('.ctn_audio_icon').click( function() 
	{
	
		showAudio();
	
	});
	
	$('.ctn_audio img').click( function() 
	{
	
		hideAudio();
	
	});
	
	
	
	// ******* Homepage Audio Trigger  **** //
	// ******* Homepage Audio Trigger  **** //


	$('.ctn_play_btn .audio').click( function() 
	{
	
		
		$str = $(this).attr('title');
		 $("#audio_title").html("Now playing: " + $str);
	
	});
	




// Play audio button
$('.ctn_play_btn a').live('click', function()
{
	
	// Get url from rel
	audio_url = $(this).attr('rel');
		
	// Play audio passing the url
	playAudio();
	
		
});
	
	
		
function playAudio() 
{
	// Find the player
	var player = document.getElementById('playerID');
	
	if(player) {
		
	var state = player.getConfig().state;
	
	if(state == "PLAYING") {
		player.sendEvent('PAUSE');
	}

	// Load the track
	player.sendEvent('LOAD',audio_url);
	
	state = player.getConfig().state;
	
	//alert(state);
	
	if(state != "BUFFERING") {
		// Play the track
		player.sendEvent('PLAY');
	}


    // This line adds the listener.  

		
	// Slide the audio player in
	showAudio();
	
	};
	
};


$('#next_prev_btns_single div a').hover(function() {

	$(this).parent().css('background','#fff');


}, function() {


	$(this).parent().css('background','#000');



})


function check_state(obj){

var player = document.getElementById('playerID');

  
  }	
	
	function showAudio() 
	{
	
		$('.ctn_audio_icon').animate({ bottom: '-40' }, 250, function() 
		{ 
		
			$('.ctn_audio').animate({ bottom: '0' }, 250);
		
		});
	
	};
	
	
	function hideAudio() 
	{
	
		$('.ctn_audio').animate({ bottom: '-40' }, 250, function() 
		{ 
		
			$('.ctn_audio_icon').animate({ bottom: '0' }, 250);
		
		});
	
	};
	
	
	
	$('.playlist a').click(function() {
	
		
		$(this).parent().siblings().children().removeClass('playing');
		
		$(this).addClass('playing');
		
	
	})
	



});
