var HeaderControls=Class.create(Widget,{widgetIdentifier:"com-apple-iweb-widget-headercontrols",initialize:function($super,f,a,b,e,d,c){if(f!=null){$super(f,a,b,e,d,c);NotificationCenter.addObserver(this,HeaderControls.prototype.p_prevPage,"PreviousPage",this.p_mediaGridID());NotificationCenter.addObserver(this,HeaderControls.prototype.p_nextPage,"NextPage",this.p_mediaGridID());NotificationCenter.addObserver(this,HeaderControls.prototype.p_setPage,"SetPage",this.p_mediaGridID());this.mRange=new IWPageRange(0,5);this.p_updateRange()}},onload:function(){var a={showBackToIndex:true,showSubscribe:true,showSlideshow:true,mediaIndex:false,entriesPerPage:99,entryCount:0};this.initializeDefaultPreferences(a);this.setPage(0);this.updateFromPreferences();if(this.preferences&&this.preferences.postNotification){this.preferences.postNotification("BLWidgetIsSafeToDrawNotification",1)}},onunload:function(){},startup:function(){this.p_updateCanvasControls();this.p_updateBackToIndex();this.p_updatePaginationControls();this.p_updateSubscribe();this.p_updateSlideshow();if(this.p_mediaIndex()){this.getElementById("media_index_only").show()}else{this.getElementById("album_only").show()}},changedPreferenceForKey:function(a){if(a=="entriesPerPage"||a=="entryCount"||a=="x-currentPage"){this.p_updateRange();this.p_updatePaginationControls()}else{if(a=="showBackToIndex"){this.p_updateBackToIndex()}else{if(a=="showSubscribe"){this.p_updateSubscribe()}else{if(a=="showSlideshow"){this.p_updateSlideshow()}else{if(a=="canvas controls"){this.p_updateCanvasControls()}else{if(this.runningInApp){if(a=="x-nextPage"){this.nextPage()}else{if(a=="x-previousPage"){this.prevPage()}else{if(a=="x-setPage"){this.setPage(this.p_setPagePreference())}}}}}}}}}},updateFromPreferences:function(){this.startup()},prevPage:function(){NotificationCenter.postNotification(new IWNotification("PreviousPage",this.p_mediaGridID(),null))},nextPage:function(){NotificationCenter.postNotification(new IWNotification("NextPage",this.p_mediaGridID(),null))},setPage:function(a){NotificationCenter.postNotification(new IWNotification("SetPage",this.p_mediaGridID(),{pageIndex:a}))},playSlideshow:function(){if(this.mPlaySlideshowFunction){this.mPlaySlideshowFunction()}},setPlaySlideshowFunction:function(a){this.mPlaySlideshowFunction=a},p_canNavigateToPrev:function(){return(this.p_currentPage()>0)},p_prevPage:function(a){if(this.p_canNavigateToPrev()){this.setPage(this.p_currentPage()-1)}},p_canNavigateToNext:function(){return(this.p_currentPage()<this.p_pageCount()-1)},p_nextPage:function(a){if(this.p_canNavigateToNext()){this.setPage(this.p_currentPage()+1)}},p_setPage:function(f){var a=f.userInfo().pageIndex;this.setPreferenceForKey(a,"x-currentPage");if(!this.runningInApp){var d=this.p_entriesPerPage();var c=a*d;var e=Math.min(this.p_entryCount()-c,d);var b={range:new IWRange(c,e)};NotificationCenter.postNotification(new IWNotification("RangeChanged",this.p_mediaGridID(),b))}},p_showBackToIndex:function(){var a=this.preferenceForKey("showBackToIndex");(function(){return a!==undefined}).assert();return a},p_showSubscribe:function(){var a=this.preferenceForKey("showSubscribe");(function(){return a!==undefined}).assert();return a},p_showSlideshow:function(){var a=this.preferenceForKey("showSlideshow");(function(){return a!==undefined}).assert();return a},p_mediaGridID:function(){var a=null;if(this.preferences){a=this.preferenceForKey("gridID")}if(a===undefined){a=null}return a},p_setPagePreference:function(){var a=null;if(this.preferences){a=this.preferenceForKey("x-setPage")}if(a===undefined){a=null}return a},p_updatePaginationControls:function(){var c=this.div();var d=this.p_currentPage();var j="";if(this.p_isPaginated()){var a=this.preferenceForKey("canvas controls");if(this.p_canNavigateToPrev()){var f=a["canvas_arrow-left"];j+="<a href='javascript:#{WIDGET_ID}.prevPage()'>";j+=imgMarkup(f,"","","");j+="</a> "}else{var f=a["canvas_arrow-left-D"];j+=imgMarkup(f,"","","")+" "}for(var b=this.mRange.min();b<this.mRange.max();b++){if(b==d){j+="<span class='current_page'>"+(b+1)+"</span> "}else{j+="<a href='javascript:#{WIDGET_ID}.setPage("+b+")'>"+(b+1)+"</a> "}}if(this.p_canNavigateToNext()){var g=a["canvas_arrow-right"];j+="<a href='javascript:#{WIDGET_ID}.nextPage()'>";j+=imgMarkup(g,"","","");j+="</a>"}else{var g=a["canvas_arrow-right-D"];j+=imgMarkup(g,"","","")}}var h=new Template(j);var e=h.evaluate({WIDGET_ID:this.instanceID});this.getElementById("pagination_controls").update(e);c.select(".paginated_only").invoke(this.p_isPaginated()?"show":"hide");c.select(".non_paginated_only").invoke(this.p_isPaginated()?"hide":"show");if(this.runningInApp){this.setPreferenceForKey(j,"x-paginationSpanContents")}else{NotificationCenter.postNotification(new IWNotification("paginationSpanContents",this.p_mediaGridID(),{controls:j}))}},p_setAnchorsUnderElementToHREF:function(b,a){$(b).select("a").map(function(c){c.href=a})},p_updateCanvasControls:function(){var a=this.preferenceForKey("canvas controls");this.div().select(".canvas").each(function(b){var c="canvas_"+b.classNames().toArray()[1];setImgSrc(b,a[c])})},p_updateBackToIndex:function(){var a=this.getElementById("back_to_index");this.p_showBackToIndex()?a.show():a.hide();if(!this.runningInApp){this.p_setAnchorsUnderElementToHREF(a,this.p_indexURL())}},p_updateSubscribe:function(){this.div().select(".subscribe").invoke(this.p_showSubscribe()?"show":"hide");if(!this.runningInApp){var a="javascript:"+this.instanceID+(this.p_mediaIndex()?".mediaIndexSubscribe()":".photocastSubscribe()");var b=this;this.div().select(".subscribe").each(function(c){b.p_setAnchorsUnderElementToHREF(c,a)})}},mediaIndexSubscribe:function(){window.location=this.p_feedURL()},photocastSubscribe:function(){photocastHelper(this.p_feedURL())},p_updateSlideshow:function(){this.div().select(".play_slideshow").invoke(this.p_showSlideshow()?"show":"hide")},p_mediaIndex:function(){var a=null;if(this.preferences){a=this.preferenceForKey("mediaIndex")}if(a===undefined){a=false}return a},p_currentPage:function(){var a=0;if(this.preferences){a=this.preferenceForKey("x-currentPage")}if(!a){a=0}return a},p_entriesPerPage:function(){var a=null;if(this.preferences){a=this.preferenceForKey("entriesPerPage")}if(a==undefined){a=99}return a},p_entryCount:function(){var a=null;if(this.preferences){a=this.preferenceForKey("entryCount")}if(a==undefined){a=0}return a},p_indexURL:function(){return this.preferenceForKey("indexURL")},p_feedURL:function(){return this.preferenceForKey("feedURL")},p_isPaginated:function(){return(this.p_entryCount()>this.p_entriesPerPage())},p_pageCount:function(){return Math.ceil(this.p_entryCount()/this.p_entriesPerPage())},p_updateRange:function(){var a=this.p_pageCount();var b=this.p_currentPage();if(b>=a){b=a-1;this.setPreferenceForKey(b,"x-currentPage")}if(a<=5||this.mRange.length()<3||this.mRange.max()>a){this.mRange.setMax(Math.min(5,a))}if(b<this.mRange.min()){this.mRange.shift(b-this.mRange.min())}else{if(b>=this.mRange.max()){this.mRange.shift(b-this.mRange.max()+1)}}}});