var ListItem = {
	_backgroundColors: ['#d9a6d2', '#a3bce3', '#93cac4', '#95a6bd', '#bf9eda'],
	
	_currentBackgroundColorIndex: -1,
	
	getTopPickMovie: function(data) {
		return ListItem._getItem(Style.topPickMovieImageHeight, data);
	},
	
	getTopPickTvShow: function(data) {
		var item = ListItem._getItem(Style.topPickTvImageHeight, data);
		item.getChildren()[1].getChildren()[1].destroy();
		return item;
	},
	
	getMovie: function(data) {
		return ListItem._getItem(Style.movieImageHeight, data);
	},
	
	getTvShow: function(data) {
		return ListItem._getItem(Style.tvImageHeight, data);
	},
	
	_getItem: function(imageHeight, data) {
		var item = ListItem.getItemLayout();
	    var image = ListItem.getItemImage(data.thumbnailUrl);
	    var description = ListItem.getItemDescription();
	    var title = ListItem.getItemDescriptionTitle(data.title);
	    var summary = ListItem._getItemDescriptionSummary(data.publishYear || data.startTime);
	    
	    item.addChild(image, {
	    	size: ['100%', imageHeight]
	    });
	    
	    item.addChild(description, {
	    	size: ['100%', Style.descriptionHeight + Style.descriptionMarginTop]
	    });
	    
	    item.addChild(ListItem.getFocusLayer());
	    
	    description.addChild(title, {
	    	size: ['95%', Style.descriptionHeight / 2]
	    });
	    
	    description.addChild(summary, {
	    	size: ['95%', Style.descriptionHeight / 2]
	    });
		
		return ListItem.setCommonProperty(item, data);
	},
	
	getItemLayout: function() {
		var Linear = caph.require('ui.base.layout.Linear');
		
		return new Linear({
			direction: Linear.LayoutParam.VERTICAL,
			dom: {
				style: {
					overflow: 'hidden'
				}
			}
		}); 
	},
	
	getItemImage: function(thumbnailUrl) {
		var View = caph.require('module.renderer.View');
		
		return new View({
			dom: {
				style: {
					backgroundColor: Style.getBackgroundColor(),
					overflow: 'hidden'
				}
			}
		}).addChild(new caph.module.renderer.View({
			dom: {
				style: {
					width: '100%',
					height: '100%',
					background: 'url("' + Style.movieImageRootPath + thumbnailUrl + '") no-repeat center center',
					opacity: 0.2
				}
			}
		}));
	},
	
	getItemDescription: function() {
		var Linear = caph.require('ui.base.layout.Linear');
		
		return new Linear({
			direction: Linear.LayoutParam.VERTICAL
		});
	},
	
	getItemDescriptionTitle: function(title) {
		var Label = caph.require('ui.base.component.Label');
		
		var title = new caph.ui.base.component.Label({
			text: title,
		    align: {
		    	horizontal: 'left',
		    	vertical: 'center'
		    }
		});
		
		title.setMultiLine(false);
		title.setEllipsis(true);
		title.setTextColor(Style.fontColorNormal);
		title.setTextSize(Style.descriptionTitleFontSize);
		title.setStyle({
			left: Style.descriptionHorizontalPadding + 'px',
			top: Style.descriptionMarginTop + 'px',
			opacity: 0.8
		});
		
		return title;
	},
	
	_getItemDescriptionSummary: function(summary) {
		var summary = new caph.ui.base.component.Label({
			text: summary,
		    align: {
		    	horizontal: 'left',
		    	vertical: 'center'
		    }
		});
		
		summary.setMultiLine(false);
		summary.setEllipsis(true);
		summary.setTextFont(Style.descriptionSummaryFontSize + '"SamsungSmart_Latin Medium"');
		summary.setTextColor(Style.fontColorNormal);
		summary.setStyle({
			left: Style.descriptionHorizontalPadding + 'px',
			top: Style.descriptionMarginTop + 'px',
			opacity: 0.6
		});
		
		return summary;
	},
	
	getFocusLayer: function() {
		return new caph.module.renderer.View({
			dom: {
				style: {
					visibility: 'hidden',
					boxSizing: 'border-box',
					borderWidth: Style.listBorderWidth,
					borderImage: Style.listBorderImage
				}
			}
		});
	},
	
	setCommonProperty: function(item, data) {
		item.setProperty({
			id: data.id,
			genreId: data.genreId
		});
		
		return item;
	},
	
	getBackgroundColor: function() {
		ListItem._currentBackgroundColorIndex = (ListItem._currentBackgroundColorIndex + 1) % ListItem._backgroundColors.length;
		return ListItem._backgroundColors[ListItem._currentBackgroundColorIndex];
	}
}
