﻿
Ext.onReady(function(){var state=JSON.parse(Ext.get('initial-state').dom.value)||{data:[]};this.m_cs=new CaseStudies({data:Ext.apply(state,{totalResults:state.data.length}),csWrapper:state.caseStudyWrapper,wrapperEl:Ext.get('caseStudyContainer')});});Ext.extend(CaseStudies=function(config){Ext.apply(this,config||{});if(!this.wrapperEl){return;}
var forLoopString='[';for(var i=0;i<this.data.totalResults-1;i++){forLoopString+=i+', ';}
forLoopString+=(this.data.totalResults-1)+']';var tpl=new Ext.XTemplate('<tpl for=".">','<div'+String.format(this.csWrapper,'{id}')+'>','<h2>{title}</h2>','<div class="caseSummary">','<tpl if="videoCode">','<div class="mediaContainer">{videoCode}</div>','</tpl>','<tpl if="!videoCode && summaryImg">','<img src="{summaryImg}" alt="{summaryImgAlt}" class="rightPadded"/>','</tpl>','{highlights}','<tpl if="this.hasTextLength(body)">','<a href="/climatesmart/cms/CaseStudy.acds?i={id}" class="moreLink">read more&gt;&gt;</a>','</tpl>','<div class="clear"/>','</div>','</div>','</tpl>','<div id="caseStudyFooter">','<div class="footerPaging">','<a onclick="window.m_cs.pageTo(\'prev\', this, event);" href="#">&lt;</a>','<tpl for="'+forLoopString+'">','<tpl if="this.isSelectedPage(xindex);">','<a class="selected-page" onclick="window.m_cs.pageTo({#}, this, event);" href="#">{#}</a>','</tpl>','<tpl if="!this.isSelectedPage(xindex);">','<a onclick="window.m_cs.pageTo({#}, this, event);" href="#">{#}</a>','</tpl>','</tpl>','<a onclick="window.m_cs.pageTo(\'next\', this, event);" href="#">&gt;</a>','</div>','<div class="footerCaption">Climate Smart success stories</div>','</div>',{hasTextLength:function(html){if(!html){return false;}
var test=document.createElement('div');test.innerHTML=html;return(test.textContent||test.innerText||'').trim().length>0;},isSelectedPage:function(index){return index===(window.m_cs?window.m_cs.curPage:1);}});this.store=new Ext.ux.data.JsonPagingStore({root:'data',totalProperty:'totalResults',pageSize:1},this.designRecord(this.data.data[0]));this.dataView=new Ext.DataView({applyTo:this.wrapperEl,store:this.store,tpl:tpl,autoHeight:true,itemSelector:'',style:Ext.isIE?{}:{'padding-left':'10px'}});this.toolbar=new Ext.ux.JayrockPagingStoreToolbar({store:this.store});this.store.loadData(this.data);},Ext.util.Observable,{designRecord:function(dataObj){var fields=[];for(var i in dataObj){fields.push({name:i});}
return Ext.data.Record.create(fields);},curPage:1,pageTo:function(toPage,el,e){if(e.preventDefault){e.preventDefault();}else{e.returnValue=false;}
switch(toPage){case"first":toPage=1;break;case"prev":toPage=Math.max(1,this.curPage-1);break;case"next":toPage=Math.min(this.curPage+1,this.store.getTotalCount());break;case"last":toPage=this.store.getTotalCount();break;case"refresh":toPage=this.curPage;break;}
if(!isNaN(toPage)){this.curPage=toPage;this.toolbar.changePage(toPage);}
if(window.wrapContent){window.wrapContent(this.wrapperEl.dom);}},end_of_module:true});