﻿!
function(a) {
	function e(b) {
		return b[0] && a.isPlainObject(b[0]) ? this.data = b[0] : this.el = b, this.isCoords = !0, this.coords = {}, this.init(), this
	}
	var f = e.prototype;
	f.init = function() {
		this.set(), this.original_coords = this.get()
	}, f.set = function(a, b) {
		var d, e, c = this.el;
		return c && !a && (this.data = c.offset(), this.data.width = c.width(), this.data.height = c.height()), c && a && !b && (d = c.offset(), this.data.top = d.top, this.data.left = d.left), e = this.data, this.coords.x1 = e.left, this.coords.y1 = e.top, this.coords.x2 = e.left + e.width, this.coords.y2 = e.top + e.height, this.coords.cx = e.left + e.width / 2, this.coords.cy = e.top + e.height / 2, this.coords.width = e.width, this.coords.height = e.height, this.coords.el = c || !1, this
	}, f.update = function(b) {
		if (!b && !this.el) return this;
		if (b) {
			var c = a.extend({}, this.data, b);
			return this.data = c, this.set(!0, !0)
		}
		return this.set(!0), this
	}, f.get = function() {
		return this.coords
	}, a.fn.coords = function() {
		if (this.data("coords")) return this.data("coords");
		var a = new e(this, arguments[0]);
		return this.data("coords", a), a
	}
}(jQuery, window, document), function(a, b, c) {
	function f(b, c, d) {
		this.options = a.extend(e, d), this.$element = b, this.last_colliders = [], this.last_colliders_coords = [], this.set_colliders(c), this.init()
	}
	var e = {
		colliders_context: c.body
	},
		g = f.prototype;
	g.init = function() {
		this.find_collisions()
	}, g.overlaps = function(a, b) {
		var c = !1,
			d = !1;
		return (b.x1 >= a.x1 && b.x1 <= a.x2 || b.x2 >= a.x1 && b.x2 <= a.x2 || a.x1 >= b.x1 && a.x2 <= b.x2) && (c = !0), (b.y1 >= a.y1 && b.y1 <= a.y2 || b.y2 >= a.y1 && b.y2 <= a.y2 || a.y1 >= b.y1 && a.y2 <= b.y2) && (d = !0), c && d
	}, g.detect_overlapping_region = function(a, b) {
		var c = "",
			d = "";
		return a.y1 > b.cy && a.y1 < b.y2 && (c = "N"), a.y2 > b.y1 && a.y2 < b.cy && (c = "S"), a.x1 > b.cx && a.x1 < b.x2 && (d = "W"), a.x2 > b.x1 && a.x2 < b.cx && (d = "E"), c + d || "C"
	}, g.calculate_overlapped_area_coords = function(b, c) {
		var d = Math.max(b.x1, c.x1),
			e = Math.max(b.y1, c.y1),
			f = Math.min(b.x2, c.x2),
			g = Math.min(b.y2, c.y2);
		return a({
			left: d,
			top: e,
			width: f - d,
			height: g - e
		}).coords().get()
	}, g.calculate_overlapped_area = function(a) {
		return a.width * a.height
	}, g.manage_colliders_start_stop = function(b, c, d) {
		var f, g, h, i, e = this.last_colliders_coords;
		for (f = 0, g = e.length; g > f; f++) - 1 === a.inArray(e[f], b) && c.call(this, e[f]);
		for (h = 0, i = b.length; i > h; h++) - 1 === a.inArray(b[h], e) && d.call(this, b[h])
	}, g.find_collisions = function(b) {
		for (var i, j, k, l, m, n, o, p, c = this, d = [], e = [], f = this.colliders || this.$colliders, g = f.length, h = c.$element.coords().update(b || !1).get(); g--;) i = c.$colliders ? a(f[g]) : f[g], j = i.isCoords ? i : i.coords(), k = j.get(), l = c.overlaps(h, k), l && (m = c.detect_overlapping_region(h, k), "C" === m && (n = c.calculate_overlapped_area_coords(h, k), o = c.calculate_overlapped_area(n), p = {
			area: o,
			area_coords: n,
			region: m,
			coords: k,
			player_coords: h,
			el: i
		}, c.options.on_overlap && c.options.on_overlap.call(this, p), d.push(j), e.push(p)));
		return (c.options.on_overlap_stop || c.options.on_overlap_start) && this.manage_colliders_start_stop(d, c.options.on_overlap_start, c.options.on_overlap_stop), this.last_colliders_coords = d, e
	}, g.get_closest_colliders = function(a) {
		var b = this.find_collisions(a);
		return b.sort(function(a, b) {
			return "C" === a.region && "C" === b.region ? a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1 ? -1 : 1 : a.area < b.area ? 1 : 1
		}), b
	}, g.set_colliders = function(b) {
		"string" == typeof b || b instanceof a ? this.$colliders = a(b, this.options.colliders_context).not(this.$element) : this.colliders = a(b)
	}, a.fn.collision = function(a, b) {
		return new f(this, a, b)
	}
}(jQuery, window, document), function(a) {
	a.delay = function(a, b) {
		var c = Array.prototype.slice.call(arguments, 2);
		return setTimeout(function() {
			return a.apply(null, c)
		}, b)
	}, a.debounce = function(a, b, c) {
		var d;
		return function() {
			var e = this,
				f = arguments,
				g = function() {
					d = null, c || a.apply(e, f)
				};
			c && !d && a.apply(e, f), clearTimeout(d), d = setTimeout(g, b)
		}
	}, a.throttle = function(a, b) {
		var c, d, e, f, g, h, i = debounce(function() {
			g = f = !1
		}, b);
		return function() {
			c = this, d = arguments;
			var j = function() {
					e = null, g && a.apply(c, d), i()
				};
			return e || (e = setTimeout(j, b)), f ? g = !0 : h = a.apply(c, d), i(), f = !0, h
		}
	}
}(window), function(a, b, c) {
	function k(b, d) {
		this.options = a.extend({}, e, d), this.$body = a(c.body), this.$container = a(b), this.$dragitems = a(this.options.items, this.$container), this.is_dragging = !1, this.player_min_left = 0 + this.options.offset_left, this.init()
	}
	var e = {
		items: "li",
		distance: 1,
		limit: !0,
		offset_left: 0,
		autoscroll: !0,
		ignore_dragging: ["INPUT", "TEXTAREA", "SELECT", "BUTTON"],
		handle: null,
		container_width: 0,
		move_element: !0,
		helper: !1
	},
		f = a(b),
		g = {
			x: "left",
			y: "top"
		},
		h = !! ("ontouchstart" in b),
		i = {
			start: h ? "touchstart.gridster-draggable" : "mousedown.gridster-draggable",
			move: h ? "touchmove.gridster-draggable" : "mousemove.gridster-draggable",
			end: h ? "touchend.gridster-draggable" : "mouseup.gridster-draggable"
		},
		j = function(a) {
			return a.charAt(0).toUpperCase() + a.slice(1)
		},
		l = k.prototype;
	l.init = function() {
		this.calculate_dimensions(), this.$container.css("position", "relative"), this.disabled = !1, this.events(), a(b).bind("resize.gridster-draggable", throttle(a.proxy(this.calculate_dimensions, this), 200))
	}, l.events = function() {
		this.$container.on("selectstart.gridster-draggable", a.proxy(this.on_select_start, this)), this.$container.on(i.start, this.options.items, a.proxy(this.drag_handler, this)), this.$body.on(i.end, a.proxy(function(a) {
			this.is_dragging = !1, this.disabled || (this.$body.off(i.move), this.drag_start && this.on_dragstop(a))
		}, this))
	}, l.get_actual_pos = function(a) {
		var b = a.position();
		return b
	}, l.get_mouse_pos = function(a) {
		if (h) {
			var b = a.originalEvent;
			a = b.touches.length ? b.touches[0] : b.changedTouches[0]
		}
		return {
			left: a.clientX,
			top: a.clientY
		}
	}, l.get_offset = function(a) {
		var b, c, d, e, f;
		return a.preventDefault(), b = this.get_mouse_pos(a), c = Math.round(b.left - this.mouse_init_pos.left), d = Math.round(b.top - this.mouse_init_pos.top), e = Math.round(this.el_init_offset.left + c - this.baseX + this.scroll_offset_x), f = Math.round(this.el_init_offset.top + d - this.baseY + this.scroll_offset_y), this.options.limit && (e > this.player_max_left ? e = this.player_max_left : e < this.player_min_left && (e = this.player_min_left)), {
			position: {
				left: e,
				top: f
			},
			pointer: {
				left: b.left,
				top: b.top,
				diff_left: c + this.scroll_offset_x,
				diff_top: d + this.scroll_offset_y
			}
		}
	}, l.get_drag_data = function(a) {
		var b = this.get_offset(a);
		return b.$player = this.$player, b.$helper = this.helper ? this.$helper : this.$player, b
	}, l.set_limits = function(a) {
		return a || (a = this.$container.width()), this.player_max_left = a - this.player_width + -this.options.offset_left, this.options.container_width = a, this
	}, l.scroll_in = function(b, d) {
		var o, e = g[b],
			h = 50,
			i = 30,
			k = "x" === b,
			l = k ? this.window_width : this.window_height,
			m = k ? a(c).width() : a(c).height(),
			n = k ? this.$player.width() : this.$player.height(),
			p = f["scroll" + j(e)](),
			q = p,
			r = q + l,
			s = r - h,
			t = q + h,
			u = q + d.pointer[e],
			v = m - l + n;
		return u >= s && (o = p + i, v > o && (f["scroll" + j(e)](o), this["scroll_offset_" + b] += i)), t >= u && (o = p - i, o > 0 && (f["scroll" + j(e)](o), this["scroll_offset_" + b] -= i)), this
	}, l.manage_scroll = function(a) {
		this.scroll_in("x", a), this.scroll_in("y", a)
	}, l.calculate_dimensions = function() {
		this.window_height = f.height(), this.window_width = f.width()
	}, l.drag_handler = function(b) {
		var d, e;
		return b.target.nodeName, this.disabled || 1 !== b.which && !h || this.ignore_drag(b) ? void 0 : (d = this, e = !0, this.$player = a(b.currentTarget), this.el_init_pos = this.get_actual_pos(this.$player), this.mouse_init_pos = this.get_mouse_pos(b), this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top, this.$body.on(i.move, function(a) {
			var b = d.get_mouse_pos(a),
				c = Math.abs(b.left - d.mouse_init_pos.left),
				f = Math.abs(b.top - d.mouse_init_pos.top);
			return c > d.options.distance || f > d.options.distance ? e ? (e = !1, d.on_dragstart.call(d, a), !1) : (d.is_dragging === !0 && d.on_dragmove.call(d, a), !1) : !1
		}), h ? void 0 : !1)
	}, l.on_dragstart = function(a) {
		if (a.preventDefault(), this.is_dragging) return this;
		this.drag_start = this.is_dragging = !0;
		var b = this.$container.offset();
		return this.baseX = Math.round(b.left), this.baseY = Math.round(b.top), this.initial_container_width = this.options.container_width || this.$container.width(), "clone" === this.options.helper ? (this.$helper = this.$player.clone().appendTo(this.$container).addClass("helper"), this.helper = !0) : this.helper = !1, this.scroll_offset_y = 0, this.scroll_offset_x = 0, this.el_init_offset = this.$player.offset(), this.player_width = this.$player.width(), this.player_height = this.$player.height(), this.set_limits(this.options.container_width), this.options.start && this.options.start.call(this.$player, a, this.get_drag_data(a)), !1
	}, l.on_dragmove = function(a) {
		var c, b = this.get_drag_data(a);
		return this.options.autoscroll && this.manage_scroll(b), this.options.move_element && (this.helper ? this.$helper : this.$player).css({
			position: "absolute",
			left: b.position.left,
			top: b.position.top
		}), c = this.last_position || b.position, b.prev_position = c, this.options.drag && this.options.drag.call(this.$player, a, b), this.last_position = b.position, !1
	}, l.on_dragstop = function(a) {
		var b = this.get_drag_data(a);
		return this.drag_start = !1, this.options.stop && this.options.stop.call(this.$player, a, b), this.helper && this.$helper.remove(), !1
	}, l.on_select_start = function(a) {
		return this.disabled || this.ignore_drag(a) ? void 0 : !1
	}, l.enable = function() {
		this.disabled = !1
	}, l.disable = function() {
		this.disabled = !0
	}, l.destroy = function() {
		this.disable(), this.$container.off(".gridster-draggable"), this.$body.off(".gridster-draggable"), a(b).off(".gridster-draggable"), a.removeData(this.$container, "drag")
	}, l.ignore_drag = function(b) {
		return this.options.handle ? !a(b.target).is(this.options.handle) : a(b.target).is(this.options.ignore_dragging.join(", "))
	}, a.fn.drag = function(a) {
		return new k(this, a)
	}
}(jQuery, window, document), function(a, b, c) {
	function f(b, c) {
		this.options = a.extend(!0, {}, e, c), this.$el = a(b), this.$wrapper = this.$el.parent(), this.$widgets = this.$el.children(this.options.widget_selector).addClass("gs-w"), this.widgets = [], this.$changed = a([]), this.wrapper_width = this.$wrapper.width(), this.min_widget_width = 2 * this.options.widget_margins[0] + this.options.widget_base_dimensions[0], this.min_widget_height = 2 * this.options.widget_margins[1] + this.options.widget_base_dimensions[1], this.generated_stylesheets = [], this.$style_tags = a([]), this.init()
	}
	var g, e = {
		namespace: "",
		widget_selector: "li",
		widget_margins: [10, 10],
		widget_base_dimensions: [400, 225],
		extra_rows: 0,
		extra_cols: 0,
		min_cols: 1,
		max_cols: 1 / 0,
		min_rows: 15,
		max_size_x: !1,
		autogrow_cols: !1,
		autogenerate_stylesheet: !0,
		avoid_overlapped_widgets: !0,
		serialize_params: function(a, b) {
			return {
				col: b.col,
				row: b.row,
				size_x: b.size_x,
				size_y: b.size_y
			}
		},
		collision: {},
		draggable: {
			items: ".gs-w",
			distance: 4
		},
		resize: {
			enabled: !1,
			axes: ["both"],
			handle_append_to: "",
			handle_class: "gs-resize-handle",
			max_size: [1 / 0, 1 / 0],
			min_size: [1, 1]
		}
	};
	f.generated_stylesheets = [], g = f.prototype, g.init = function() {
		this.options.resize.enabled && this.setup_resize(), this.generate_grid_and_stylesheet(), this.get_widgets_from_DOM(), this.set_dom_grid_height(), this.set_dom_grid_width(), this.$wrapper.addClass("ready"), this.draggable(), this.options.resize.enabled && this.resizable(), a(b).bind("resize.gridster", throttle(a.proxy(this.recalculate_faux_grid, this), 200))
	}, g.disable = function() {
		return this.$wrapper.find(".player-revert").removeClass("player-revert"), this.drag_api.disable(), this
	}, g.enable = function() {
		return this.drag_api.enable(), this
	}, g.disable_resize = function() {
		return this.$el.addClass("gs-resize-disabled"), this.resize_api.disable(), this
	}, g.enable_resize = function() {
		return this.$el.removeClass("gs-resize-disabled"), this.resize_api.enable(), this
	}, g.add_widget = function(b, c, d, e, f, g, h, i, j) {
		var k, l;
		return d || (d = 1), e || (e = 1), !i & !j ? k = this.next_position(d, e) : (k = {
			col: i,
			row: j
		}, this.empty_cells(i, j, d, e)), l = a(b).attr({
			id: c,
			"data-col": k.col,
			"data-row": k.row,
			"data-sizex": d,
			"data-sizey": e
		}).addClass("gs-w").html(f).appendTo(this.$el).hide(), this.$widgets = this.$widgets.add(l), this.register_widget(l), this.add_faux_rows(k.size_y), g && this.set_widget_max_size(l, g), h && this.set_widget_min_size(l, h), this.set_dom_grid_width(), this.set_dom_grid_height(), this.drag_api.set_limits(this.cols * this.min_widget_width), l.fadeIn()
	}, g.set_widget_min_size = function(a, b) {
		if (a = "number" == typeof a ? this.$widgets.eq(a) : a, !a.length) return this;
		var c = a.data("coords").grid;
		return c.min_size_x = b[0], c.min_size_y = b[1], this
	}, g.set_widget_max_size = function(a, b) {
		if (a = "number" == typeof a ? this.$widgets.eq(a) : a, !a.length) return this;
		var c = a.data("coords").grid;
		return c.max_size_x = b[0], c.max_size_y = b[1], this
	}, g.add_resize_handle = function(b) {
		var c = this.options.resize.handle_append_to;
		return a(this.resize_handle_tpl).appendTo(c ? a(c, b) : b), this
	}, g.resize_widget = function(a, b, c, d) {
		var k, l, e = a.coords().grid,
			f = e.col,
			g = this.options.max_cols,
			h = e.size_y,
			i = e.col,
			j = i;
		return b || (b = e.size_x), c || (c = e.size_y), 1 / 0 !== g && (b = Math.min(b, g - f + 1)), c > h && this.add_faux_rows(Math.max(c - h, 0)), k = f + b - 1, k > this.cols && this.add_faux_cols(k - this.cols), l = {
			col: j,
			row: e.row,
			size_x: b,
			size_y: c
		}, this.mutate_widget_in_gridmap(a, e, l), this.set_dom_grid_height(), this.set_dom_grid_width(), d && d.call(this, l.size_x, l.size_y), a
	}, g.mutate_widget_in_gridmap = function(b, c, d) {
		var f, g, h, i, j, k, l, m, n, o, p;
		return c.size_x, f = c.size_y, g = this.get_cells_occupied(c), h = this.get_cells_occupied(d), i = [], a.each(g.cols, function(b, c) {
			-1 === a.inArray(c, h.cols) && i.push(c)
		}), j = [], a.each(h.cols, function(b, c) {
			-1 === a.inArray(c, g.cols) && j.push(c)
		}), k = [], a.each(g.rows, function(b, c) {
			-1 === a.inArray(c, h.rows) && k.push(c)
		}), l = [], a.each(h.rows, function(b, c) {
			-1 === a.inArray(c, g.rows) && l.push(c)
		}), this.remove_from_gridmap(c), j.length && (m = [d.col, d.row, d.size_x, Math.min(f, d.size_y), b], this.empty_cells.apply(this, m)), l.length && (n = [d.col, d.row, d.size_x, d.size_y, b], this.empty_cells.apply(this, n)), c.col = d.col, c.row = d.row, c.size_x = d.size_x, c.size_y = d.size_y, this.add_to_gridmap(d, b), b.removeClass("player-revert"), b.data("coords").update({
			width: d.size_x * this.options.widget_base_dimensions[0] + 2 * (d.size_x - 1) * this.options.widget_margins[0],
			height: d.size_y * this.options.widget_base_dimensions[1] + 2 * (d.size_y - 1) * this.options.widget_margins[1]
		}), b.attr({
			"data-col": d.col,
			"data-row": d.row,
			"data-sizex": d.size_x,
			"data-sizey": d.size_y
		}), i.length && (o = [i[0], d.row, i.length, Math.min(f, d.size_y), b], this.remove_empty_cells.apply(this, o)), k.length && (p = [d.col, d.row, d.size_x, d.size_y, b], this.remove_empty_cells.apply(this, p)), this.move_widget_up(b), this
	}, g.empty_cells = function(b, c, d, e, f) {
		var g = this.widgets_below({
			col: b,
			row: c - e,
			size_x: d,
			size_y: e
		});
		return g.not(f).each(a.proxy(function(b, d) {
			var g, f = a(d).coords().grid;
			f.row <= c + e - 1 && (g = c + e - f.row, this.move_widget_down(a(d), g))
		}, this)), this.set_dom_grid_height(), this
	}, g.remove_empty_cells = function(b, c, d, e, f) {
		var g = this.widgets_below({
			col: b,
			row: c,
			size_x: d,
			size_y: e
		});
		return g.not(f).each(a.proxy(function(b, c) {
			this.move_widget_up(a(c), e)
		}, this)), this.set_dom_grid_height(), this
	}, g.next_position = function(a, b) {
		var c, d, e, f, g, h, i;
		for (a || (a = 1), b || (b = 1), c = this.gridmap, d = c.length, e = [], g = 1; d > g; g++) for (f = c[g].length, h = 1; f >= h; h++) i = this.can_move_to({
			size_x: a,
			size_y: b
		}, g, h), i && e.push({
			col: g,
			row: h,
			size_y: b,
			size_x: a
		});
		return e.length ? this.sort_by_row_and_col_asc(e)[0] : !1
	}, g.remove_widget = function(b, c, d) {
		var g, e = b instanceof a ? b : a(b),
			f = e.coords().grid;
		return a.isFunction(c) && (d = c, c = !1), this.cells_occupied_by_placeholder = {}, this.$widgets = this.$widgets.not(e), g = this.widgets_below(e), this.remove_from_gridmap(f), e.fadeOut(a.proxy(function() {
			e.remove(), c || g.each(a.proxy(function(b, c) {
				this.move_widget_up(a(c), f.size_y)
			}, this)), this.set_dom_grid_height(), d && d.call(this, b)
		}, this)), this
	}, g.remove_all_widgets = function(b) {
		return this.$widgets.each(a.proxy(function(a, c) {
			this.remove_widget(c, !0, b)
		}, this)), this
	}, g.serialize = function(b) {
		b || (b = this.$widgets);
		var c = [];
		return b.each(a.proxy(function(b, d) {
			c.push(this.options.serialize_params(a(d), a(d).coords().grid))
		}, this)), c
	}, g.serialize_changed = function() {
		return this.serialize(this.$changed)
	}, g.register_widget = function(b) {
		var c = {
			id: b.attr("id") || !1,
			col: parseInt(b.attr("data-col"), 10),
			row: parseInt(b.attr("data-row"), 10),
			size_x: parseInt(b.attr("data-sizex"), 10),
			size_y: parseInt(b.attr("data-sizey"), 10),
			max_size_x: parseInt(b.attr("data-max-sizex"), 10) || 0,
			max_size_y: parseInt(b.attr("data-max-sizey"), 10) || 0,
			min_size_x: parseInt(b.attr("data-min-sizex"), 10) || 0,
			min_size_y: parseInt(b.attr("data-min-sizey"), 10) || 0,
			Content: b.html() || !1,
			el: b
		};
		return this.options.avoid_overlapped_widgets && !this.can_move_to({
			size_x: c.size_x,
			size_y: c.size_y
		}, c.col, c.row) && (a.extend(c, this.next_position(c.size_x, c.size_y)), b.attr({
			"data-col": c.col,
			"data-row": c.row,
			"data-sizex": c.size_x,
			"data-sizey": c.size_y
		})), b.data("coords", b.coords()), b.data("coords").grid = c, this.add_to_gridmap(c, b), this.options.resize.enabled && this.add_resize_handle(b), this
	}, g.update_widget_position = function(a, b) {
		return this.for_each_cell_occupied(a, function(a, c) {
			return this.gridmap[a] ? (this.gridmap[a][c] = b, void 0) : this
		}), this
	}, g.remove_from_gridmap = function(a) {
		return this.update_widget_position(a, !1)
	}, g.add_to_gridmap = function(b, c) {
		if (this.update_widget_position(b, c || b.el), b.el) {
			var d = this.widgets_below(b.el);
			d.each(a.proxy(function(b, c) {
				this.move_widget_up(a(c))
			}, this))
		}
	}, g.draggable = function() {
		var b = this,
			c = a.extend(!0, {}, this.options.draggable, {
				offset_left: this.options.widget_margins[0],
				offset_top: this.options.widget_margins[1],
				container_width: this.cols * this.min_widget_width,
				limit: !0,
				ignore_dragging: ["INPUT", "TEXTAREA", "SELECT", "BUTTON", "." + this.options.resize.handle_class],
				start: function(c, d) {
					b.$widgets.filter(".player-revert").removeClass("player-revert"), b.$player = a(this), b.$helper = a(d.$helper), b.helper = !b.$helper.is(b.$player), b.on_start_drag.call(b, c, d), b.$el.trigger("gridster:dragstart")
				},
				stop: function(a, c) {
					b.on_stop_drag.call(b, a, c), b.$el.trigger("gridster:dragstop")
				},
				drag: throttle(function(a, c) {
					b.on_drag.call(b, a, c), b.$el.trigger("gridster:drag")
				}, 60)
			});
		return this.drag_api = this.$el.drag(c), this
	}, g.resizable = function() {
		return this.resize_api = this.$el.drag({
			items: "." + this.options.resize.handle_class,
			offset_left: this.options.widget_margins[0],
			container_width: this.container_width,
			move_element: !1,
			resize: !0,
			limit: this.options.autogrow_cols ? !1 : !0,
			start: a.proxy(this.on_start_resize, this),
			stop: a.proxy(function(b, c) {
				delay(a.proxy(function() {
					this.on_stop_resize(b, c)
				}, this), 120)
			}, this),
			drag: throttle(a.proxy(this.on_resize, this), 60)
		}), this
	}, g.setup_resize = function() {
		var b, c;
		return this.resize_handle_class = this.options.resize.handle_class, b = this.options.resize.axes, c = '<span class="' + this.resize_handle_class + " " + this.resize_handle_class + '-{type}" />', this.resize_handle_tpl = a.map(b, function(a) {
			return c.replace("{type}", a)
		}).join(""), this
	}, g.on_start_drag = function(b, c) {
		var d, e, f, g;
		this.$helper.add(this.$player).add(this.$wrapper).addClass("dragging"), this.highest_col = this.get_highest_occupied_cell().col, this.$player.addClass("player"), this.player_grid_data = this.$player.coords().grid, this.placeholder_grid_data = a.extend({}, this.player_grid_data), this.set_dom_grid_height(this.$el.height() + this.player_grid_data.size_y * this.min_widget_height), this.set_dom_grid_width(this.cols), d = this.player_grid_data.size_x, e = this.cols - this.highest_col, this.options.autogrow_cols && d >= e && this.add_faux_cols(Math.min(d - e, 1)), f = this.faux_grid, g = this.$player.data("coords").coords, this.cells_occupied_by_player = this.get_cells_occupied(this.player_grid_data), this.cells_occupied_by_placeholder = this.get_cells_occupied(this.placeholder_grid_data), this.last_cols = [], this.last_rows = [], this.collision_api = this.$helper.collision(f, this.options.collision), this.$preview_holder = a("<" + this.$player.get(0).tagName + " />", {
			"class": "preview-holder",
			"data-row": this.$player.attr("data-row"),
			"data-col": 2,
			css: {
				width: g.width,
				height: g.height
			}
		}).appendTo(this.$el), this.options.draggable.start && this.options.draggable.start.call(this, b, c)
	}, g.on_drag = function(a, b) {
		var c, d;
		return null === this.$player ? !1 : (c = {
			left: b.position.left + this.baseX,
			top: b.position.top + this.baseY
		}, this.options.autogrow_cols && (d = this.placeholder_grid_data.col + this.placeholder_grid_data.size_x - 1, d >= this.cols - 1 && this.options.max_cols >= this.cols + 1 && (this.add_faux_cols(1), this.set_dom_grid_width(this.cols + 1), this.drag_api.set_limits(this.container_width)), this.collision_api.set_colliders(this.faux_grid)), this.colliders_data = this.collision_api.get_closest_colliders(c), this.on_overlapped_column_change(this.on_start_overlapping_column, this.on_stop_overlapping_column), this.on_overlapped_row_change(this.on_start_overlapping_row, this.on_stop_overlapping_row), this.helper && this.$player && this.$player.css({
			left: b.position.left,
			top: b.position.top
		}), this.options.draggable.drag && this.options.draggable.drag.call(this, a, b), void 0)
	}, g.on_stop_drag = function(a, b) {
		this.$helper.add(this.$player).add(this.$wrapper).removeClass("dragging"), b.position.left = b.position.left + this.baseX, b.position.top = b.position.top + this.baseY, this.colliders_data = this.collision_api.get_closest_colliders(b.position), this.on_overlapped_column_change(this.on_start_overlapping_column, this.on_stop_overlapping_column), this.on_overlapped_row_change(this.on_start_overlapping_row, this.on_stop_overlapping_row), this.$player.addClass("player-revert").removeClass("player").attr({
			"data-col": this.placeholder_grid_data.col,
			"data-row": this.placeholder_grid_data.row
		}).css({
			left: "",
			top: ""
		}), this.$changed = this.$changed.add(this.$player), this.cells_occupied_by_player = this.get_cells_occupied(this.placeholder_grid_data), this.set_cells_player_occupies(this.placeholder_grid_data.col, this.placeholder_grid_data.row), this.$player.coords().grid.row = this.placeholder_grid_data.row, this.$player.coords().grid.col = this.placeholder_grid_data.col, this.options.draggable.stop && this.options.draggable.stop.call(this, a, b), this.$preview_holder.remove(), this.$player = null, this.$helper = null, this.placeholder_grid_data = {}, this.player_grid_data = {}, this.cells_occupied_by_placeholder = {}, this.cells_occupied_by_player = {}, this.set_dom_grid_height(), this.set_dom_grid_width(), this.options.autogrow_cols && this.drag_api.set_limits(this.cols * this.min_widget_width)
	}, g.on_start_resize = function(b, c) {
		this.$resized_widget = c.$player.closest(".gs-w"), this.resize_coords = this.$resized_widget.coords(), this.resize_wgd = this.resize_coords.grid, this.resize_initial_width = this.resize_coords.coords.width, this.resize_initial_height = this.resize_coords.coords.height, this.resize_initial_sizex = this.resize_coords.grid.size_x, this.resize_initial_sizey = this.resize_coords.grid.size_y, this.resize_initial_col = this.resize_coords.grid.col, this.resize_last_sizex = this.resize_initial_sizex, this.resize_last_sizey = this.resize_initial_sizey, this.resize_max_size_x = Math.min(this.resize_wgd.max_size_x || this.options.resize.max_size[0], this.options.max_cols - this.resize_initial_col + 1), this.resize_max_size_y = this.resize_wgd.max_size_y || this.options.resize.max_size[1], this.resize_min_size_x = this.resize_wgd.min_size_x || this.options.resize.min_size[0] || 1, this.resize_min_size_y = this.resize_wgd.min_size_y || this.options.resize.min_size[1] || 1, this.resize_initial_last_col = this.get_highest_occupied_cell().col, this.set_dom_grid_width(this.cols), this.resize_dir = {
			right: c.$player.is("." + this.resize_handle_class + "-x"),
			bottom: c.$player.is("." + this.resize_handle_class + "-y")
		}, this.$resized_widget.css({
			"min-width": this.options.widget_base_dimensions[0],
			"min-height": this.options.widget_base_dimensions[1]
		});
		var d = this.$resized_widget.get(0).tagName;
		this.$resize_preview_holder = a("<" + d + " />", {
			"class": "preview-holder resize-preview-holder",
			"data-row": this.$resized_widget.attr("data-row"),
			"data-col": this.$resized_widget.attr("data-col"),
			css: {
				width: this.resize_initial_width,
				height: this.resize_initial_height
			}
		}).appendTo(this.$el), this.$resized_widget.addClass("resizing"), this.options.resize.start && this.options.resize.start.call(this, b, c, this.$resized_widget), this.$el.trigger("gridster:resizestart")
	}, g.on_stop_resize = function(b, c) {
		this.$resized_widget.removeClass("resizing").css({
			width: "",
			height: ""
		}), delay(a.proxy(function() {
			this.$resize_preview_holder.remove().css({
				"min-width": "",
				"min-height": ""
			}), this.options.resize.stop && this.options.resize.stop.call(this, b, c, this.$resized_widget), this.$el.trigger("gridster:resizestop")
		}, this), 300), this.set_dom_grid_width(), this.options.autogrow_cols && this.drag_api.set_limits(this.cols * this.min_widget_width)
	}, g.on_resize = function(a, b) {
		var n, w, x, c = b.pointer.diff_left,
			d = b.pointer.diff_top,
			e = this.options.widget_base_dimensions[0],
			f = this.options.widget_base_dimensions[1],
			g = this.options.widget_margins[0],
			h = this.options.widget_margins[1],
			i = this.resize_max_size_x,
			j = this.resize_min_size_x,
			k = this.resize_max_size_y,
			l = this.resize_min_size_y,
			m = this.options.autogrow_cols,
			o = 1 / 0,
			p = 1 / 0,
			q = Math.ceil(c / (e + 2 * g) - .2),
			r = Math.ceil(d / (f + 2 * h) - .2),
			s = Math.max(1, this.resize_initial_sizex + q),
			t = Math.max(1, this.resize_initial_sizey + r),
			u = this.container_width / this.min_widget_width - this.resize_initial_col + 1,
			v = u * this.min_widget_width - 2 * g;
		s = Math.max(Math.min(s, i), j), s = Math.min(u, s), n = i * e + 2 * (s - 1) * g, o = Math.min(n, v), min_width = j * e + 2 * (s - 1) * g, t = Math.max(Math.min(t, k), l), p = k * f + 2 * (t - 1) * h, min_height = l * f + 2 * (t - 1) * h, this.resize_dir.right ? t = this.resize_initial_sizey : this.resize_dir.bottom && (s = this.resize_initial_sizex), m && (w = this.resize_initial_col + s - 1, m && this.resize_initial_last_col <= w && (this.set_dom_grid_width(Math.max(w + 1, this.cols)), this.cols < w && this.add_faux_cols(w - this.cols))), x = {}, !this.resize_dir.bottom && (x.width = Math.max(Math.min(this.resize_initial_width + c, o), min_width)), !this.resize_dir.right && (x.height = Math.max(Math.min(this.resize_initial_height + d, p), min_height)), this.$resized_widget.css(x), (s !== this.resize_last_sizex || t !== this.resize_last_sizey) && (this.resize_widget(this.$resized_widget, s, t), this.set_dom_grid_width(this.cols), this.$resize_preview_holder.css({
			width: "",
			height: ""
		}).attr({
			"data-row": this.$resized_widget.attr("data-row"),
			"data-sizex": s,
			"data-sizey": t
		})), this.options.resize.resize && this.options.resize.resize.call(this, a, b, this.$resized_widget), this.$el.trigger("gridster:resize"), this.resize_last_sizex = s, this.resize_last_sizey = t
	}, g.on_overlapped_column_change = function(b, c) {
		var d, e, f, g;
		if (!this.colliders_data.length) return this;
		for (d = this.get_targeted_columns(this.colliders_data[0].el.data.col), e = this.last_cols.length, f = d.length, g = 0; f > g; g++) - 1 === a.inArray(d[g], this.last_cols) && (b || a.noop).call(this, d[g]);
		for (g = 0; e > g; g++) - 1 === a.inArray(this.last_cols[g], d) && (c || a.noop).call(this, this.last_cols[g]);
		return this.last_cols = d, this
	}, g.on_overlapped_row_change = function(b, c) {
		var d, e, f, g;
		if (!this.colliders_data.length) return this;
		for (d = this.get_targeted_rows(this.colliders_data[0].el.data.row), e = this.last_rows.length, f = d.length, g = 0; f > g; g++) - 1 === a.inArray(d[g], this.last_rows) && (b || a.noop).call(this, d[g]);
		for (g = 0; e > g; g++) - 1 === a.inArray(this.last_rows[g], d) && (c || a.noop).call(this, this.last_rows[g]);
		this.last_rows = d
	}, g.set_player = function(a, b, c) {
		var e, f, g, h, i, d = this;
		return c || this.empty_cells_player_occupies(), e = c ? {
			col: a
		} : d.colliders_data[0].el.data, f = e.col, g = b || e.row, this.player_grid_data = {
			col: f,
			row: g,
			size_y: this.player_grid_data.size_y,
			size_x: this.player_grid_data.size_x
		}, this.cells_occupied_by_player = this.get_cells_occupied(this.player_grid_data), h = this.get_widgets_overlapped(this.player_grid_data), i = this.widgets_constraints(h), this.manage_movements(i.can_go_up, f, g), this.manage_movements(i.can_not_go_up, f, g), h.length || this.set_placeholder(f, g), {
			col: f,
			row: g
		}
	}, g.widgets_constraints = function(b) {
		var d, c = a([]),
			e = [],
			f = [];
		return b.each(a.proxy(function(b, d) {
			var g = a(d),
				h = g.coords().grid;
			this.can_go_widget_up(h) ? (c = c.add(g), e.push(h)) : f.push(h)
		}, this)), d = b.not(c), {
			can_go_up: this.sort_by_row_asc(e),
			can_not_go_up: this.sort_by_row_desc(f)
		}
	}, g.sort_by_row_asc = function(b) {
		return b = b.sort(function(b, c) {
			return b.row || (b = a(b).coords().grid, c = a(c).coords().grid), b.row > c.row ? 1 : -1
		})
	}, g.sort_by_row_and_col_asc = function(a) {
		return a = a.sort(function(a, b) {
			return a.row > b.row || a.row === b.row && a.col > b.col ? 1 : -1
		})
	}, g.sort_by_col_asc = function(a) {
		return a = a.sort(function(a, b) {
			return a.col > b.col ? 1 : -1
		})
	}, g.sort_by_row_desc = function(a) {
		return a = a.sort(function(a, b) {
			return a.row + a.size_y < b.row + b.size_y ? 1 : -1
		})
	}, g.manage_movements = function(b, c, d) {
		return a.each(b, a.proxy(function(a, b) {
			var h, i, e = b,
				f = e.el,
				g = this.can_go_widget_up(e);
			g ? (this.move_widget_to(f, g), this.set_placeholder(c, g + e.size_y)) : (h = this.can_go_player_up(this.player_grid_data), h || (i = d + this.player_grid_data.size_y - e.row, this.move_widget_down(f, i), this.set_placeholder(c, d)))
		}, this)), this
	}, g.is_player = function(a, b) {
		if (b && !this.gridmap[a]) return !1;
		var c = b ? this.gridmap[a][b] : a;
		return c && (c.is(this.$player) || c.is(this.$helper))
	}, g.is_player_in = function(b, c) {
		var d = this.cells_occupied_by_player || {};
		return a.inArray(b, d.cols) >= 0 && a.inArray(c, d.rows) >= 0
	}, g.is_placeholder_in = function(b, c) {
		var d = this.cells_occupied_by_placeholder || {};
		return this.is_placeholder_in_col(b) && a.inArray(c, d.rows) >= 0
	}, g.is_placeholder_in_col = function(b) {
		var c = this.cells_occupied_by_placeholder || [];
		return a.inArray(b, c.cols) >= 0
	}, g.is_empty = function(a, b) {
		return "undefined" != typeof this.gridmap[a] ? "undefined" != typeof this.gridmap[a][b] && this.gridmap[a][b] === !1 ? !0 : !1 : !0
	}, g.is_occupied = function(a, b) {
		return this.gridmap[a] ? this.gridmap[a][b] ? !0 : !1 : !1
	}, g.is_widget = function(a, b) {
		var c = this.gridmap[a];
		return c ? (c = c[b], c ? c : !1) : !1
	}, g.is_widget_under_player = function(a, b) {
		return this.is_widget(a, b) ? this.is_player_in(a, b) : !1
	}, g.get_widgets_under_player = function(b) {
		b || (b = this.cells_occupied_by_player || {
			cols: [],
			rows: []
		});
		var c = a([]);
		return a.each(b.cols, a.proxy(function(d, e) {
			a.each(b.rows, a.proxy(function(a, b) {
				this.is_widget(e, b) && (c = c.add(this.gridmap[e][b]))
			}, this))
		}, this)), c
	}, g.set_placeholder = function(b, c) {
		var g, h, i, d = a.extend({}, this.placeholder_grid_data),
			e = this.widgets_below({
				col: d.col,
				row: d.row,
				size_y: d.size_y,
				size_x: d.size_x
			}),
			f = b + d.size_x - 1;
		f > this.cols && (b -= f - b), g = this.placeholder_grid_data.row < c, h = this.placeholder_grid_data.col !== b, this.placeholder_grid_data.col = b, this.placeholder_grid_data.row = c, this.cells_occupied_by_placeholder = this.get_cells_occupied(this.placeholder_grid_data), this.$preview_holder.attr({
			"data-row": c,
			"data-col": b
		}), (g || h) && e.each(a.proxy(function(c, e) {
			this.move_widget_up(a(e), this.placeholder_grid_data.col - b + d.size_y)
		}, this)), i = this.get_widgets_under_player(this.cells_occupied_by_placeholder), i.length && i.each(a.proxy(function(b, e) {
			var f = a(e);
			this.move_widget_down(f, c + d.size_y - f.data("coords").grid.row)
		}, this))
	}, g.can_go_player_up = function(a) {
		var b = a.row + a.size_y - 1,
			c = !0,
			d = [],
			e = 1e4,
			f = this.get_widgets_under_player();
		return this.for_each_column_occupied(a, function(a) {
			var g = this.gridmap[a],
				h = b + 1;
			for (d[a] = []; --h > 0 && (this.is_empty(a, h) || this.is_player(a, h) || this.is_widget(a, h) && g[h].is(f));) d[a].push(h), e = e > h ? h : e;
			return 0 === d[a].length ? (c = !1, !0) : (d[a].sort(function(a, b) {
				return a - b
			}), void 0)
		}), c ? this.get_valid_rows(a, d, e) : !1
	}, g.can_go_widget_up = function(a) {
		var b = a.row + a.size_y - 1,
			c = !0,
			d = [],
			e = 1e4;
		return this.for_each_column_occupied(a, function(f) {
			var h, g = this.gridmap[f];
			for (d[f] = [], h = b + 1; --h > 0 && (!this.is_widget(f, h) || this.is_player_in(f, h) || g[h].is(a.el));) this.is_player(f, h) || this.is_placeholder_in(f, h) || this.is_player_in(f, h) || d[f].push(h), e > h && (e = h);
			return 0 === d[f].length ? (c = !1, !0) : (d[f].sort(function(a, b) {
				return a - b
			}), void 0)
		}), c ? this.get_valid_rows(a, d, e) : !1
	}, g.get_valid_rows = function(b, c, d) {
		for (var j, k, e = b.row, f = b.row + b.size_y - 1, g = b.size_y, h = d - 1, i = []; ++h <= f && (j = !0, a.each(c, function(b, c) {
			a.isArray(c) && -1 === a.inArray(h, c) && (j = !1)
		}), j !== !0 || (i.push(h), i.length !== g)););
		return k = !1, 1 === g ? i[0] !== e && (k = i[0] || !1) : i[0] !== e && (k = this.get_consecutive_numbers_index(i, g)), k
	}, g.get_consecutive_numbers_index = function(a, b) {
		var g, c = a.length,
			d = [],
			e = !0,
			f = -1;
		for (g = 0; c > g; g++) {
			if (e || a[g] === f + 1) {
				if (d.push(g), d.length === b) break;
				e = !1
			} else d = [], e = !0;
			f = a[g]
		}
		return d.length >= b ? a[d[0]] : !1
	}, g.get_widgets_overlapped = function() {
		var c = a([]),
			d = [],
			e = this.cells_occupied_by_player.rows.slice(0);
		return e.reverse(), a.each(this.cells_occupied_by_player.cols, a.proxy(function(b, f) {
			a.each(e, a.proxy(function(b, e) {
				if (!this.gridmap[f]) return !0;
				var g = this.gridmap[f][e];
				this.is_occupied(f, e) && !this.is_player(g) && -1 === a.inArray(g, d) && (c = c.add(g), d.push(g))
			}, this))
		}, this)), c
	}, g.on_start_overlapping_column = function(a) {
		this.set_player(a, !1)
	}, g.on_start_overlapping_row = function(a) {
		this.set_player(!1, a)
	}, g.on_stop_overlapping_column = function(a) {
		this.set_player(a, !1);
		var b = this;
		this.for_each_widget_below(a, this.cells_occupied_by_player.rows[0], function() {
			b.move_widget_up(this, b.player_grid_data.size_y)
		})
	}, g.on_stop_overlapping_row = function(a) {
		var b, c, d, e;
		for (this.set_player(!1, a), b = this, c = this.cells_occupied_by_player.cols, d = 0, e = c.length; e > d; d++) this.for_each_widget_below(c[d], a, function() {
			b.move_widget_up(this, b.player_grid_data.size_y)
		})
	}, g.move_widget_to = function(b, c) {
		var g, h, d = this,
			e = b.coords().grid;
		return c - e.row, g = this.widgets_below(b), h = this.can_move_to(e, e.col, c, b), h === !1 ? !1 : (this.remove_from_gridmap(e), e.row = c, this.add_to_gridmap(e), b.attr("data-row", c), this.$changed = this.$changed.add(b), g.each(function(b, c) {
			var e = a(c),
				f = e.coords().grid,
				g = d.can_go_widget_up(f);
			g && g !== f.row && d.move_widget_to(e, g)
		}), this)
	}, g.move_widget_up = function(b, c) {
		var d = b.coords().grid,
			e = d.row,
			f = [];
		return c || (c = 1), this.can_go_up(b) ? (this.for_each_column_occupied(d, function(d) {
			var g, h, i;
			if (-1 === a.inArray(b, f)) {
				if (g = b.coords().grid, h = e - c, h = this.can_go_up_to_row(g, d, h), !h) return !0;
				i = this.widgets_below(b), this.remove_from_gridmap(g), g.row = h, this.add_to_gridmap(g), b.attr("data-row", g.row), this.$changed = this.$changed.add(b), f.push(b), i.each(a.proxy(function(b, d) {
					this.move_widget_up(a(d), c)
				}, this))
			}
		}), void 0) : !1
	}, g.move_widget_down = function(b, c) {
		var d, e, f, g, h, i, j;
		return 0 >= c ? !1 : (d = b.coords().grid, e = d.row, f = [], g = c, b ? (-1 === a.inArray(b, f) && (h = b.coords().grid, i = e + c, j = this.widgets_below(b), this.remove_from_gridmap(h), j.each(a.proxy(function(b, c) {
			var d = a(c),
				e = d.coords().grid,
				f = this.displacement_diff(e, h, g);
			f > 0 && this.move_widget_down(d, f)
		}, this)), h.row = i, this.update_widget_position(h, b), b.attr("data-row", h.row), this.$changed = this.$changed.add(b), f.push(b)), void 0) : !1)
	}, g.can_go_up_to_row = function(b, c, d) {
		var i, j, k, l, e = this.gridmap,
			f = !0,
			g = [],
			h = b.row;
		if (this.for_each_column_occupied(b, function(a) {
			for (e[a], g[a] = [], i = h; i-- && this.is_empty(a, i) && !this.is_placeholder_in(a, i);) g[a].push(i);
			return g[a].length ? void 0 : (f = !1, !0)
		}), !f) return !1;
		for (i = d, i = 1; h > i; i++) {
			for (j = !0, k = 0, l = g.length; l > k; k++) g[k] && -1 === a.inArray(i, g[k]) && (j = !1);
			if (j === !0) {
				f = i;
				break
			}
		}
		return f
	}, g.displacement_diff = function(a, b, c) {
		var g, d = a.row,
			e = [],
			f = b.row + b.size_y;
		return this.for_each_column_occupied(a, function(a) {
			var c, b = 0;
			for (c = f; d > c; c++) this.is_empty(a, c) && (b += 1);
			e.push(b)
		}), g = Math.max.apply(Math, e), c -= g, c > 0 ? c : 0
	}, g.widgets_below = function(b) {
		var f, g, c = a.isPlainObject(b) ? b : b.coords().grid,
			d = this;
		return this.gridmap, f = c.row + c.size_y - 1, g = a([]), this.for_each_column_occupied(c, function(b) {
			d.for_each_widget_below(b, f, function() {
				return d.is_player(this) || -1 !== a.inArray(this, g) ? void 0 : (g = g.add(this), !0)
			})
		}), this.sort_by_row_asc(g)
	}, g.set_cells_player_occupies = function(a, b) {
		return this.remove_from_gridmap(this.placeholder_grid_data), this.placeholder_grid_data.col = a, this.placeholder_grid_data.row = b, this.add_to_gridmap(this.placeholder_grid_data, this.$player), this
	}, g.empty_cells_player_occupies = function() {
		return this.remove_from_gridmap(this.placeholder_grid_data), this
	}, g.can_go_up = function(a) {
		var g, b = a.coords().grid,
			c = b.row,
			d = c - 1;
		return this.gridmap, g = !0, 1 === c ? !1 : (this.for_each_column_occupied(b, function(a) {
			return this.is_widget(a, d), this.is_occupied(a, d) || this.is_player(a, d) || this.is_placeholder_in(a, d) || this.is_player_in(a, d) ? (g = !1, !0) : void 0
		}), g)
	}, g.can_move_to = function(a, b, c, d) {
		var f, g, h, i;
		return this.gridmap, f = a.el, g = {
			size_y: a.size_y,
			size_x: a.size_x,
			col: b,
			row: c
		}, h = !0, i = b + a.size_x - 1, i > this.cols ? !1 : d && d < c + a.size_y - 1 ? !1 : (this.for_each_cell_occupied(g, function(b, c) {
			var d = this.is_widget(b, c);
			!d || a.el && !d.is(f) || (h = !1)
		}), h)
	}, g.get_targeted_columns = function(a) {
		var d, b = (a || this.player_grid_data.col) + (this.player_grid_data.size_x - 1),
			c = [];
		for (d = a; b >= d; d++) c.push(d);
		return c
	}, g.get_targeted_rows = function(a) {
		var d, b = (a || this.player_grid_data.row) + (this.player_grid_data.size_y - 1),
			c = [];
		for (d = a; b >= d; d++) c.push(d);
		return c
	}, g.get_cells_occupied = function(b) {
		var d, e, f, c = {
			cols: [],
			rows: []
		};
		for (arguments[1] instanceof a && (b = arguments[1].coords().grid), d = 0; d < b.size_x; d++) e = b.col + d, c.cols.push(e);
		for (d = 0; d < b.size_y; d++) f = b.row + d, c.rows.push(f);
		return c
	}, g.for_each_cell_occupied = function(a, b) {
		return this.for_each_column_occupied(a, function(c) {
			this.for_each_row_occupied(a, function(a) {
				b.call(this, c, a)
			})
		}), this
	}, g.for_each_column_occupied = function(a, b) {
		var c, d;
		for (c = 0; c < a.size_x; c++) d = a.col + c, b.call(this, d, a)
	}, g.for_each_row_occupied = function(a, b) {
		var c, d;
		for (c = 0; c < a.size_y; c++) d = a.row + c, b.call(this, d, a)
	}, g._traversing_widgets = function(b, c, d, e, f) {
		var h, i, j, k, l, m, n, g = this.gridmap;
		g[d] && (j = b + "/" + c, arguments[2] instanceof a && (k = arguments[2].coords().grid, d = k.col, e = k.row, f = arguments[3]), l = [], m = e, n = {
			"for_each/above": function() {
				for (; m-- && !(m > 0 && this.is_widget(d, m) && -1 === a.inArray(g[d][m], l) && (h = f.call(g[d][m], d, m), l.push(g[d][m]), h)););
			},
			"for_each/below": function() {
				for (m = e + 1, i = g[d].length; i > m && (!this.is_widget(d, m) || -1 !== a.inArray(g[d][m], l) || (h = f.call(g[d][m], d, m), l.push(g[d][m]), !h)); m++);
			}
		}, n[j] && n[j].call(this))
	}, g.for_each_widget_above = function(a, b, c) {
		return this._traversing_widgets("for_each", "above", a, b, c), this
	}, g.for_each_widget_below = function(a, b, c) {
		return this._traversing_widgets("for_each", "below", a, b, c), this
	}, g.get_highest_occupied_cell = function() {
		var a, g, b = this.gridmap,
			c = b[1].length,
			d = [],
			e = [];
		for (g = b.length - 1; g >= 1; g--) for (a = c - 1; a >= 1; a--) if (this.is_widget(g, a)) {
			d.push(a), e.push(g);
			break
		}
		return {
			col: Math.max.apply(Math, e),
			row: Math.max.apply(Math, d)
		}
	}, g.get_widgets_from = function(b, c) {
		this.gridmap;
		var e = a();
		return b && (e = e.add(this.$widgets.filter(function() {
			var c = a(this).attr("data-col");
			return c === b || c > b
		}))), c && (e = e.add(this.$widgets.filter(function() {
			var b = a(this).attr("data-row");
			return b === c || b > c
		}))), e
	}, g.set_dom_grid_height = function(a) {
		if ("undefined" == typeof a) {
			var b = this.get_highest_occupied_cell().row;
			a = b * this.min_widget_height
		}
		return this.container_height = a, this.$el.css("height", this.container_height), this
	}, g.set_dom_grid_width = function(a) {
		"undefined" == typeof a && (a = this.get_highest_occupied_cell().col);
		var b = this.options.autogrow_cols ? this.options.max_cols : this.cols;
		return a = Math.min(b, Math.max(a, this.options.min_cols)), this.container_width = a * this.min_widget_width, this.$el.css("width", this.container_width), this
	}, g.generate_stylesheet = function(b) {
		var h, j, k, l, c = "",
			d = this.options.max_size_x || this.cols;
		if (b || (b = {}), b.cols || (b.cols = this.cols), b.rows || (b.rows = this.rows), b.namespace || (b.namespace = this.options.namespace), b.widget_base_dimensions || (b.widget_base_dimensions = this.options.widget_base_dimensions), b.widget_margins || (b.widget_margins = this.options.widget_margins), b.min_widget_width = 2 * b.widget_margins[0] + b.widget_base_dimensions[0], b.min_widget_height = 2 * b.widget_margins[1] + b.widget_base_dimensions[1], j = a.param(b), a.inArray(j, f.generated_stylesheets) >= 0) return !1;
		for (this.generated_stylesheets.push(j), f.generated_stylesheets.push(j), h = b.cols; h >= 0; h--) c += b.namespace + ' [data-col="' + (h + 1) + '"] { left:' + (h * b.widget_base_dimensions[0] + h * b.widget_margins[0] + (h + 1) * b.widget_margins[0]) + "px; }\n";
		for (h = b.rows; h >= 0; h--) c += b.namespace + ' [data-row="' + (h + 1) + '"] { top:' + (h * b.widget_base_dimensions[1] + h * b.widget_margins[1] + (h + 1) * b.widget_margins[1]) + "px; }\n";
		for (k = 1; k <= b.rows; k++) c += b.namespace + ' [data-sizey="' + k + '"] { height:' + (k * b.widget_base_dimensions[1] + (k - 1) * 2 * b.widget_margins[1]) + "px; }\n";
		for (l = 1; d >= l; l++) c += b.namespace + ' [data-sizex="' + l + '"] { width:' + (l * b.widget_base_dimensions[0] + (l - 1) * 2 * b.widget_margins[0]) + "px; }\n";
		return this.add_style_tag(c)
	}, g.add_style_tag = function(a) {
		var b = c,
			d = b.createElement("style");
		return b.getElementsByTagName("head")[0].appendChild(d), d.setAttribute("type", "text/css"), d.styleSheet ? d.styleSheet.cssText = a : d.appendChild(c.createTextNode(a)), this.$style_tags = this.$style_tags.add(d), this
	}, g.remove_style_tags = function() {
		var b = f.generated_stylesheets,
			c = this.generated_stylesheets;
		this.$style_tags.remove(), f.generated_stylesheets = a.map(b, function(b) {
			return -1 === a.inArray(b, c) ? b : void 0
		})
	}, g.generate_faux_grid = function(a, b) {
		var c, d;
		for (this.faux_grid = [], this.gridmap = [], c = b; c > 0; c--) for (this.gridmap[c] = [], d = a; d > 0; d--) this.add_faux_cell(d, c);
		return this
	}, g.add_faux_cell = function(b, c) {
		var d = a({
			left: this.baseX + (c - 1) * this.min_widget_width,
			top: this.baseY + (b - 1) * this.min_widget_height,
			width: this.min_widget_width,
			height: this.min_widget_height,
			col: c,
			row: b,
			original_col: c,
			original_row: b
		}).coords();
		return a.isArray(this.gridmap[c]) || (this.gridmap[c] = []), this.gridmap[c][b] = !1, this.faux_grid.push(d), this
	}, g.add_faux_rows = function(a) {
		var d, e, b = this.rows,
			c = b + (a || 1);
		for (d = c; d > b; d--) for (e = this.cols; e >= 1; e--) this.add_faux_cell(d, e);
		return this.rows = c, this.options.autogenerate_stylesheet && this.generate_stylesheet(), this
	}, g.add_faux_cols = function(a) {
		var d, e, b = this.cols,
			c = b + (a || 1);
		for (c = Math.min(c, this.options.max_cols), d = b + 1; c >= d; d++) for (e = this.rows; e >= 1; e--) this.add_faux_cell(e, d);
		return this.cols = c, this.options.autogenerate_stylesheet && this.generate_stylesheet(), this
	}, g.recalculate_faux_grid = function() {
		var c = this.$wrapper.width();
		return this.baseX = (a(b).width() - c) / 2, this.baseY = this.$wrapper.offset().top, a.each(this.faux_grid, a.proxy(function(a, b) {
			this.faux_grid[a] = b.update({
				left: this.baseX + (b.data.col - 1) * this.min_widget_width,
				top: this.baseY + (b.data.row - 1) * this.min_widget_height
			})
		}, this)), this
	}, g.get_widgets_from_DOM = function() {
		return this.$widgets.each(a.proxy(function(b, c) {
			this.register_widget(a(c))
		}, this)), this
	}, g.generate_grid_and_stylesheet = function() {
		var g, h, c = this.$wrapper.width(),
			d = this.options.max_cols,
			e = Math.floor(c / this.min_widget_width) + this.options.extra_cols,
			f = this.$widgets.map(function() {
				return a(this).attr("data-col")
			}).get();
		return f.length || (f = [0]), g = Math.max.apply(Math, f), this.cols = Math.max(g, e, this.options.min_cols), 1 / 0 !== d && d >= g && d < this.cols && (this.cols = d), h = this.options.extra_rows, this.$widgets.each(function(b, c) {
			h += +a(c).attr("data-sizey")
		}), this.rows = Math.max(h, this.options.min_rows), this.baseX = (a(b).width() - c) / 2, this.baseY = this.$wrapper.offset().top, this.options.autogenerate_stylesheet && this.generate_stylesheet(), this.generate_faux_grid(this.rows, this.cols)
	}, g.destroy = function() {
		return a(b).unbind(".gridster"), this.drag_api && this.drag_api.destroy(), this.remove_style_tags(), this.$el.remove(), this
	}, a.fn.gridster = function(b) {
		return this.each(function() {
			a(this).data("gridster") || a(this).data("gridster", new f(this, b))
		})
	}, a.Gridster = g
}(jQuery, window, document);