/**
 * The Modal jQuery plugin
 *
 * @author Alexander Makarov <sam@rmcreative.ru>
 * @link https://github.com/samdark/the-modal
 * @version 1.0
 */
;(function($, window, document, undefined) {
	"use strict";
	/*jshint smarttabs:true*/

	var pluginNamespace = 'the-modal',
		// global defaults
    	defaults = {
			overlayClass: 'themodal-overlay',

			closeOnEsc: true,
			closeOnOverlayClick: true,

			onClose: null,
			onOpen: null
        };

	function lockContainer() {
		$('html,body').addClass('lock');
	}
	
	function unlockContainer() {
		$('html,body').removeClass('lock');
	}

	function init(els, options) {
		var modalOptions = options;

		if(els.length) {
			els.each(function(){
				$(this).data(pluginNamespace+'.options', modalOptions);
			});
		}
		else {
			$.extend(defaults, modalOptions);
		}

		return {
			open: function(options) {
				var el = els.get(0);
				var localOptions = $.extend({}, defaults, $(el).data(pluginNamespace+'.options'), options);

				// close modal if opened
				if($('.'+localOptions.overlayClass).length) {
					$.modal().close();
				}
				
				lockContainer();

				var overlay = $('<div/>').addClass(localOptions.overlayClass).prependTo('body');
				overlay.data(pluginNamespace+'.options', options);

				if(el) {
					$(el).clone(true).appendTo(overlay).show();
				}

				if(localOptions.closeOnEsc) {
					$(document).bind('keyup.'+pluginNamespace, function(e){
						if(e.keyCode === 27) {
							$.modal().close();
						}
					});
				}

				if(localOptions.closeOnOverlayClick) {
					overlay.children().on('click.' + pluginNamespace, function(e){
						e.stopPropagation();
					});
					$('.' + localOptions.overlayClass).on('click.' + pluginNamespace, function(e){
						$.modal().close();
					});
				}

				$(document).bind('touchmove.'+pluginNamespace,function(e){
					if(!$(e).parents('.' + localOptions.overlayClass)) {
						e.preventDefault();
					}
				});

				if(localOptions.onOpen) {
					localOptions.onOpen(overlay, localOptions);
				}
			},
			close: function() {
				var el = els.get(0);

				var localOptions = $.extend({}, defaults, options);
				var overlay = $('.' + localOptions.overlayClass);
				$.extend(localOptions, overlay.data(pluginNamespace+'.options'));

				overlay.remove();
				unlockContainer();

				if(localOptions.closeOnEsc) {
					$(document).unbind('keyup.'+pluginNamespace);
				}

				if(localOptions.onClose) {
					localOptions.onClose(overlay, localOptions);
				}
			}
		};
	}

	$.modal = function(options){
		return init($(), options);
	};

	$.fn.modal = function(options) {
		return init(this, options);
	};

})(jQuery, window, document);

@@ -428,16 +428,35 @@
 en: null
+,%0A%0A%09%09%09cloning: true
 %0A       
@@ -1275,24 +1275,219 @@
 %09%09%09if(el) %7B%0A
+%09%09%09%09%09if (!localOptions.cloning) %7B%0A%09%09%09%09%09%09overlay.data(pluginNamespace+'.el', el);%0A%09%09%09%09%09%09$(el).data(pluginNamespace+'.parent', $(el).parent());%0A%09%09%09%09%09%09$(el).appendTo(overlay).show();%0A%09%09%09%09%09%7D else %7B%0A%09
 %09%09%09%09%09$(el).c
@@ -1519,24 +1519,31 @@
 ay).show();%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%7D%0A%0A%09%09%09%09i
@@ -2463,24 +2463,195 @@
 ptions'));%0A%0A
+%09%09%09%09if (!localOptions.cloning) %7B%0A%09%09%09%09%09if (!el) %7B%0A%09%09%09%09%09%09el = overlay.data(pluginNamespace+'.el');%0A%09%09%09%09%09%7D%0A%09%09%09%09%09$(el).appendTo($(el).data(pluginNamespace+'.parent'));%0A%09%09%09%09%7D%0A%0A
 %09%09%09%09overlay.

Add moving (in additional to cloning) element of the modal window to overlay.