/**
 * All intellectual property rights in this Software throughout the world belong to UK Radioplayer, 
 * rights in the Software are licensed (not sold) to subscriber stations, and subscriber stations 
 * have no rights in, or to, the Software other than the right to use it in accordance with the 
 * Terms and Conditions at www.radioplayer.co.uk/terms. You shall not produce any derivate works 
 * based on whole or part of the Software, including the source code, for any other purpose other 
 * than for usage associated with connecting to the UK Radioplayer Service in accordance with these 
 * Terms and Conditions, and you shall not convey nor sublicense the Software, including the source 
 * code, for any other purpose or to any third party, without the prior written consent of UK Radioplayer.
 *
 * @name StationIconFactory
 * @description creates a preset object
 *
 *
 * @authors Mike Colley <michael.colley@bbc.co.uk>
 * @authors Sergejs Vaskevics <sergejs.vaskevics@ubcmedia.com>
 */

radioplayer.models.StationIconFactory = function() {};

radioplayer.models.StationIconFactory.prototype = {		
		createPresetFromStationData: function( stationData, isLastPlayed, isCurrentStation ) {
			var preset = glow.dom.create("<div class='station-icon'></div>");			
			
			preset.append(this._getImageNode(stationData));
	
			if (!isLastPlayed) {
				if (stationData.stationID) {
					preset.attr('id', 'station_' + stationData.stationID);
				}
				
				preset.addClass('preset');
				this._appendOverlaysToPreset(preset, stationData, isCurrentStation);
			}else{
				preset.attr('id', 'last-played-station-icon');
			}
			
			preset.data(stationData);
			return preset;
		},
		
		_createLastSavedPreset: function( lastplayedData, isCurrentStation ) {
			return this.createPresetFromStationData(lastplayedData, true);
		},
			
		
		_getImageNode: function( stationData ) {
			var imageTag = "<span class='station-underlay'><a href='" + stationData.playerUrl + "' title='Play " + stationData.name + "' class='station-link' style='background-image:url(" + stationData.logoUrl + ");'><span class='station-play-icon'></span><span class='station-overlay'></span></a></span>",
				imageNode = glow.dom.create(imageTag);
			return imageNode;
		},
		
		
		_appendOverlaysToPreset: function( presetIconNode, stationData, isCurrentStation ) {			
			presetIconNode.append(
					glow.dom.create('<div class="station-close-button show-on-edit" title="Remove '+ stationData.name +'" id="remove_station_' + stationData.stationID + '"><span></span></div>')
					);
			if(!(glow.env.ie==6)){
				presetIconNode.append(
					glow.dom.create('<div class="icon-overlay station-object-handle"></div>')
				);	
			}	
		
			if (isCurrentStation) {
				presetIconNode.append(
					glow.dom.create('<div class="icon-overlay current-station-overlay hide-on-edit"><div></div></div>')
				);	
			}
			return presetIconNode;
		},
		
		createCurrentProgrammeTooltip: function(text) {
			if(text.length > 105) {
				text = text.substring(0,105) + "...";
			}
			var tooltipMarkup = '<div id="current-programme-tipbox" class="tipbox-container">'+
									'<div class="tipbox-inner">' +
										'<p><span class="bold">LIVE: </span>'+ text +'</p>'+
									'</div>' +					
								'</div>',
				markupParent = glow.dom.create('<div></div>'),
				tooltip = glow.dom.create(tooltipMarkup);
			markupParent.append(tooltip);
			return tooltip;
		},	

		
		createEmptyPlaceholder: function() {
			var emptyPlaceholder = glow.dom.create("<div class='station-icon station-placeholder'></div>"),
			emptyPlaceholderIcon = glow.dom.create("<p class='station-placeholder-marker'></p>");
			emptyPlaceholder.append(emptyPlaceholderIcon);
			return emptyPlaceholder;
		}

};

