
Ext.apply(Ext.ux.application.config,{urlApiThemes:URL_BASE+"/get/page/accueil/MainThemes",urlApiAutresFresques:URL_BASE+"/get/page/accueil/ListeFresques",sizeImgTheme:[45,34]});Ext.apply(Ext.ux.application,{otherInit:function(){this.hideRightColumn();Ext.select("div.themes-panel").each(this.setupThemesPanel,this);Ext.select("div.ext-template").each(this.setupTemplates.createDelegate(this));this.formatFresquesSlideShow();},setupTemplates:function(tplEl){var ws=tplEl.select(".ws-url").first();var params=tplEl.select(".ws-params").first();var tpl=tplEl.select(".template").first();if(!ws||Ext.isEmpty(ws.dom.innerHTML)||!tpl)return;var parameters={};if(params)
params.select("> div").each(function(p){if(p)
parameters[p.getAttribute("class")||p.getAttribute("className")]=p.dom.innerHTML;},this);Ext.Ajax.request({url:ws.dom.innerHTML,method:"GET",params:parameters,success:this.onDataForTemplateReceived.createDelegate(this,[new Ext.Template(decodeURI(tpl.dom.innerHTML),{compiled:true}),tplEl.parent()],true)});Ext.removeNode(tplEl.dom);},onDataForTemplateReceived:function(tsp,opts,tpl,el){var tplParams=Ext.util.JSON.decode(tsp.responseText);Ext.each(tplParams,function(tplParam){tpl.insertFirst(el,tplParam);},this);},setupThemesPanel:function(el){this.themeElFly=el;this.themesStore=new Ext.data.JsonStore({autoLoad:{url:this.config.urlApiThemes,callback:this.onThemesRecus,scope:this},url:this.config.urlApiThemes,root:"themes",idProperty:"theme",fields:["theme","link","imgs"]});},onThemesRecus:function(){var totalWidth=this.themeElFly.getWidth()-15;var count=this.themesStore.getCount();this.themesContainer=new Ext.Panel({renderTo:this.themeElFly,layout:"hbox",width:totalWidth,border:false})
this.themesStore.each(function(record,panelIndex){var panel=new Ext.Panel({baseCls:"ux-theme-panel",link:record.get("link"),title:"<a href=\""+record.get("link")+"\">"+record.get("theme")+"</a>",width:Math.ceil(totalWidth/count),height:this.config.sizeImgTheme[1]*(record.get("imgs").length/2)});Ext.each(record.get("imgs"),function(img,imgIndex){var image=new Ext.BoxComponent({autoEl:{tag:"img",cls:"ux-theme-panel-img",width:this.config.sizeImgTheme[0],height:this.config.sizeImgTheme[1],src:img}});this.themesContainer.add(panel);this.themesContainer.doLayout();panel.el.on('click',(function(url){window.location=url;}).createDelegate(this,[record.get("link")]));panel.el.on('mouseover',(function(panel){panel.addClass("ux-img-transition");}).createDelegate(this,[panel]));panel.el.on('mouseout',(function(panel){panel.removeClass("ux-img-transition");}).createDelegate(this,[panel]));panel.add(image);panel.doLayout();var imgXDirection=(imgIndex%2)==0?1:-1;var imgYDirection=(imgIndex>4)==0?-1:1;image.el.setXY([panel.el.getX()+((panel.getWidth()-image.getWidth())/2)+(Math.random()*(image.getWidth()/1.5)*imgXDirection),panel.el.getY()+((panel.getHeight()-image.getHeight())/2)+(Math.random()*(image.getHeight()/1.5)*imgYDirection)]);},this);},this);},formatFresquesSlideShow:function(config){if(Ext.get("slideshow")){Ext.ComponentMgr.create({xtype:"ux-slideshow",renderTo:Ext.get("slideshow"),urlViews:this.config.urlApiAutresFresques});}}});

