define(["lazyLoader","require"],function(lazyLoader,require){"use strict";var supportsNativeLazyLoading="loading"in HTMLImageElement.prototype;(supportsNativeLazyLoading=!1)||require(["css!./imageloader"]);var self={};function fillImage(elem,source){if(source||!supportsNativeLazyLoading){if("IMG"===elem.tagName)return elem.setAttribute("src",source||elem.getAttribute("data-src")),void elem.removeAttribute("data-src");source&&(elem.style.backgroundImage="url('"+source+"')"),elem.classList.remove("lazy")}}function getPrimaryImageAspectRatio(items,options){for(var values=[],i=0,length=items.length;i<length;i++){var item=items[i],imageItem=options&&options.showCurrentProgramImage?item.CurrentProgram||item:item.ProgramInfo||item,ratio=imageItem.PrimaryImageAspectRatio||0;ratio&&(values[values.length]=ratio)}if(!values.length)return null;values.sort(function(a,b){return a-b});var half=Math.floor(values.length/2),result=values.length%2?values[half]:(values[half-1]+values[half])/2;if(Math.abs(2/3-result)<=.1666667)return 2/3;if(Math.abs(16/9-result)<=.222222)return 16/9;return Math.abs(4/3-result)<=.2?4/3:Math.abs(1-result)<=.1666667?1:result}function getShapeFromAspect(primaryImageAspectRatio){return primaryImageAspectRatio?3<=primaryImageAspectRatio?"banner":1.4<=primaryImageAspectRatio?"backdrop":1.2<primaryImageAspectRatio?"fourThree":.71<primaryImageAspectRatio?"square":"portrait":null}self.fillImages=function(elems){if(!supportsNativeLazyLoading)for(var i=0,length=elems.length;i<length;i++){fillImage(elems[0])}},self.lazyImage=fillImage,self.lazyChildren=function(elem){supportsNativeLazyLoading||lazyLoader.lazyChildren(elem,fillImage)},self.getPrimaryImageAspectRatio=getPrimaryImageAspectRatio,self.getShape=function(items,options){return getShapeFromAspect(getPrimaryImageAspectRatio(items,options))||(options.defaultShape||function(items){var firstItem=items[0];if(firstItem)switch(firstItem.Type){case"Movie":case"SeriesTimer":return"portrait";case"Episode":case"Program":case"Video":return"backdrop"}return"square"}(items))},self.getAspectFromShape=function(shape,options){if(shape){if(shape.includes("ortrait"))return{aspect:2/3,aspectCss:"2/3"};if(shape.includes("ackdrop"))return{aspect:16/9,aspectCss:"16/9"};if(shape.includes("quare"))return{aspect:1,aspectCss:"1"};if(shape.includes("ourThree"))return{aspect:4/3,aspectCss:"4/3"};if(shape.includes("anner"))return options.sideFooter?{aspect:1,aspectCss:"1"}:{aspect:1e3/185,aspectCss:"1000/185"}}return{}},self.getShapeFromAspect=getShapeFromAspect;return self.getCoveredImageClass=function(item,itemAspect,uiAspect,force){var imageClass=null;if(force||Math.abs(itemAspect-uiAspect)<=.28){imageClass=" coveredImage";var itemType=item.Type;return"TvChannel"===itemType?imageClass+=" coveredImage-contain":"PhotoAlbum"!==itemType&&"Folder"!==itemType&&"Program"!==itemType&&"Recording"!==itemType&&"Photo"!==item.MediaType||(imageClass+=" coveredImage-noScale"),imageClass}},self});