define(["itemShortcuts","itemHelper","backdrop","mediaInfo","browser","layoutManager","dom","userSettings","connectionManager","skinManager"],function(itemShortcuts,itemHelper,backdrop,mediaInfo,browser,layoutManager,dom,userSettings,connectionManager,skinManager){"use strict";var selectedItemInfoElementHasContent;return function(options){var focusedElement,parent=options.parent;layoutManager.tv&&(dom.addEventListener(parent,"focus",onFocusIn,{capture:!0,passive:!0}),dom.addEventListener(parent,"blur",onFocusOut,{capture:!0,passive:!0}));var selectedItemInfoTimeout,selectedItemInfoElement=options.selectedItemInfoElement;function onFocusIn(e){var focused=e.target;(focusedElement=focused)&&selectedItemInfoElement&&(clearSelectedInfoTimer(),selectedItemInfoTimeout=setTimeout(onSelectedInfoTimeout,500))}function onFocusOut(e){clearSelectedInfoTimer(),selectedItemInfoElement&&selectedItemInfoElementHasContent&&requestAnimationFrame(clearSelectedItemInfo);focusedElement=null}function clearSelectedInfoTimer(){selectedItemInfoTimeout&&clearTimeout(selectedItemInfoTimeout)}function onSelectedInfoTimeout(){focusedElement&&function(card){if(!1!==options.enableBackdrops||selectedItemInfoElement){var item=itemShortcuts.getItemFromChildNode(card,!0);if(!item||!item.ServerId||item.IsCategory)return;!1!==options.enableBackdrops&&userSettings.enableBackdrops()&&(browser.tv||browser.xboxOne||backdrop.setBackdrop(item)),function(card,item){if(!selectedItemInfoElement)return;var html="",logoImageUrl=function(item,options){options=options||{};var logoTypes=skinManager.getPreferredLogoImageTypes();return connectionManager.getApiClient(item).getLogoImageUrl(item,options,logoTypes)}(item,{});logoImageUrl&&(html+='<div class="selectedItemInfoLogo" style="background-image:url(\''+logoImageUrl+"');\"></div>");var mediaInfoHtml="Program"===item.Type?mediaInfo.getSecondaryMediaInfoHtml(item):mediaInfo.getPrimaryMediaInfoHtml(item);html+='<div class="selectedItemInfoDetails">',html+='<div class="selectedItemName">',item.AlbumArtist&&(html+=item.AlbumArtist+" - ");item.IsSeries?html+=item.Name:html+=itemHelper.getDisplayName(item);html+="</div>",mediaInfoHtml&&(html+='<div class="selectedItemMediaInfo">',html+=mediaInfoHtml,html+="</div>");html+="</div>",selectedItemInfoElement.innerHTML=html,selectedItemInfoElementHasContent=!0;var rect=card.getBoundingClientRect(),left=Math.min(rect.left,.8*dom.getWindowSize().innerWidth);selectedItemInfoElement.style.left=Math.max(left,70)+"px",html&&selectedItemInfoElement.animate&&function(elem){elem.animate([{opacity:"0",offset:0},{opacity:"1",offset:1}],{duration:140,iterations:1,easing:"ease-out"})}(selectedItemInfoElement)}(card,item)}}(focusedElement)}function clearSelectedItemInfo(){selectedItemInfoElement.innerHTML="",selectedItemInfoElementHasContent=!1}this.destroy=function(){dom.removeEventListener(parent,"focus",onFocusIn,{capture:!0,passive:!0}),dom.removeEventListener(parent,"blur",onFocusOut,{capture:!0,passive:!0}),selectedItemInfoElement&&(selectedItemInfoElement.innerHTML="")}}});