/*
  jQuery Picture Tag 0.0.3
  Built by Jessica Lynn Suttles: https://github.com/jlsuttles
  Built by Bookis Smuin: https://github.com/bookis
  Details and source: https://github.com/g5/jquery-picture-tag
  Demo: https://g5.github.com/jquery-picture-tag/development/example.html
*/// Generated by CoffeeScript 1.6.1
(function(){var e,t=this;this.PictureTag={};e=jQuery;e.fn.pictureTag=function(){return this.each(function(){return new PictureTag.Picture(e(this))})};this.PictureTag.Picture=function(){function t(n){var r=this;this.$el=n;this._displayBest=function(){return t.prototype._displayBest.apply(r,arguments)};this.$fallbackImg=this.$el.children("img:first");this.$fallbackImg.hide();this.pictureImg=new PictureTag.Img(this);this.sources=new PictureTag.Sources(this.$el.children("source"));this._displayBest();e(window).resize(this._displayBest)}t.prototype._displayBest=function(){return this.pictureImg.display(this.sources.best())};return t}();this.PictureTag.Img=function(){function t(n){var r=this;this.picture=n;this._replace=function(){return t.prototype._replace.apply(r,arguments)};this._current=function(){return t.prototype._current.apply(r,arguments)};this.display=function(e){return t.prototype.display.apply(r,arguments)};this.alt=this.picture.$el.attr("alt");this.$el=e('<img alt="'+this.alt+'" src="">');this.picture.$el.children("img:last").after(this.$el)}t.prototype.display=function(e){this.$el=this._current();if(e!==this.$el.attr("src")){this.$el2=this.$el.clone();this.$el2.attr("src",null);this.$el2.attr("src",e);return this.$el2.load(this._replace)}};t.prototype._current=function(){return this.picture.$el.children("img:last")};t.prototype._replace=function(){return this.$el.replaceWith(this.$el2)};return t}();this.PictureTag.Sources=function(){function t(e){var n=this;this.$els=e;this._newSource=function(e,r){return t.prototype._newSource.apply(n,arguments)};this.best=function(){return t.prototype.best.apply(n,arguments)};this.defaultSource=new PictureTag.Source(this.$els.filter(":not([media])"));this.mediaSources=this.$els.filter("[media]").map(this._newSource)}t.prototype.best=function(){var e,t=this;e=this.defaultSource;this.mediaSources.each(function(t,n){if(n.isBetterThan(e))return e=n});return e.src()};t.prototype._newSource=function(t,n){return new PictureTag.Source(e(n))};return t}();this.PictureTag.Source=function(){function e(e){this.$el=e;this.media=new PictureTag.Media(this.$el.attr("media"));this.srcset=this.$el.attr("srcset")}e.prototype.isBetterThan=function(e){return this.media.isBetterThan(e.media)};e.prototype.src=function(){if(this.srcset)return this.srcset.match(/^\S+?(?=,|\s)/)[0]};return e}();this.PictureTag.Media=function(){function e(e){this.query=e}e.prototype.isBetterThan=function(e){return this._matches()&&!e._matches()?!0:this._matches()&&e._matches()?this._minWidth>=e.minWidth:!1};e.prototype._matches=function(){return this.query&&matchMedia(this.query).matches};e.prototype._minWidth=function(){return parseInt(this.query.match(/\d+/)[0])};return e}()}).call(this);