function DataSet(a,b,c){this.tag=a;if(null!=b)this.refreshInterval=b;if(null!=c)this.feedType=c}
DataSet.prototype={lastUpdate:0,requested:!1,response:null,tag:"",feedType:"json",loadedAll:!1,stepSize:10,refreshInterval:6E4,lastArgsSet:null,update:function(a,b,c){this.requested=!1;if(0===b||null==b)this.lastUpdate=+new Date;if(null!=b){var c=c||this.stepSize,d=getLen(a);this.loadedAll=d<c;c=d;if(null==this.response)this.response=a;else for(d=0;d<c;d++)this.response.ads[b+d]=a.ads[d]}else this.response=a,this.loadedAll=!0},compareArgs:function(a){if(null==this.lastArgsSet&&null==a)return!0;if(null==
this.lastArgsSet||null==a)return!1;for(var b in a)if(a[b]!=this.lastArgsSet[b])return!1;for(b in this.lastArgsSet)if(a[b]!=this.lastArgsSet[b])return!1;return!0}};function Updater(a,b,c,d){this.requiredData="string"==typeof b?b.split(";"):b;if(null!=c)this.preparingFunction=c;if(null!=d)this._arguments=d;this.viewBinder=a}Updater.prototype={viewBinder:function(){},preparingFunction:function(){},requiredData:[],_arguments:{}};function Model(a){this.data=a;this.fillFromStorage()}
Model.prototype={data:null,updaters:{},refreshData:function(a,b,c,d){if(!a.requested){a.requested=!0;var d=d||a.stepSize,e=this,g="",h;for(h in b._arguments)g+="&{0}={1}".format(h,b._arguments[h]);null!=c&&(g+="&startFrom={0}&count={1}".format(c,d));if(!a.compareArgs(b._arguments))a.response=null;a.lastArgsSet=b._arguments;$.get("feeds/proxy.php?feed="+a.tag+g,function(g){var f=null;switch(a.feedType){case "rss":f=new JFeed(g);break;case "json":f=$.parseJSON(g);if(null!=f.response)f=f.response;else if(null!=
f.data&&f.data.items&&null==f.ads)f.ads=f.data.items;break;default:f=g}null!=c?a.update(f,c,d):a.update(f);e.rebind(b,c,d)}).error(function(){})}},rebind:function(a,b,c){$.mobile.showPageLoadingMsg();if(null!=a){for(var d=new Date,e,g=!0,h=0;h<a.requiredData.length;h++){e=this.data[a.requiredData[h]];if(null==b){if((+e.lastUpdate||0)<d-e.refreshInterval)this.loadMoreUpdater=null,this.refreshData(e,a)}else this.loadMoreUpdater=a,(+e.lastUpdate||0)<d-e.refreshInterval?this.refreshData(e,a,0,b+e.stepSize):
(null==e.response||!e.compareArgs(a._arguments)||getLen(e.response)<=b&&!e.loadedAll)&&this.refreshData(e,a,b);e.requested&&(g=!1)}g&&(a.viewBinder(b,c),this.store(),$.mobile.hidePageLoadingMsg())}},loadMoreUpdater:null,loadMore:function(){if(null!=this.loadMoreUpdater){var a=this.loadMoreUpdater.requiredData[0];this.data[a].loadedAll||(null!=this.data[a].response?this.rebind(this.loadMoreUpdater,this.data[a].response.ads.length):this.rebind(this.loadMoreUpdater,0))}},fillFromStorage:function(){var a=
$.Storage.get(this.storageTag);try{a=$.parseJSON(a)}catch(b){return}try{for(var c in a)for(var d in a[c])this.data[c][d]=a[c][d],this.data[c].requested=!1}catch(e){}},store:function(){var a={},b;for(b in this.data)null!=this.data[b].response&&(a[b]=this.data[b]);$.Storage.set(this.storageTag,jsonEncode(a))},cleanup:function(){$.Storage.remove(this.storageTag)},storageTag:"tv2-beep-data-storage"};function StorageItem(a,b,c){this.tag=a;if(b)this.get=b;if(c)this.set=c}
StorageItem.prototype={tag:"",get:function(){return+$.Storage.get(this.tag)},set:function(a){return $.Storage.set(this.tag,""+a)}};function StorageManager(){}
StorageManager.prototype={currentNews:new StorageItem("tv2-beep-currentArticleId",function(){return $.Storage.get(this.tag)},function(a){return $.Storage.set(this.tag,""+a)}),currentVideo:new StorageItem("tv2-beep-currentVideoId",function(){return $.Storage.get(this.tag)},function(a){return $.Storage.set(this.tag,""+a)}),newsOrTop:new StorageItem("tv2-beep-newsOrTop",function(){return $.Storage.get(this.tag)},function(a){return $.Storage.set(this.tag,""+a)})};
