﻿jQuery.fn.zoom = function (fn) {
	// Set handler for keyboard zooming in Firefox, IE, Opera, Safari.
	// This is the only valid case of browser-specific code I've ever seen -JM
	jQuery(document).keydown(function (e) {
		switch (true) {
			case jQuery.browser.mozilla || jQuery.browser.msie || jQuery.browser.safari:
				if (e.ctrlKey && (
					e.which == 187 || // =/+ (zoom in [FF, IE])
					e.which == 189 || // -   (zoom out [FF, IE])
					e.which == 107 || // +   (numpad) (zoom in [FF, IE])
					e.which == 109 || // -   (numpad) (zoom out [FF, IE])
					e.which == 96 || // 0   (reset zoom [FF, IE])
					e.which == 48     // 0   (numpad) (reset zoom [IE, FF, Opera])
				)) fn();
				break;
			case jQuery.browser.opera:
				// Opera requires CTRL to be pressed for reset (using num 0)
				if (
					e.which == 43 ||             // +   (numpad) (zoom in [Opera, Safari])
					e.which == 45 ||             // -   (numpad) (zoom out [Opera, Safari])
					e.which == 42 ||             // *   (numpad) (reset zoom [Opera])
					(e.ctrlKey && e.which == 48) // 0   (numpad) (reset zoom [FF, IE, Opera])
				) fn();
				break;
//			case jQuery.browser.safari:
//				// Use e.metaKey for the Apple key
//				if (e.metaKey && (
//					e.charCode == 43 || // +   (numpad) (zoom in [Opera, Safari])
//					e.charCode == 45    // -   (numpad) (zoom out [Opera, Safari])
//				)) fn();
//				break;
		}
		return;
	});

	// Set handler for scrollwheel zooming in IE
	jQuery(document).bind('mousewheel', function (e) {
		if (e.ctrlKey) fn();
	});

	// Set handler for scrollwheel zooming in Firefox
	jQuery(document).bind('DOMMouseScroll', function (e) {
		if (e.ctrlKey) fn();
	});
};

