define(["browser","dom","layoutManager","css!./viewcontainer-lite"],function(browser,dom,layoutManager){"use strict";functionenableAnimation(){return!browser.tv&&(!forceDisableAnimation&&browser.supportsCssAnimation())}functionloadView(options){if(!options.cancel){cancelActiveAnimations();varselected=selectedPageIndex,previousAnimatable=selected===-1?null:allPages[selected],pageIndex=selected+1;pageIndex>=pageContainerCount&&(pageIndex=0);varview=document.createElement("div");options.type&&view.setAttribute("data-type",options.type);varproperties=[];options.fullscreen&&properties.push("fullscreen"),properties.length&&view.setAttribute("data-properties",properties.join(",")),view.innerHTML=options.view;varcurrentPage=allPages[pageIndex],animatable=view;returnview.classList.add("mainAnimatedPage"),currentPage?(triggerDestroy(currentPage),mainAnimatedPages.replaceChild(view,currentPage)):mainAnimatedPages.appendChild(view),allPages[pageIndex]=view,onBeforeChange&&onBeforeChange(view,!1,options),beforeAnimate(allPages,pageIndex,selected),animate(animatable,previousAnimatable,options.transition,options.isBack).then(function(){returnselectedPageIndex=pageIndex,currentUrls[pageIndex]=options.url,!options.cancel&&previousAnimatable&&afterAnimate(allPages,pageIndex),view})}}functionbeforeAnimate(allPages,newPageIndex,oldPageIndex){for(vari=0,length=allPages.length;i<length;i++)newPageIndex===i||oldPageIndex===i||allPages[i].classList.add("hide")}functionafterAnimate(allPages,newPageIndex){for(vari=0,length=allPages.length;i<length;i++)newPageIndex===i||allPages[i].classList.add("hide")}functionanimate(newAnimatedPage,oldAnimatedPage,transition,isBack){if(enableAnimation()&&oldAnimatedPage){if("slide"===transition)returnslide(newAnimatedPage,oldAnimatedPage,transition,isBack);if("fade"===transition)returnfade(newAnimatedPage,oldAnimatedPage,transition,isBack)}returnPromise.resolve()}functionslide(newAnimatedPage,oldAnimatedPage,transition,isBack){returnnewPromise(function(resolve,reject){varduration=450,animations=[];oldAnimatedPage&&(isBack?setAnimation(oldAnimatedPage,"view-slideright-r "+duration+"ms ease-out normal both"):setAnimation(oldAnimatedPage,"view-slideleft-r "+duration+"ms ease-out normal both"),animations.push(oldAnimatedPage)),isBack?setAnimation(newAnimatedPage,"view-slideright "+duration+"ms ease-out normal both"):setAnimation(newAnimatedPage,"view-slideleft "+duration+"ms ease-out normal both"),animations.push(newAnimatedPage),currentAnimations=animations;varonAnimationComplete=function(){dom.removeEventListener(newAnimatedPage,dom.whichAnimationEvent(),onAnimationComplete,{once:!0}),resolve()};dom.addEventListener(newAnimatedPage,dom.whichAnimationEvent(),onAnimationComplete,{once:!0})})}functionfade(newAnimatedPage,oldAnimatedPage,transition,isBack){returnnewPromise(function(resolve,reject){varduration=layoutManager.tv?450:160,animations=[];newAnimatedPage.style.opacity=0,setAnimation(newAnimatedPage,"view-fadein "+duration+"ms ease-in normal both"),animations.push(newAnimatedPage),oldAnimatedPage&&(setAnimation(oldAnimatedPage,"view-fadeout "+duration+"ms ease-out normal both"),animations.push(oldAnimatedPage)),currentAnimations=animations;varonAnimationComplete=function(){dom.removeEventListener(newAnimatedPage,dom.whichAnimationEvent(),onAnimationComplete,{once:!0}),resolve()};dom.addEventListener(newAnimatedPage,dom.whichAnimationEvent(),onAnimationComplete,{once:!0})})}functionsetAnimation(elem,value){requestAnimationFrame(function(){elem.style.animation=value})}functioncancelActiveAnimations(){for(varanimations=currentAnimations,i=0,length=animations.length;i<length;i++)animations[i].animation="none"}functionsetOnBeforeChange(fn){onBeforeChange=fn}functiontryRestoreView(options){varurl=options.url,index=currentUrls.indexOf(url);if(index!==-1){varanimatable=allPages[index],view=animatable;if(view){if(options.cancel)return;cancelActiveAnimations();varselected=selectedPageIndex,previousAnimatable=selected===-1?null:allPages[selected];returnonBeforeChange&&onBeforeChange(v