define(["lazyLoader","imageFetcher","layoutManager","browser","appSettings","require","css!./style"],function(lazyLoader,imageFetcher,layoutManager,browser,appSettings,require){"use strict";functionfillImage(elem,source,enableEffects){if(!elem)thrownewError("elem cannot be null");source||(source=elem.getAttribute("data-src")),source&&fillImageElement(elem,source,enableEffects)}functionfillImageElement(elem,source,enableEffects){imageFetcher.loadImage(elem,source).then(function(){varfillingVibrant=fillVibrant(elem,source);!enableFade||layoutManager.tv||enableEffects===!1||fillingVibrant||fadeIn(elem),elem.removeAttribute("data-src")})}functionfillVibrant(img,url,canvas,canvasContext){varvibrantElement=img.getAttribute("data-vibrant");return!!vibrantElement&&(window.Vibrant?(fillVibrantOnLoaded(img,url,vibrantElement,canvas,canvasContext),!0):(require(["vibrant"],function(){fillVibrantOnLoaded(img,url,vibrantElement,canvas,canvasContext)}),!0))}functionfillVibrantOnLoaded(img,url,vibrantElement){vibrantElement=document.getElementById(vibrantElement),vibrantElement&&requestIdleCallback(function(){getVibrantInfoFromElement(img,url).then(function(vibrantInfo){varswatch=vibrantInfo.split("|");if(swatch.length){varindex=0,style=vibrantElement.style;style.backgroundColor=swatch[index],style.color=swatch[index+1];varclassList=vibrantElement.classList;classList.contains("cardFooter")?classList.add("cardFooter-vibrant"):classList.add("vibrant")}})})}functiongetVibrantInfoFromElement(elem,url){returnnewPromise(function(resolve,reject){require(["vibrant"],function(){if("IMG"===elem.tagName)returnvoidresolve(getVibrantInfo(elem,url));varimg=newImage;img.onload=function(){resolve(getVibrantInfo(img,url))},img.src=url})})}functiongetSettingsKey(url){varparts=url.split("://");url=parts[parts.length-1],url=url.substring(url.indexOf("/")+1),url=url.split("?")[0];varcacheKey="vibrant31";returncacheKey+url}functiongetCachedVibrantInfo(url){returnappSettings.get(getSettingsKey(url))}functiongetVibrantInfo(img,url){varvalue=getCachedVibrantInfo(url);if(value)returnvalue;varvibrant=newVibrant(img),swatches=vibrant.swatches();value="";varswatch=swatches.DarkVibrant;returnvalue+=getSwatchString(swatch),appSettings.set(getSettingsKey(url),value),value}functiongetSwatchString(swatch){returnswatch?swatch.getHex()+"|"+swatch.getBodyTextColor()+"|"+swatch.getTitleTextColor():"||"}functionfadeIn(elem){varcssClass=layoutManager.tv?"lazy-image-fadein-fast":"lazy-image-fadein";elem.classList.add(cssClass)}functionlazyChildren(elem){lazyLoader.lazyChildren(elem,fillImage)}functiongetPrimaryImageAspectRatio(items){for(varvalues=[],i=0,length=items.length;i<length;i++){varratio=items[i].PrimaryImageAspectRatio||0;ratio&&(values[values.length]=ratio)}if(!values.length)returnnull;values.sort(function(a,b){returna-b});varresult,half=Math.floor(values.length/2);result=values.length%2?values[half]:(values[half-1]+values[half])/2;varaspect2x3=2/3;if(Math.abs(aspect2x3-result)<=.15)returnaspect2x3;varaspect16x9=16/9;if(Math.abs(aspect16x9-result)<=.2)returnaspect16x9;if(Math.abs(1-result)<=.15)return1;varaspect4x3=4/3;returnMath.abs(aspect4x3-result)<=.15?aspect4x3:result}functionfillImages(elems){for(vari=0,length=elems.length;i<length;i++){varelem=elems[0];fillImage(elem)}}varrequestIdleCallback=window.requestIdleCallback||function(fn){fn()},self={},enableFade=!browser.slow;returnself.fillImages=fillImages,self.lazyImage=fillImage,self.lazyChildren=lazyChildren,self.getPrimaryImageAspectRatio=getPrimaryImageAspectRatio,self.getCachedVibrantInfo=getCachedVibrantInfo,self.getVibrantInfoFromElement=getVibrantInfoFromElement,self});