jQuery(document).ready(function($) {

	/* ============ key bindings ============== */
	/* we are using jquery hotkeys to handle key bindings */

	window.Bindings = {

		init : function() {
			/*
			 * binding return keypress and kayup to take control over Enter in
			 * all browsers
			 */

			$(document).bind('keydown', 'Ctrl+]', function() {
				return false;
			});
			$(document).bind('keypress', 'return', function(evt) {
				return false;
			});
			$(document).bind('keyup', 'return', function(evt) {
				return false;
			});
			return this;
		},
		addSetPageBindings : function() {
			$(document).bind('keydown', 'p', function() {
				if (!$('.previous_photo').hasClass('disabled') && $('.modal:visible').length == 0) {
					window.location.href = $('.previous_photo').attr('href');
				} else {
					return true;
				}
				return false;
			});
			$(document).bind('keydown', 'n', function() {
				if (!$('.next_photo').hasClass('disabled') && $('.modal:visible').length == 0) {
					window.location.href = $('.next_photo').attr('href');
				} else {
					return true;
				}
				return false;
			});
			$(document).bind('keydown', 'e', function() {
				if ($('.modal:visible').length == 0) {
					$('.edit').click();
				} else {
					return true;
				}
				return false;
			});
			$(document).bind('keydown', 's', function() {
				if ($('.modal:visible').length == 0) {
					$('.embed-link').click();
				} else {
					return true;
				}
				return false;
			});

		},
		addNamingModalBindings : function() {
			/* keyboard events for naming modal, not a face-'n', mark as bug-'b' */
			$(document).bind('keydown', {
				combi : 'n',
				disableInInput : true
			}, function(evt) {
				if ($('.notaface').length != 0) {
					Naming.skipFace();
					Bindings.clearNamingModalBindings();
				}
				return false;
			});
			$(document).bind('keydown', {
				combi : 'b',
				disableInInput : true
			}, function(evt) {
				Naming.markAsNotAFace();
				Bindings.clearNamingModalBindings();
				return false;
			});

			$(document).bind('keydown', 'return', function(evt) {
				if ($('li .match:visible').length == 1 || $('li#add_email:visible').length == 1) {
					GeneralUtils.autocomplete.chooseSelectedValue();
					if (GeneralUtils.autocomplete.enterPressedCallback)
						return GeneralUtils.autocomplete.enterPressedCallback(GeneralUtils.autocomplete.inputElement);
					return false;
				} else {
					return false;
				}
			});

		},
		clearNamingModalBindings : function() {
			/* clean up bindings */
			$(document).unbind('keydown', 'n');
			$(document).unbind('keydown', 'b');
			$(document).unbind('keydown', 'tab');
			$(document).unbind('keydown', 'return');
		}

	}.init();
});
