$(document).ready(function() {
	
	// Get META data into global namespace
	var meta = parse_meta_data();
	
	// Index Gallery Slider
	var current_photo = 0;
	var number_of_photos = 2;
	$('#gallery-control-next').click(function(){
		if (!$('#gallery-control-next').hasClass('disabled'))
		{			
			$('#gallery-control-previous').removeClass('disabled')
			current_photo++;
			
			$('#gallery-image').attr('src', meta.gallery.images[current_photo].thumb);
			$('#gallery-full').attr('src', meta.gallery.images[current_photo].full);
			$('#gallery-title').text(meta.gallery.images[current_photo].title);
			$('#gallery-caption').text(meta.gallery.images[current_photo].caption);
			$('#gallery-date').text(meta.gallery.images[current_photo].date);
			if (current_photo >= number_of_photos)
			{
				$('#gallery-control-next').addClass('disabled')
			}
		}		
	});
	
	$('#gallery-control-previous').click(function(){
		if (!$('#gallery-control-previous').hasClass('disabled'))
		{		
			$('#gallery-control-next').removeClass('disabled')
			current_photo--;
			$('#gallery-image').attr('src', meta.gallery.images[current_photo].thumb);
			$('#gallery-full').attr('src', meta.gallery.images[current_photo].full);
			$('#gallery-title').text(meta.gallery.images[current_photo].title);
			$('#gallery-caption').text(meta.gallery.images[current_photo].caption);
			$('#gallery-date').text(meta.gallery.images[current_photo].date);
			if (current_photo <= 0)
			{
				$('#gallery-control-previous').addClass('disabled')
			}
		}
	});
	
	$('#gallery-image').click(function(){
		$('#gallery-full').fadeIn('slow');		
		$('#gallery-full-controls').show(200);
	});
	
	$('#gallery-full').click(function(){
		$('#gallery-full').hide();
		$('#gallery-full-controls').hide();
	});
	
	$('#gallery-close').click(function(){
		$('#gallery-full').hide();
		$('#gallery-full-controls').hide();
	});
	
	$('.code_block_toggle').click(function(){
		$(this).parent().parent().children('textarea').toggle();
		$(this).parent().parent().children('.pretty').toggle();
	});
});

// Fetches and parses META data
function parse_meta_data()
{
	//var $json = $('#meta').text();
	//return $.parseJSON($json);
}
