(function(a, b) { var c = function(a, b, c) { var d; return function() { function h() { if (!c) a.apply(f, g); d = null } var f = this, g = arguments; if (d) cleartimeout(d); else if (c) a.apply(f, g); d = settimeout(h, b || 150) } }; jquery.fn[b] = function(a) { return a ? this.bind("resize", c(a)) : this.trigger(b) } })(jquery, "smartresize"); (function(a) { a.gal = function(b, c) { this.element = a(c); this._init(b) }; a.gal.settings = { selector: ".item", width: 225, gutter: 20, animate: false, animationoptions: { speed: 200, duration: 300, effect: "fadeinonappear", queue: true, complete: function() {} } }; a.gal.prototype = { _init: function(b) { var c = this; this.name = this._setname(5); this.gridarr = []; this.gridarrappend = []; this.gridarrprepend = []; this.setarr = false; this.setgrid = false; this.setoptions; this.cols = 0; this.itemcount = 0; this.prependcount = 0; this.isprepending = false; this.appendcount = 0; this.resetcount = true; this.ifcallback = true; this.box = this.element; this.options = a.extend(true, {}, a.gal.settings, b); this.gridarr = a.makearray(this.box.find(this.options.selector)); this.isresizing = false; this.w = 0; this.boxarr = []; this._setcols(); this._rendergrid("append"); a(this.box).addclass("gridalicious"); a(window).smartresize(function() { c.resize() }) }, _setname: function(a, b) { b = b ? b: ""; return a ? this._setname(--a, "0123456789abcdefghijklmnopqrstuvwxtzabcdefghiklmnopqrstuvwxyz".charat(math.floor(math.random() * 60)) + b) : b }, _setcols: function() { this.cols = math.floor(this.box.width() / this.options.width); diff = (this.box.width() - this.cols * this.options.width - this.options.gutter) / this.cols; w = (this.options.width + diff) / this.box.width() * 100; this.w = w; for (var b = 0; b < this.cols; b++) { var c = a("
").addclass("galcolumn").attr("id", "item" + b + this.name).css({ width: w + "%", paddingleft: this.options.gutter, paddingbottom: this.options.gutter, "float": "left", "-webkit-box-sizing": "border-box", "-moz-box-sizing": "border-box", "-o-box-sizing": "border-box", "box-sizing": "border-box" }); this.box.append(c) } this.box.find(a("#clear" + this.name)).remove(); var d = a("
").css({ clear: "both", height: "0", width: "0", display: "block" }).attr("id", "clear" + this.name); this.box.append(d) }, _rendergrid: function(b, c, d, e) { var f = []; var g = []; var h = []; var i = 0; var j = this.prependcount; var k = this.appendcount; var l = this.options.gutter; var m = this.cols; var n = this.name; var o = 0; var p = a(".galcolumn").width(); if (c) { g = c; if (b == "append") { k += d; i = this.appendcount } if (b == "prepend") { this.isprepending = true; i = math.round(d % m); if (i <= 0) i = m } if (b == "renderafterprepend") { k += d; i = d } } else { g = this.gridarr; k = a(this.gridarr).size() } a.each(g, function(c, d) { var e = a(d); var g = "100%"; if (e.hasclass("not-responsive")) { g = "auto" } e.css({ marginbottom: l, zoom: "1", filter: "alpha(opacity=0)", opacity: "0" }).find("img, object, embed, iframe").css({ width: g, height: "auto", display: "block", "margin-left": "auto", "margin-right": "auto" }); if (b == "prepend") { i--; a("#item" + i + n).prepend(e); f.push(e); if (i == 0) i = m } else { a("#item" + i + n).append(e); f.push(e); i++; if (i >= m) i = 0; if (k >= m) k = k - m } }); this.appendcount = k; this.itemcount = i; if (b == "append" || b == "prepend") { if (b == "prepend") { this._updateafterprepend(this.gridarr, g) } this._renderitem(f); this.isprepending = false } else { this._renderitem(this.gridarr) } }, _collectitems: function() { var b = []; a(this.box).find(this.options.selector).each(function(c) { b.push(a(this)) }); return b }, _renderitem: function(b) { var c = this.options.animationoptions.speed; var d = this.options.animationoptions.effect; var e = this.options.animationoptions.duration; var f = this.options.animationoptions.queue; var g = this.options.animate; var h = this.options.animationoptions.complete; var i = 0; var j = 0; if (g === true && !this.isresizing) { if (f === true && d == "fadeinonappear") { if (this.isprepending) b.reverse(); a.each(b, function(d, f) { settimeout(function() { a(f).animate({ opacity: "1.0" }, e); j++; if (j == b.length) { h.call(undefined, b) } }, i * c); i++ }) } else if (f === false && d == "fadeinonappear") { if (this.isprepending) b.reverse(); a.each(b, function(c, d) { a(d).animate({ opacity: "1.0" }, e); j++; if (j == b.length) { if (this.ifcallback) { h.call(undefined, b) } } }) } if (f === true && !d) { a.each(b, function(c, d) { a(d).css({ opacity: "1", filter: "alpha(opacity=1)" }); j++; if (j == b.length) { if (this.ifcallback) { h.call(undefined, b) } } }) } } else { a.each(b, function(b, c) { a(c).css({ opacity: "1", filter: "alpha(opacity=1)" }) }); if (this.ifcallback) { h.call(b) } } }, _updateafterprepend: function(b, c) { var d = this.gridarr; a.each(c, function(a, b) { d.unshift(b) }); this.gridarr = d }, resize: function() { this.box.find(a(".galcolumn")).remove(); this._setcols(); this.ifcallback = false; this.isresizing = true; this._rendergrid("append"); this.ifcallback = true; this.isresizing = false }, append: function(b) { var c = this.gridarr; var d = this.gridarrprepend; a.each(b, function(a, b) { c.push(b); d.push(b) }); this._rendergrid("append", b, a(b).size()) }, prepend: function(b) { this.ifcallback = false; this._rendergrid("prepend", b, a(b).size()); this.ifcallback = true } }; a.fn.gridalicious = function(b, c) { if (typeof b === "string") { this.each(function() { var d = a.data(this, "gridalicious"); d[b].apply(d, [c]) }) } else { this.each(function() { a.data(this, "gridalicious", new a.gal(b, this)) }) } return this } })(jquery);