# Album Plugin:	utils/keynavigation
# For info:	'album -plugin_info utils/keynavigation'
# For usage:	'album -plugin_usage utils/keynavigation'
use strict;
use File::Copy;

my $DESCRIPTION = << 'DESCRIPTION';
Adds left, right and up arrow key navigation to easy usability while browsing
thumbnailed album. Left arrow goes to previous image and right arrow to 
next image. Arrow up navigates one level up.

Plugin utilizes jQuery from google server, 
see https://developers.google.com/speed/libraries/devguide for more information.

Tested:       Firefox, Chrome

Author:        Matti Laitala
Modifications: David Ljung Madison
DESCRIPTION

my @KEY_ORDER = qw();

sub start_plugin {
  my ($opt) = @_;

  # Setup the options
  # Setup the hooks
  album::hook($opt, 'write_image_page', \&setup_script);

  return {
    author => 'Matti Laitala',
    version => '1.0',
    description => $DESCRIPTION,
  };
}

sub setup_script {
  my ($opt, $data, $hookname, $dir, $file, $pic, $i, $prev, $next) = @_;

	my $obj = $data->{obj}{$pic};

	# Get the links
	my $prev_pic = $data->{pics}[$prev];
	my $prev_url = $data->{obj}{$prev_pic}{URL}{image_page}{image_page};
	my $next_pic = $data->{pics}[$next];
	my $next_url = $data->{obj}{$next_pic}{URL}{image_page}{image_page};

	album::add_head_image($opt,$data,$pic, <<HEAD);
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
\$(document).keyup(function(event) {
	switch (event.which) {
		case 37:
			window.location.href = $prev_url;
			break;
		case 38:
			window.location.href = "../";
			break;
		case 39:
			window.location.href = $next_url;
			break;
		default:
			return;
			break;
	}
	event.preventDefault();
});
</script>
HEAD
  
  return 0;	# Don't skip the album!
}

# Plugins always end with:
1;


