debugLog&&parliamentUK.logEvent("[SUB-SITE JAVASCRIPT]: main.js loaded"),parliamentUK.main={websiteFeaturesInit:function(n){var t,r;if(debugLog&&parliamentUK.logEvent("[WEBSITE FEATURES]: initialize"),$(function(){$("#footer-modules .three-wide > div").equalHeights()}),$("#website-features").length==1){for(isIe==undefined&&parliamentUK.browserSniffer(),t=n.main.websiteFeaturesConfigInitialLoad!=undefined?n.main.websiteFeaturesConfigInitialLoad:websiteFeaturesConfig.initialLoad,$("#website-features DIV").each(function(n){var t={},i=isIe?"<EM>":"<em>";isOpera&&(i="<EM>"),t.heading=$("H3 A",$(this)).html(),t.subHeading=$("H3 a em",$(this)).html(),t.fullsizeImageSrc=$("IMG",$(this)).attr("src"),t.thumbnailImageSrc=$("A:eq(1)",$(this)).attr("rel"),t.itemUrl=$("A:eq(1)",$(this)).attr("href"),t.imageAlt=$("IMG",$(this)).attr("alt"),t.description=$("P",$(this)).html(),websiteFeatures.push(t),debugLog&&parliamentUK.logEvent("[WEBSITE FEATURES (item "+(n+1)+" content)]: heading="+t.heading+", subHeading="+t.subHeading+",fullsizeImageSrc="+t.fullsizeImageSrc+", thumbnailImageSrc="+t.thumbnailImageSrc+", imageAlt="+t.imageAlt+", description="+t.description)}),$("#website-features").remove(),$("<div />").attr({id:"website-features","class":"injected"}).insertBefore($("#content")).append($("<div />").attr({"class":"two-wide"}).append($("<div />").attr({"class":"thumbnails"}).append($("<h2 />").html("Featured on the UK Parliament website")))),i=0;i<=websiteFeatures.length-1;i++)r=i==websiteFeatures.length-1?"four-wide last":"four-wide",$("<div />").attr({"class":r}).appendTo($("#website-features .thumbnails")).append($("<a />").attr({href:websiteFeatures[i].itemUrl}).append($("<img />").attr({src:websiteFeatures[i].thumbnailImageSrc,alt:websiteFeatures[i].imageAlt})).append($("<em />").html(websiteFeatures[i].subHeading))),i==t-1&&($(".thumbnails").addClass("thumbnail-"+t+"-select"),$(".thumbnails DIV:eq("+(t-1)+")").attr("class","four-wide selected"));n.main.websiteFeaturesConfigRotationEnabled&&(websiteFeaturesConfig.rotationEnabled=!0),n.main.websiteFeaturesConfigRotationTime!=undefined&&(websiteFeaturesConfig.rotationTime=n.main.websiteFeaturesConfigRotationTime),websiteFeaturesConfig.rotationEnabled?setTimeout("parliamentUK.main.toggleWebsiteFeatures("+t+","+websiteFeatures.length+")",websiteFeaturesConfig.rotationTime):$("#website-features .four-wide A").each(function(n){$(this).bind("mouseenter focusin",function(){return parliamentUK.main.toggleWebsiteFeatures(n,websiteFeatures.length),!1})}),$("<div />").attr({"class":"inner"}).appendTo($("#website-features .two-wide:eq(0)")).append($("<h3 />").append($("<a />").attr({href:websiteFeatures[t-1].itemUrl}).html(websiteFeatures[t-1].heading))).append($("<p />").html(websiteFeatures[t-1].description)),$("<div />").attr({id:"fullsize","class":"two-wide last"}).appendTo($("#website-features")).append($("<a />").attr({href:websiteFeatures[t-1].itemUrl}).append($("<img />").attr({src:websiteFeatures[t-1].fullsizeImageSrc,alt:websiteFeatures[t-1].imageAlt})))}},toggleWebsiteFeatures:function(n,t){debugLog&&parliamentUK.logEvent("[TOGGLE WEBSITE FEATURES]: newIndex="+n+", totalFeatures="+t),$("#website-features .inner H3 A").html(websiteFeatures[n].heading),$("#website-features .inner H3 A").attr("href",websiteFeatures[n].itemUrl),$("#website-features .inner P").html(websiteFeatures[n].description),$("#website-features #fullsize A").attr("href",websiteFeatures[n].itemUrl),$("#website-features #fullsize IMG").attr("src",websiteFeatures[n].fullsizeImageSrc).attr("alt",websiteFeatures[n].imageAlt),$(".thumbnails").attr("class","thumbnails thumbnail-"+(n+1)+"-select"),$(".thumbnails DIV").each(function(t){$(this).attr("class",t==n?"four-wide selected":"four-wide")}),websiteFeaturesConfig.rotationEnabled&&setTimeout("parliamentUK.main.toggleWebsiteFeatures("+(n==t-1?0:n+1)+","+t+")",websiteFeaturesConfig.rotationTime)},monthPrefix:function(n){return debugLog&&parliamentUK.logEvent("[MONTH PREFIX]: "+n),n.toString().length==1?"0"+n:n},calendarInit:function(n){var t="";for(x in n)t+=x+"="+n[x]+", ";t=t.substr(0,t.length-2),debugLog&&parliamentUK.logEvent("[CALENDAR INIT]: "+t),$("FIELDSET.calendar").size()>0&&$("FIELDSET.calendar").each(function(t){var r,u,i,e,f;for(calendarStartYear=$("SELECT:eq(2) OPTION:last",$(this)).val(),calendarStartDate="1/1/"+calendarStartYear,calendarEndDate="31/12/"+$("SELECT:eq(2) OPTION:first",$(this)).val(),availableDays=[],$("SELECT:eq(0) OPTION",$(this)).each(function(){availableDays.push($(this).hasClass("available"))}),r="calendar",$(this).hasClass("commons")&&(r+=" commons"),$(this).hasClass("lords")&&(r+=" lords"),$("<div />").attr({"class":"calendar"}).insertBefore($(this)),preloadDay=$("OPTION:selected",$("SELECT:eq(0)")).val(),preloadMonth=$("OPTION:selected",$("SELECT:eq(1)")).val(),preloadYear=$("OPTION:selected",$("SELECT:eq(2)")).val(),(preloadDay==undefined||preloadMonth==undefined||preloadYear==undefined)&&(u=new Date,preloadMonth=u.getMonth()+1,preloadYear=u.getFullYear(),preloadDay=u.getDate()),calendarPreloadDate=preloadDay+"/"+preloadMonth+"/"+preloadYear,i=parliamentUK.main.getUrlDetails({url:top.location.href,mode:"readUri"}),$(".calendar:eq("+t+")").datePicker({endDate:calendarEndDate,inline:!0,startDate:calendarStartDate}),e=!1,f=0;f<=availableDays.length-1;f++)if(availableDays[f]){e=!0;break}e?($(".calendar:eq("+t+")").bind("dateSelected",function(t,r,u){var f=u.html()+"/"+(parseInt(r.getMonth())+1)+"/"+preloadYear;f!=calendarPreloadDate&&(top.location.href=i+"?d="+u.html()+"&m="+(parseInt(r.getMonth())+1)+"&y="+preloadYear+"&pageInstanceId="+n.pageInstanceId)}),$(".calendar:eq("+t+")").dpSetSelected(preloadDay+"/"+preloadMonth+"/"+preloadYear)):($(".calendar:eq("+t+")").dpSetSelected("1/"+preloadMonth+"/"+preloadYear),$(".calendar:eq("+t+") .jCalendar .selected").removeClass("selected")),$(".calendar:eq("+t+") .selected",$(this)).addClass("disabled"),$(".calendar:eq("+t+") .other-month",$(this)).addClass("disabled"),currentMonth=parseInt(preloadMonth),currentYear=parseInt(preloadYear),$(".calendar:eq("+t+") .dp-nav-next-month").bind("click",function(){var t=!1,r,u;$(this).hasClass("disabled")?currentMonth!=12&&(t=!0):t=!0,t&&(monthToLoad=currentMonth<12?currentMonth+1:1,yearToLoad=currentMonth==12?currentYear+1:currentYear,r=parliamentUK.main.calendarMonthStart({ajaxUrl:n.ajaxUrl,monthCheck:currentMonth,yearCheck:currentYear,mode:"next-month",pageInstanceId:n.pageInstanceId}),u=i+"?d="+r+"&m="+monthToLoad+"&y="+yearToLoad+"&pageInstanceId="+n.pageInstanceId,top.location.href=u)}),$(".calendar:eq("+t+") .dp-nav-next-year").bind("click",function(){var t=!1,r,u;return $(this).hasClass("disabled")?currentMonth!=1&&(t=!0):t=!0,t&&(yearToLoad=currentYear+1,r=parliamentUK.main.calendarMonthStart({ajaxUrl:n.ajaxUrl,monthCheck:currentMonth,yearCheck:yearToLoad,mode:"next-year",pageInstanceId:n.pageInstanceId}),u=i+"?d="+r+"&m="+monthToLoad+"&y="+yearToLoad+"&pageInstanceId="+n.pageInstanceId,top.location.href=u),!1}),$(".calendar:eq("+t+") .dp-nav-prev-month").bind("click",function(){var t=!1,r,u;$(this).hasClass("disabled")?currentMonth!=1&&(t=!0):t=!0,t&&(monthToLoad=currentMonth>1?currentMonth-1:12,yearToLoad=currentMonth==1?currentYear-1:currentYear,r=parliamentUK.main.calendarMonthStart({ajaxUrl:n.ajaxUrl,monthCheck:currentMonth,yearCheck:currentYear,mode:"previous-month",pageInstanceId:n.pageInstanceId}),u=i+"?d="+r+"&m="+monthToLoad+"&y="+yearToLoad+"&pageInstanceId="+n.pageInstanceId,top.location.href=u)}),$(".calendar:eq("+t+") .dp-nav-prev-year").bind("click",function(){var t=!1,r;return $(this).hasClass("disabled")?currentMonth!=12&&(t=!0):t=!0,t&&(yearToLoad=currentYear-1,r=parliamentUK.main.calendarMonthStart({ajaxUrl:n.ajaxUrl,monthCheck:currentMonth,yearCheck:yearToLoad,mode:"previous-year",pageInstanceId:n.pageInstanceId}),top.location.href=i+"?d="+r+"&m="+monthToLoad+"&y="+yearToLoad+"&pageInstanceId="+n.pageInstanceId),!1}),r!="calendar"&&$("DIV:eq(0)",$(".calendar:eq("+t+")")).addClass(r),$(".calendar:eq("+t+") .jCalendar .current-month").each(function(n){$(this).addClass(availableDays[n]!=!0?"disabled":"")})}).remove()},calendarMonthStart:function(n){var t="",i;for(x in n)t+=x+"="+n[x]+", ";t=t.substr(0,t.length-2),debugLog&&parliamentUK.logEvent("[CALENDAR MONTH START]: "+t);switch(n.mode){case"init":case"next-year":case"previous-year":monthToLoad=n.monthCheck,yearToLoad=n.yearCheck;break;case"next-month":monthToLoad=n.monthCheck<12?n.monthCheck+1:1,yearToLoad=n.monthCheck==12?n.yearCheck+1:n.yearCheck;break;case"previous-month":monthToLoad=n.monthCheck>1?n.monthCheck-1:12,yearToLoad=n.monthCheck==1?n.yearCheck-1:n.yearCheck}return $.ajax({url:n.ajaxUrl+"?m="+monthToLoad+"&y="+yearToLoad+"&pageInstanceId="+n.pageInstanceId,cache:!1,dataType:"text/html",success:function(n){i=n,debugLog&&parliamentUK.logEvent("[CALENDAR MONTH START (ajax return)]: "+i)},async:!1}),i},getUrlDetails:function(n){var i="",u,t,o,f,r,s,e;for(x in n)i+=x+"="+n[x]+", ";if(i=i.substr(0,i.length-2),debugLog&&parliamentUK.logEvent("[GET URL DETAILS]: "+i),u=n.url.split("/"),t=u[u.length-1],t.indexOf("?")!=-1){o=t.split("?")[0],f=t.split("?")[1].split("&"),t=o;switch(n.mode){case"readUri":return debugLog&&parliamentUK.logEvent("[GET URL DETAILS (return uri)]: "+u),t;case"readQueryStringKey":for(r=0;r<=f.length-1;r++)if(s=f[r].split("=")[0],e=f[r].split("=")[1],s==n.queryStringKeyName)return debugLog&&parliamentUK.logEvent("[GET URL DETAILS (return querystring key value)]: "+e),e}}else if(n.mode=="readUri")return t},advancedSearchInit:function(n){var t,i;$("#advanced-search LI.mandatory").each(function(){$("<span />").insertBefore($("A",$(this))).append($("<em />").html($("A",$(this)).attr("title"))),$("A",$(this)).bind("click",function(){return!1})}),$("#advanced-search A").bind("mouseenter",function(){$(this).prev().is("SPAN")&&$(this).prev().css({visibility:"visible"})}).bind("mouseleave",function(){$(this).prev().is("SPAN")&&$(this).prev().css("visibility","hidden")}),t="Search using Boolean and proximity operators",$("#advanced-search .free-text INPUT").attr("value")!=t&&$("#advanced-search .free-text INPUT").attr("class","active"),$("#advanced-search .free-text INPUT").bind("blur",function(){$(this).attr("value")==""&&$(this).attr("value",t).removeClass("active")}).bind("focus",function(){$(this).attr("value")==t?$(this).attr("value","").attr("class","active"):$(this).attr("class","active")}),$("#advanced-search #content-type OL:first>LI").each(function(){$(">LABEL:first",$(this)).prev().bind("click",function(){var n=$(this).next().next();n.css("display",n.css("display")=="block"?"none":"block"),$("INPUT",n).each(function(){$(this).attr("checked",n.css("display")=="block"?!0:!1)})}),$("OL",$(this)).css("display","none"),$(">INPUT:first",$(this)).attr("checked")&&$("OL",$(this)).css("display","block")}),$("<a />").attr({"class":"date-pick"}).html("Choose date").appendTo($("#refining-options FIELDSET:first")),$("<a />").attr({"class":"date-pick"}).html("Choose date").appendTo($("#refining-options FIELDSET:last")),$(".date-search SELECT:first").bind("change",function(){$(".date-search FIELDSET:eq(1)").css("display",$(this).val()=="before"||$(this).val()=="after"?"none":"block")}),$(".date-search .date-pick").each(function(){var n=$(this).parent(),t=$("SELECT:eq(2) OPTION:last",n).val(),i=$("SELECT:eq(2) OPTION:eq(1)",n).val();$(this).datePicker({createButton:!1,startDate:"01/01/"+t,endDate:"31/12/"+i,showYearNavigation:!0}).bind("click",function(){return parliamentUK.main.advancedSearchSelects({selectedDate:$(this).dpGetSelected()[0],calendarWrapper:n}),$(this).dpDisplay(),!1}).bind("dateSelected",function(t,i){parliamentUK.main.advancedSearchSelects({selectedDate:i,calendarWrapper:n})}).bind("dpClosed",function(t,i){parliamentUK.main.advancedSearchSelects({selectedDate:i[0],calendarWrapper:n})}).dpSetPosition($.dpConst.POS_BOTTOM,$.dpConst.POS_RIGHT)}),$(".date-search .date-pick:eq(0)").bind("dpClosed",function(n,t){var i=t[0];i&&(i=new Date(i),$(".date-search .date-pick:eq(1)").dpSetStartDate(i.asString()))}),n.pageType=="main-search-results"&&($("<h4 />").prependTo($("#advanced-search")).append($("<img />").attr({src:"/assets/images/minus-blue.gif",alt:""})).append($("<a />").attr({href:"#"}).html("Hide Advanced Search form")),$("#advanced-search H4 A").bind("click",function(){var t=$(this).parent().parent(),n=$("FIELDSET:first",t).css("display")=="block"?"hide":"show";return t.children("FIELDSET,DIV").css("display",n=="hide"?"none":"block"),$("IMG",$(this).parent()).attr("src",n=="hide"?"/assets/images/plus-blue.gif":"/assets/images/minus-blue.gif"),$(this).html(n=="hide"?"Show Advanced Search form":"Hide Advanced Search form"),!1}),$("#advanced-search H4 A").triggerHandler("click")),i=$(".date-search SELECT:first>option:selected").val(),(i=="before"||i=="after")&&$(".date-search SELECT:first").triggerHandler("change"),isIe6||$("<input />").attr({"class":"clear-all-fields",type:"reset"}).prependTo($(".submission")).val("Clear all fields"),$(".submission INPUT.clear-all-fields").bind("click",function(n){n.preventDefault(),$("FIELDSET").each(function(){$("INPUT[type=text]",$(this)).val(""),$("INPUT[type=checkbox]",$(this)).attr("checked",!1),$("SELECT",$(this)).attr("selectedIndex",0);var n=$("LI.free-text",$(this));$(n).size()==1&&$("INPUT",$(n)).attr("class","").val("Search using Boolean and proximity operators")})})},advancedSearchSelects:function(n){var t=new Date(n.selectedDate);$("SELECT:eq(0) option[value="+t.getDate()+"]",n.calendarWrapper).attr("selected","selected"),$("SELECT:eq(1) option[value="+(t.getMonth()+1)+"]",n.calendarWrapper).attr("selected","selected"),$("SELECT:eq(2) option[value="+t.getFullYear()+"]",n.calendarWrapper).attr("selected","selected")},publicationCalendar:{$outerContainer:null,$container:null,$form:null,$sessionSelect:null,$yearSelect:null,$monthSelect:null,$obj:null,$currentDateTextContainer:null,$currentDateText:null,$dateEventInfoContainer:null,$loaderBar:null,previousDate:null,activeDate:null,asyncLoad:!0,dummyData:!1,useSuppliedData:!0,calendarGenerated:null,addedToDOM:!1,hasInit:!1,pageID:null,pageType:null,urls:{},init:function(n){this.pageID=n.pageRootId,this.pageType=n.availablePageTypes,this.urls.sessionData=n.urls.PublicationSessions,this.urls.eventDates=n.urls.SessionDates,this.urls.eventDetails=n.urls.PublicationDataByDate,this.$outerContainer=$('<div class="datepicker-outer" />'),this.$container=$('<div id="datepicker_'+this.pageID+'" class="datepicker-container" />').appendTo(this.$outerContainer),this.$form=$('<form class="datepicker-form"><table cellpadding="0" cellspacing="0"><thead><tr><td><label for="session-select">Session<\/label><\/td><td><label for="year-select">Year<\/label><\/td><td colspan="3" class="last"><label for="month-select">Month<\/label><\/td><\/tr><\/thead><tbody><tr><td><select class="session-select"><\/select><\/td><td><select class="year-select"><\/select><\/td><td><select class="month-select"><\/select><\/td><td><input type="submit" id="calendar-update" value="Go" class="default" /><\/td><td class="fill"><\/td><\/tr><\/tbody><\/table><\/form>'),this.$container.append(this.$form),this.$sessionSelect=$(".session-select",this.$form).bind("change",function(){parliamentUK.main.publicationCalendar.onFormSessionChanged()}),this.$yearSelect=$(".year-select",this.$form).bind("change",function(){parliamentUK.main.publicationCalendar.onFormYearChanged()}),this.$monthSelect=$(".month-select",this.$form),this.$obj=$('<div class="datepicker" />').appendTo(this.$container),this.$currentDateTextContainer=$('<div class="current-date-text-container" />').appendTo(this.$outerContainer),this.$loaderBar=$('<div class="loader-bar" />').appendTo(this.$currentDateTextContainer),this.$currentDateText=$('<h2 class="current-date" />').appendTo(this.$currentDateTextContainer),this.$dateEventInfoContainer=$('<div class="date-event-info" />').appendTo(this.$outerContainer),this.$form.bind("submit",function(n){n.preventDefault(),parliamentUK.main.publicationCalendar.onFormSubmit()}).prependTo(this.$container),this.sessionManager.parent=this,this.sessionManager.init()},onSessionsInit:function(){var n=this.getHashData();n?(this.sessionManager.setActiveSession(n.sessionID),this.activeDate=n.date):(this.sessionManager.setActiveSession(this.sessionManager.getDefaultSessionID()),this.activeDate=this.sessionManager.activeSession.getDefaultDate()),this.setUrlFragment(),this.initFormSelects(),this.generateCalendar(),this.updatePage(this.activeDate.getTime()),this.bindHashChange(),this.addCalendarToDOM(),this.hasInit=!0},initFormSelects:function(){this.$sessionSelect.append(this.sessionManager.getSelectOptions()),this.$yearSelect.append(this.sessionManager.activeSession.getYearOptions()),this.$monthSelect.append(this.sessionManager.activeSession.getMonthOptions(this.activeDate.getFullYear()))},generateCalendar:function(){var n=$.extend(!0,{},this.baseJqueryCalendarConfig,this.sessionManager.activeSession.getCalendarConfig());this.$obj.datepicker(n),this.calendarGenerated=!0},bindHashChange:function(){$(window).hashchange(function(){parliamentUK.main.publicationCalendar.onHashChange()})},addCalendarToDOM:function(){$(document).ready(function(){var n=$(".datepicker-placeholder:first");n.length&&(n.removeClass("loading").addClass("init").append(parliamentUK.main.publicationCalendar.$outerContainer.css({opacity:0})),parliamentUK.main.publicationCalendar.$outerContainer.animate({opacity:1},1e3),parliamentUK.main.publicationCalendar.addedToDOM=!0)})},updateCurrentDayText:function(){date=this.$obj.datepicker("getDate"),this.$currentDateText.text(date.getDayName()+" "+date.getDate()+" "+date.getMonthName()+" "+date.getFullYear())},onFormSessionChanged:function(){this.updateFormYears()},onFormYearChanged:function(){this.updateFormMonths()},onFormSubmit:function(){if(this.$yearSelect.attr("disabled")||this.$monthSelect.attr("disabled"))return!1;var n=this.$sessionSelect.val(),t=this.$yearSelect.val(),i=this.$monthSelect.val();this.sessionManager.activeSessionID!=n&&this.sessionManager.setActiveSession(n),this.activeDate.getMonth()!=i||this.activeDate.getFullYear()!=t?this.setTheDate(this.sessionManager.activeSession.getDefaultDateFor(t,i)):this.setUrlFragment()},onDateClick:function(n){this.setTheDate(n)},onHashChange:function(){var n=this.getHashData();if(!n)return!1;n.sessionID!=this.sessionManager.activeSessionID&&(this.$sessionSelect.val(n.sessionID),this.sessionManager.setActiveSession(n.sessionID)),n.date.getDate()!=this.activeDate.getDate()&&this.setTheDate(n.date)},getHashData:function(){var u=!0,t=URI.parseQuery((new URI).fragment()),f=["session","year","month","day"],r,n,e;for(i=0;i<f.length;i++)if(!t.hasOwnProperty(f[i])){u=!1;break}return u?(r=new Date(t.year,t.month,t.day),isNaN(r.getTime()))?!1:!t.session in this.sessionManager.sessions?!1:(n=t.session,(typeof this.sessionManager.sessions[n]=="undefined"||this.sessionManager.sessions[n]==null)&&(e=$.map(this.sessionManager.sessions,function(n){return n.ID}),n=Math.max.apply(this,e)),this.sessionManager.sessions[n].checkLoadEventDates(),!this.sessionManager.sessions[n].hasPublicationsIn(r.getFullYear(),r.getMonth(),r.getDate()))?!1:{sessionID:n,date:r}:!1},setUrlFragment:function(){var n=new URI,t=["session="+this.sessionManager.activeSessionID,"year="+this.activeDate.getFullYear(),"month="+this.activeDate.getMonth(),"day="+this.activeDate.getDate()];window.location.hash=n.fragment(t.join("&")).fragment()},setTheDate:function(n){return this.activeDate.getTime()==n.getTime()?!1:(this.previousDate=this.activeDate,this.activeDate=n,this.setUrlFragment(),this.updatePage(),!0)},updatePage:function(){this.$obj.datepicker("setDate",this.activeDate),this.hasInit&&this.previousDate.getFullYear()==this.activeDate.getFullYear()||(this.$yearSelect.val(this.activeDate.getFullYear()),this.updateFormMonths()),this.hasInit&&this.previousDate.getMonth()==this.activeDate.getMonth()||this.$monthSelect.val(this.activeDate.getMonth()),this.updateEventList(),this.updateCurrentDayText()},updateFormYears:function(){var t=this.$sessionSelect.val(),n=this.sessionManager.sessions[t].getYearOptions();n==!1?(n=$("<option>---<\/option>"),this.$yearSelect.attr({disabled:"true"})):this.$yearSelect.removeAttr("disabled"),$("option",this.$yearSelect).remove(),this.$yearSelect.append(n),this.updateFormMonths()},updateFormMonths:function(){var t=this.$sessionSelect.val(),i=this.$yearSelect.val(),n=this.sessionManager.sessions[t].getMonthOptions(i);n==!1?(n=$("<option>---<\/option>"),this.$monthSelect.attr({disabled:"true"})):this.$monthSelect.removeAttr("disabled"),$("option",this.$monthSelect).remove(),this.$monthSelect.append(n),($("html").hasClass("ie8")||$("html").hasClass("ie7"))&&this.$form.prependTo(this.$container)},updateEventList:function(n){var u,t,i,r,f;if(n)this.$dateEventInfoContainer.html(this.processEventListJSONToHTML(n)),this.unsetStateLoading();else{if(this.setStateLoading(),u=this.activeDate.asString("yyyy-mm-dd"),t=this.sessionManager.activeSessionID,t==0)for(ID in this.sessionManager.sessions)if(ID!=0&&this.sessionManager.sessions.hasOwnProperty(ID)&&this.sessionManager.sessions[ID].hasPublicationsIn(this.activeDate.getFullYear(),this.activeDate.getMonth(),this.activeDate.getDate())){t=ID;break}i=this.addedToDOM,r={url:this.dummyData?"/htmlTemplates/calendar-prototype/events.txt?"+(new Date).getTime():this.urls.eventDetails,data:{PageID:this.pageID,PageType:this.pageType,SessionID:t,SessionDate:u},dataType:"json",async:i},i&&(r.success=function(n){n&&parliamentUK.main.publicationCalendar.updateEventList(n)}),f=$.ajax(r),i||(this.$dateEventInfoContainer.html(this.processEventListJSONToHTML($.parseJSON(f.responseText))),this.unsetStateLoading())}},processEventListJSONToHTML:function(n){function i(n,t){function o(){var n=f(i),t='<a href="{0}" rel="external" target="_blank">PDF version<\/a> <img src="/assets/images/pdf-icon.gif" alt="PDF" /><img height="10" class="new-window-icon" src="/assets/images/new-window-icon.gif" alt="Opens in a new window">'.format(r);return n+" | "+t}function f(){return'<a href="{0}">{1}<\/a>'.format(i,t?"<strong>"+u+"<\/strong>":u)}function s(){return'<a href="{0}" rel="external" target="_blank">{1} <img src="/assets/images/pdf-icon.gif" alt="PDF"><img height="10" class="new-window-icon" src="/assets/images/new-window-icon.gif" alt="Opens in a new window"><\/a>'.format(r,t?"<strong>"+u+"<\/strong>":u)}var e;if(!n)return"";var i=n.ContentLinkUrl,r=n.DocumentLink,u=n.Title;return i=i&&i.trim()?i.trim():!1,r=r&&r.trim()?r.trim():!1,i&&i.endsWith(".pdf")&&(e=i,i=r,r=e),i&&r?o():i?f():r?s():""}if(n=n[0],!n)return"";var t="";return n.ContentItems&&n.ContentItems.length&&(t+='<ul class="event-list">',$.each(n.ContentItems,function(){var n=i(this,!0);n&&(t+="<li><h3>"+n+"<\/h3><p>"+this.Teaser+"<\/p><\/li>")}),t+="<\/ul>"),(n.Contents||n.Index)&&(t+='<ul class="meta">',$.each([n.Contents,n.Index],function(){var n=i(this,!1);n&&(t+="<li>"+n+"<\/li>")}),t+="<\/ul>"),n.DocumentItems&&n.DocumentItems.length&&(t+='<ul class="documents square-bullets">',$.each(n.DocumentItems,function(){var n=i(this,!1);n&&(t+="<li>"+n+"<\/li>")}),t+="<\/ul>"),$(t)},setStateLoading:function(){this.$outerContainer.addClass("datepicker-loading")},unsetStateLoading:function(){this.$outerContainer.removeClass("datepicker-loading")},baseJqueryCalendarConfig:{showOtherMonths:!0,selectOtherMonths:!0,beforeShowDay:function(n){var t=parliamentUK.main.publicationCalendar.sessionManager.activeSession,r=n.getFullYear(),u=n.getMonth(),f=n.getDate(),i=t.coversDate(n)&&t.hasPublicationsIn(r,u,f);return[i,i?"content-available":""]},onSelect:function(n){var t=new Date(n);parliamentUK.main.publicationCalendar.onDateClick(t)}},sessionManager:{parent:null,sessions:{},activeSessionID:null,activeSession:null,init:function(){var n={data:{PageID:parliamentUK.main.publicationCalendar.pageID,PageType:parliamentUK.main.publicationCalendar.pageType},dataType:"json",async:this.parent.asyncLoad},t;n.url=this.parent.dummyData?"/htmlTemplates/calendar-prototype/sessions."+(this.parent.useSuppliedData?"b.":"")+"txt":this.parent.urls.sessionData,this.parent.asyncLoad&&(n.success=function(n){parliamentUK.main.publicationCalendar.sessionManager.processSessionJSON(n)}),t=$.ajax(n),this.parent.asyncLoad||this.processSessionJSON($.parseJSON(t.responseText))},processSessionJSON:function(n){n=parliamentUK.main.publicationCalendar.utils.processSessionJSONToSchema(n);for(ID in n)if(n.hasOwnProperty(ID)){var t,i,f=n[ID].longName,r=new Date(parseInt(n[ID].startDate)),u=new Date(parseInt(n[ID].endDate));(!t||r<t)&&(t=r),(!i||u>i)&&(i=u),this.sessions[ID]=new this.sessionObj(ID,f,r,u,this)}this.addAllSession(t,i),this.parent.onSessionsInit()},addAllSession:function(n,t){this.sessions[0]=new this.sessionObj(0,"All",n,t,this)},getDefaultSessionID:function(){var i=new Date,n,t;for(ID in this.sessions)if(this.sessions.hasOwnProperty(ID)&&ID!=0&&this.sessions[ID].coversDate(i)){n=ID;break}return(typeof n=="undefined"||n==null)&&(t=$.map(this.sessions,function(n){return n.ID}),n=Math.max.apply(this,t)),n},setActiveSession:function(n){if(this.activeSessionID=n,this.activeSession=this.sessions[this.activeSessionID],this.activeSession.checkLoadEventDates(),this.parent.calendarGenerated){var t=this.activeSession.getCalendarConfig();this.parent.$obj.datepicker("option",t)}},getAllEventDates:function(){var n={};for(ID in this.sessions)this.sessions.hasOwnProperty(ID)&&ID!=0&&(this.sessions[ID].checkLoadEventDates(),this.sessions[ID].eventDates&&$.extend(!0,n,this.sessions[ID].eventDates));return n},getSelectOptions:function(){var n=[];for(ID in this.sessions)this.sessions.hasOwnProperty(ID)&&n.push({value:ID,label:this.sessions[ID].longName,startDate:this.sessions[ID].startDate});return n.sort(function(n,t){return n.value==0?-1:t.value==0?1:n.startDate>t.startDate?-1:1}),parliamentUK.main.publicationCalendar.utils.generateOptions(n,this.activeSessionID)},sessionObj:function(n,t,i,r,u){this.ID=n,this.longName=t,this.startDate=i,this.endDate=r,this.parent=u,this.eventDatesLoaded=!1,this.eventDates,this.loadEventDates=function(){var n=parliamentUK.main.publicationCalendar,t,i;return t=n.dummyData?"/htmlTemplates/calendar-prototype/event-dates."+(n.useSuppliedData?"b.":"")+""+this.ID+".txt?"+(new Date).getTime():n.urls.eventDates,this.ID==0?this.eventDates=this.parent.getAllEventDates():(i=$.ajax({async:!1,url:t,data:{PageID:n.pageID,PageType:n.pageType,SessionID:this.ID}}).responseText,this.eventDates=n.utils.processSessionDatesJSONToSchema($.parseJSON(i))),this.eventDatesLoaded=!0,!0},this.checkLoadEventDates=function(){this.eventDatesLoaded||this.loadEventDates()},this.getYearOptions=function(){var n;if(this.checkLoadEventDates(),!this.eventDates)return!1;n=[];for(year in this.eventDates)this.eventDates.hasOwnProperty(year)&&n.push({value:year,label:year});return n.sort(function(n,t){return parseInt(t.value)-parseInt(n.value)}),this.parent.parent.utils.generateOptions(n,this.parent.parent.activeDate.getFullYear())},this.getMonthOptions=function(n){if(this.checkLoadEventDates(),!this.eventDates)return!1;var t=[];for(month in this.eventDates[n])this.eventDates[n].hasOwnProperty(month)&&t.push({value:month,label:Date.monthNames[month]});return t.sort(function(n,t){return parseInt(n.value)-parseInt(t.value)}),parliamentUK.main.publicationCalendar.utils.generateOptions(t,this.parent.parent.activeDate.getMonth())},this.getDefaultDate=function(){var n=new Date,t,i,r,u,f;if(!this.parent.hasInit&&this.coversDate(n))if(this.hasPublicationsIn(n.getFullYear(),n.getMonth()))t=n.getFullYear(),i=n.getMonth();else{if(u=this.getNearestPreviousPublicationDate(n),u)return u;if(f=this.getNearestNextPublicationDate(n),f)return f}return this.hasPublicationsIn(n.getFullYear())?(t=n.getFullYear(),i=this.hasPublicationsIn(n.getFullYear(),n.getMonth())?n.getMonth():this.lastPublicationMonth(t)):(t=this.lastPublicationYear(),i=this.lastPublicationMonth(t)),r||(r=this.lastPublicationDay(t,i)),new Date(t,i,r)},this.getNearestPreviousPublicationDate=function(n){years=parliamentUK.main.publicationCalendar.utils._getPropertiesSortedNumerically(this.eventDates,"desc");var t=!1;return that=this,years.length&&$.each(years,function(){return year=parseInt(this),year<=n.getFullYear()&&(months=parliamentUK.main.publicationCalendar.utils._getPropertiesSortedNumerically(that.eventDates[this],"desc"),$.each(months,function(){if(month=parseInt(this),year<n.getFullYear()||month<=n.getMonth())if(month==n.getMonth()){if(index=that.eventDates[year][month].indexOf(n.getDate()),index>0)return t=new Date(year,month,that.eventDates[year][month][index-1]),!1}else return t=new Date(year,month,that.lastPublicationDay(year,month)),!1}),t)?!1:void 0}),t},this.getNearestNextPublicationDate=function(n){years=parliamentUK.main.publicationCalendar.utils._getPropertiesSortedNumerically(this.eventDates,"asc");var t=!1;return that=this,years.length&&$.each(years,function(){return year=parseInt(this),year>=n.getFullYear()&&(months=parliamentUK.main.publicationCalendar.utils._getPropertiesSortedNumerically(that.eventDates[this],"asc"),$.each(months,function(){if(month=parseInt(this),year>n.getFullYear()||month>=n.getMonth())if(month==n.getMonth()){if(index=that.eventDates[year][month].indexOf(n.getDate()),index<that.eventDates[year][month]-1)return t=new Date(year,month,that.eventDates[year][month][index+1]),!1}else return t=new Date(year,month,that.firstPublicationDay(year,month)),!1}),t)?!1:void 0}),t},this.getDefaultDateFor=function(n,t){var i=new Date;return t||(t=n==i.getFullYear()?this.hasPublicationsIn(i.getFullYear(),i.getMonth())?i.getMonth():this.lastPublicationMonth(n):this.firstPublicationMonth(n)),new Date(n,t,this.firstPublicationDay(n,t))},this.coversDate=function(n){return n>=this.startDate&&n<=this.endDate?!0:!1},this.hasPublicationsIn=function(n,t,i){if(!this.eventDates)return!1;var r,u;return(r=n in this.eventDates,!r||t==null)?r:(u=t in this.eventDates[n],!u||i==null)?u:this.eventDates[n][t].indexOf(i)>-1},this.lastPublicationYear=function(){return parliamentUK.main.publicationCalendar.utils.lastPropertyNumerically(this.eventDates)},this.firstPublicationYear=function(){return parliamentUK.main.publicationCalendar.utils.firstPropertyNumerically(this.eventDates)},this.lastPublicationMonth=function(n){return parliamentUK.main.publicationCalendar.utils.lastPropertyNumerically(this.eventDates[n])},this.firstPublicationMonth=function(n){return parliamentUK.main.publicationCalendar.utils.firstPropertyNumerically(this.eventDates[n])},this.lastPublicationDay=function(n,t){var i=this.eventDates[n][t].length-1;return this.eventDates[n][t][i]},this.firstPublicationDay=function(n,t){return this.eventDates[n][t][0]},this.getCalendarConfig=function(){return{minDate:this.startDate,maxDate:this.endDate}}}},utils:{processSessionJSONToSchema:function(n){return parliamentUK.main.publicationCalendar.useSuppliedData?n?(myJSON={},$.each(n,function(){myJSON[this.SessionId]={startDate:parseInt(this.FromDate.substr(6)),endDate:parseInt(this.ToDate.substr(6)),longName:this.LongTitle}}),myJSON):!1:n},processSessionDatesJSONToSchema:function(n){return parliamentUK.main.publicationCalendar.useSuppliedData?n?(myJSON={},$.each(n,function(){var n=this.Year;myJSON[n]={},$.each(this.Months,function(){myJSON[n][this.Mon-1]=this.Days})}),myJSON):!1:n},generateOptions:function(n,t){return optionEls="",$.each(n,function(){optionEls+='<option value="'+this.value+'"',typeof t!="undefined"&&this.value==t&&(optionEls+=" selected"),optionEls+=">"+this.label+"<\/option>"}),$(optionEls)},firstPropertyNumerically:function(n){return this._getPropertiesSortedNumerically(n,"asc")[0]},lastPropertyNumerically:function(n){return this._getPropertiesSortedNumerically(n,"desc")[0]},_getPropertiesSortedNumerically:function(n,t){t!="asc"&&t!="desc"&&t=="asc";var r=[];for(i in n)n.hasOwnProperty(i)&&r.push(i);return r.sort(function(n,i){return t=="asc"?n-i:i-n})}}}}