/*
 *  (c) 2000-2015 deviantART, Inc. All rights reserved.
 */
DWait.ready(["jms/pages/duperbrowse/duperbrowse.helpers.js","jms/lib/Base.js","jms/lib/jquery/jquery.current.js","jms/pages/duperbrowse/duperbrowse.master.js","jms/lib/ddt.js","jms/lib/gmi.js"],function(){(function(e){window.DuperbrowseBaseCustomStream=GMIBase.extend({_items:[],_current_item:null,_current_item_offset:null,gmiConstructor:function(){this._items=[],this.init_stream()},gmiDestructor:function(){},init_stream:function(){},_get_item_data_from_clicked_element:function(){},_on_stream_item_closed:function(){},_add_item:function(e,t,r,s,i,_){(window.deviantART.deviant.loggedIn||!e.hasClass("antisocial")&&!e.hasClass("ismature"))&&(this._items[r]={itemid:s,stream_offset:r},_===!0?window.DuperbrowseHelpers.cache_dimensions_for_legacy_item(e,s):window.DuperbrowseHelpers.cache_dimensions_for_item(e,s),window.DuperbrowseHelpers.cache_options_for_item(e,s),window.DuperbrowseHelpers.map_url(s,i),t.data("itemid",s),t.data("stream_offset",r))},_open_duperbrowse:function(t){var r=window.DuperbrowseHelpers.click_handler(t);if(ddt.log("Duperbrowse","custom stream open",t,r),r.open_duperbrowse){var s=e(t.currentTarget),i=this._get_item_data_from_clicked_element(s);if(i){var _={next_item_callback:this._next_item_callback.bind(this),prev_item_callback:this._prev_item_callback.bind(this),has_next_callback:this._has_next_callback.bind(this),has_prev_callback:this._has_prev_callback.bind(this),on_stream_item_opened:this._on_stream_item_opened.bind(this),on_stream_item_closed:this._on_stream_item_closed.bind(this)};return Duperbrowse.open(i,_),!1}return!1}return r.click_return},_next_item_callback:function(){var t=this._current_offset+1,r=this._items[t];return void 0!==r?e.Deferred().resolve(r).promise():e.Deferred().reject("end of stream").promise()},_prev_item_callback:function(){var t=this._current_offset-1,r=this._items[t];return void 0!==r?e.Deferred().resolve(r).promise():e.Deferred().reject("end of stream").promise()},_has_next_callback:function(){var e=this._current_offset+1;return void 0!==this._items[e]?!0:!1},_has_prev_callback:function(){var e=this._current_offset-1;return 0>e?!1:void 0!==this._items[e]?!0:!1},_on_stream_item_opened:function(e){void 0!==this._items[e.stream_offset]?(this._current_item=e,this._current_offset=e.stream_offset):(this._current_item=null,this._current_offset=null)}})})(jQuery),window.DWait&&DWait.run("jms/pages/duperbrowse/stream/base.custom.stream.js")});
DWait.ready(["jms/lib/jquery/plugins/jquery.somedata.js","jms/lib/gmi.js","jms/lib/Base.js","jms/lib/pubsub.js","jms/lib/jquery/jquery.current.js","jms/pages/duperbrowse/duperbrowse.helpers.js","jms/lib/glbl.js","jms/pages/lub/lub_constants.js","jms/pages/duperbrowse/stream/base.custom.stream.js"],function(){(function(e,t){t.DuperbrowseFreeformCustomStream=DuperbrowseBaseCustomStream.extend({init_stream:function(){if(this._should_init_stream()){var t=e(".shadow-holder, .embedded-deviation, a[data-deviationid]",this.$),i=this;e.each(t,function(t,a){var r,s=e("a.thumb",a),n=e(a),o=parseInt(n.data("embed-id")||n.data("deviationid"),10),d=!1;if(s.length>0){if(r=s.attr("href"),i._should_not_include_in_stream(r))return;if(isNaN(o)&&(o=i._get_deviationid_from_legacy_markup(r),d=!0,!o))return;return i._add_item(s,s,t,o,r,d),s.on("click",i._open_duperbrowse.bind(i)),void 0}if(n.hasClass("embedded-deviation")||n.data("deviationid")){if(r=n.attr("href"),i._should_not_include_in_stream(r))return;if(isNaN(o)&&(o=i._get_deviationid_from_legacy_markup(r),d=!0,!o))return;i._add_item(n,n,t,o,r,d),n.on("click",i._open_duperbrowse.bind(i))}})}},_get_deviationid_from_legacy_markup:function(e){var t=e.match(REG_DEVIATION_2)||e.match(REG_OLD_DEVIATION_2),i=parseInt(t[3],10);return isNaN(i)?!1:i},_should_init_stream:function(){return Glbl("Site.is_stash")?!1:t.location!=t.parent.location?!1:Glbl("Location.get_params").edit?!1:"/journal/update"==Glbl("Location.path")?!1:!0},_should_not_include_in_stream:function(e){return e?e.match(/^https?:\/\/(www\.)?sta\.sh\b/)?!0:Glbl("Site.is_stash")?!0:!1:!0},_get_item_data_from_clicked_element:function(t){var i=t.someData("itemid","stream_offset");return e.isEmptyObject(i)?!1:i},_on_stream_item_closed:function(t){var i=e(".shadow-holder, .embedded-deviation, a[data-deviationid]",this.$).filter(function(){return e.data(this,"itemid")==t.current_id});0!==i.length&&DuperbrowseHelpers.scroll_to_thumb(i)}})})(jQuery,window),window.DWait&&DWait.run("jms/pages/duperbrowse/stream/freeform.custom.stream.js")});if(window.DWait){DWait.count()}