// create namespace
Ext.namespace('com.evoca.players', 'com.evoca.players.util');

var userID;

/**
  * PlayerViewPanel
  */
com.evoca.players.renderPlayerGrid = function(divID, userIDParam) {
	// Initialize quicktips
	Ext.QuickTips.init();
			
	Ext.apply(Ext.QuickTips.getQuickTip(), {
		maxWidth: 200,
		minWidth: 100,
		showDelay: 50,
		trackMouse:  true
	});
			
	userID = userIDParam;
	
	var playerUtils = new com.evoca.players.PlayerUtils();

	this.playerStore = new Ext.data.Store({
		url: '../Request?action=getPlayers&userID=1581',
		autoLoad: true,
		reader: new com.evoca.players.PlayerListXMLReader({
			record : 'player',
			totalRecords: 'totalPlayers'
		}, playerUtils.createPlayerRecord())
	});

	var deleteColumn = new com.evoca.players.DeleteColumn({
		id: 'delete',
		width: 40,
		header: "Delete"
	});
	
	var configureColumn = new com.evoca.players.ConfigureColumn({
		id: 'config',
		width: 27,
		scope: this,
		header: 'Edit'
	});
	
	var showHTMLColumn = new com.evoca.players.ShowHTMLColumn({
		id: 'showhtml',
		header: 'Get HTML Code',
		width: 85,
		scope: this
	});	
	
	var cm = new Ext.grid.ColumnModel([
		configureColumn,
		{
			id:'name',
			header: "Player Name",
			dataIndex: 'name',
			width: 200
		},{
			id: 'type',
			header: 'Type',
			dataIndex: 'type',
			renderer: function(v,params,record){
				
				var retVal = 'Unknown Type';
				
				switch(v) {
					case 'DEFAULT':
						retVal = 'Default Single Player';
						break;
					case 'CUSTOM':
						retVal = 'Custom Single Player';
						break;
					case 'HYBRID_DEFAULT':
						retVal = 'Default Playlist Player';
						break;
					case 'HYBRID_CUSTOMIZED':
						retVal = 'Custom Playlist Player';
						break;
					default:
						retVal = 'Unknown Type';
				}
				
				return retVal;
			}
		},
		showHTMLColumn,
		deleteColumn,
		{
			hidden : true,
			dataIndex: 'playerParams'
		},{
			dataIndex: 'swfFilename',
			hidden : true
		},{
			dataIndex: 'swfHeight',
			hidden : true
		},{
			dataIndex: 'swfWidth',
			hidden : true
		}
	]);

	var playerGrid = new Ext.grid.GridPanel({
		region:'center',
		ds: this.playerStore,
		cm: cm,
		stripeRows: true,
		autoExpandColumn: 'type',
		autoHeight: true,
		width: 800,
		title: 'Players',
		// config options for stateful behavior
		stateful: false,
		stateId: 'playergrid',
		scope: this,
		tbar: [{
			text: 'Create Player',
			handler: function() {
				var createWin = new com.evoca.players.CreateWindow(null, this);
				createWin.show();
			},
			iconCls: 'add-icon',
			scope: this
		}]
	});

	function cellClick(grid, rowIndex, columnIndex, e, parent) {
		var columnObj = grid.getColumnModel().config[columnIndex];
		if(columnObj.handleClick)
			columnObj.handleClick(grid, rowIndex, columnIndex, e, this);
	}
	
	playerGrid.on('cellclick', cellClick);
	
	playerGrid.render(divID);
};

//Ext.extend(com.evoca.players.PlayerViewPanel,  Ext.grid.GridPanel, {});

/**
  * ConfigureColumn
  */
com.evoca.players.ConfigureColumn = function(config){
	Ext.apply(this, config);

	if(!this.id){
		this.id = Ext.id();
	}
};

com.evoca.players.ConfigureColumn.prototype ={
	renderer : function(v, p, record){
		p.css += ' configure-column';
		return '&#160;';
	},
	
	handleClick : function(grid, rowIndex, columnIndex, e, parent) {
		var record = grid.getStore().getAt(rowIndex);  // Get the Record for the row
		
		var createWin = new com.evoca.players.CreateWindow(record, parent);
		createWin.show();
	}
};


/**
  * ShowHTMLColumn
  */
com.evoca.players.ShowHTMLColumn = function(config){
	Ext.apply(this, config);
	if(!this.id){
		this.id = Ext.id();
	}
};

com.evoca.players.ShowHTMLColumn.prototype ={
	renderer : function(v, p, record){
		p.css += ' showhtml-column';
		return '&#160;';
	},
	
	handleClick : function(grid, rowIndex, columnIndex, e) {
		var record = grid.getStore().getAt(rowIndex);  // Get the Record for the row
		var showHTMLWin = new com.evoca.players.ShowHTMLWindow(record, parent);
		showHTMLWin.show();
	}
};



/**
  * DeleteColumn
  */
com.evoca.players.DeleteColumn = function(config){
	Ext.apply(this, config);
	if(!this.id){
		this.id = Ext.id();
	}
};

com.evoca.players.DeleteColumn.prototype ={
	renderer : function(v, p, record){
		var playerUtils = new com.evoca.players.PlayerUtils();
		
		if(record != null && playerUtils.isDefaultPlayer(record))
			p.css += ' delete-column-disabled';
		else
			p.css += ' delete-column';
		return '&#160;';
	},
	
	handleClick : function(grid, rowIndex, columnIndex, e) {
		var record = grid.getStore().getAt(rowIndex);  // Get the Record for the row
		var data = record.get('name');
		var type = record.get('type');

		var playerUtils = new com.evoca.players.PlayerUtils();
		
		if(!playerUtils.isDefaultPlayer(record)) {
			Ext.Msg.show({
				title: 'Delete',
				buttonAlign: 'center',
				buttons: Ext.Msg.YESNO,
				msg: 'Are you sure you want to delete the player: ' + data + '?',
				fn: function(btn, text) {
					if(btn == 'yes') {
						Ext.Ajax.request({
							url: 'data/deletePlayer/' + data,
							success: function(response) {
								Ext.Msg.show({
									title: 'Success',
									buttonAlign: 'center',
									buttons: Ext.Msg.OK,
									msg: response.responseText,//'The player has been deleted.',
									fn: function() {
										//window.location.reload();
									},
									scope: this
								});
								
								grid.store.remove(record);
								
							}, 
							failure: function(){
								Ext.Msg.show({
									title: 'Failure',
									buttonAlign: 'center',
									buttons: Ext.Msg.OK,
									msg: 'The player could not be deleted.',
									fn: function() {
										this.hide();
										window.location.reload();
									},
									scope: this
								});
							},
							scope: this
						});
					}
				},
				scope: this
			});
		}
	}
};


/**
  * ShowHTMLWindow
  */

com.evoca.players.ShowHTMLWindow = function(record, parent) {	
	this.record = record;
	this.parent = parent;
	
	this.disableParent();

	this.feedRecord = 
		Ext.data.Record.create([
			{name: 'name'}
		]);
	
	var feedXMLReader = new Ext.data.XmlReader({
		totalRecords: "totalRecordCount",
		record: "feed"
	}, this.feedRecord
	);
	
	var feedStore = new Ext.data.Store({
		autoLoad: true,
		url: 'data/feeds/',
		reader: feedXMLReader
	});
	
	
	this.feedsPicker = new Ext.form.ComboBox({
		name: 'feedsPicker',
		id: 'feedsPicker',
		fieldLabel: 'Choose a Feed',
		store: feedStore,
		displayField:'name',
		valueField: 'name', 
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		emptyText: 'Please select a feed'
	});
	
	this.feedsForm = new Ext.form.FormPanel({
        onSubmit: Ext.emptyFn,
        items: this.feedsPicker,
        bodyStyle:'background:transparent',
        border: false,
        submit: function() {
            this.getForm().getEl().dom.submit();
        }
    });
    
    this.infoPanel = new Ext.Panel({
  		html: 'Generating the HTML snippet for a player requires that you pick a  <b><i>playlist feed</i></b> for your player.<br/><br/>If no feeds appear in the dropdown box then you can create a playlist feed by navigating the menu to the Feeds Configuration page: <i>Configuration-->Feeds</i><br/><br/>',
  		bodyStyle:'background:transparent',
  		border: false
    });
	
	this.feedsPicker.on ( 'select', function() {
		var feedName = this.feedsForm.getForm().findField('feedsPicker').getValue();
		var playerName = this.record.get('name');
		var enableShareButton = this.record.get('enableShareButton');
		var shareButtonTheme = this.record.get('shareButtonTheme');
		
		var localResourceStr = 'data/players/audio/flash/' + playerName + '/feeds/' + feedName + '?resourceExpires=2147483647';

		var beginHTMLStr = '<form action=\'\' name=\'embedForm1\' id=\'embedForm1\'><input size=\'50\' id=\'embed_code1\' name=\'embed_code1\' value=\'';
		var endHTMLStr = '\' onclick=\'javascript:document.embedForm1.embed_code1.focus();document.embedForm1.embed_code1.select();\' readonly=\'readonly\' type=\'text\' /></form>';
  		
		Ext.Ajax.request({
			url: localResourceStr,
			disableCaching: false,
			success: function(response) {
				var text = response.responseText.replace(/\r|\n|\r\n/g, "");
				var displayText = response.responseText;
				
				if(!Ext.isIE) {
					displayText = displayText.replace(/wmode/g, 'wmodefake');
				}
				
				if(enableShareButton == 'true') {
					displayText = '<span style="color:red;font-weight:bold;">Preview shows only first page of share feature. Not for use in posting player.</span><br /><br />' + displayText;
				
					var shareButton3 = "";
					shareButton3 += '<a id="previewShareLink" href="javascript:com.evoca.players.displayEmbedWidget(\'codeInfo\', \'gigyaWidget\', \'' + shareButtonTheme + '\');"><img src="/web/images/share-button.jpg"><div id="gigyaWidget" name="gigyaWidget"></div></a>';
					
					displayText += shareButton3;
				}
				
				displayText = '<div style="float:left;">' + displayText + '</div>';
				
				Ext.Msg.show({
					title: 'HTML Player and Copy-n-Paste Code',
					buttonAlign: 'center',
					buttons: Ext.Msg.OK,
					width: 700,
					msg: displayText + '<div style="clear:both"><br/><br/><ol><li>1. Test the player to make sure that it is the player that you want.</li><li>2. Click on the Copy-n-Paste HTML Code to select it.</li><li>3. Copy this code to the webpage where you want this player to be displayed.</li></ol><br/>Copy-n-Paste HTML Code <br/>' + beginHTMLStr + text + endHTMLStr + '<br/><br/>*Note: If you are seeing a spining image but see no player then you may have a problem with the feed. Please check the following:<br/>1.Verify that the "Enable playlist" checkbox is checked for this feed.<br/>2.Verify that there are recordings in the feed.  If there are no recordings in the feed then the player will not display properly.</div>',
					fn: function() {
						//window.location.reload();
					},
					scope: this
				});
				
			}, 
			failure: function(){
				Ext.Msg.show({
					title: 'Failure',
					buttonAlign: 'center',
					buttons: Ext.Msg.OK,
					msg: 'The player HTML code could not be fetched.',
					fn: function() {
						this.hide();
						window.location.reload();
					},
					scope: this
				});
			},
			scope: this
		});	
	},this);

	com.evoca.players.ShowHTMLWindow.superclass.constructor.call(this, {
		title: 'Show Player HTML Code',
		id: 'ev-showhtml-window',
		autoHeight: true,
		width: 310,
		resizable: false,
		plain:true,
		modal: true,
		autoScroll: true,
		stateful: false,	
		closeAction: 'close',
		closable: true,
		//labelWidth: 110, // label settings here cascade unless overridden
		scope: this,
		items: [this.infoPanel, this.feedsForm]
	});

}

Ext.extend(com.evoca.players.ShowHTMLWindow, Ext.Window, {
	close : function() {
		this.destroy();
		this.enableParent();
	},
	
	disableParent : function() {
		if(this.parent) {
			//this.parent.disable();
		}
	},
	
	enableParent : function() {
		if(this.parent) {
			//this.parent.enable();
		}
	}
});

com.evoca.players.hideDisplayWidget = function(embedCodeID, embedToID, themeNumber) {
	if($(embedToID)) {
		Element.hide(embedToID);
	}
		
	if($('previewShareLink')) {
		$('previewShareLink').href = "javascript:com.evoca.players.displayEmbedWidget('" + embedCodeID + "', '" + embedToID + "', '" + themeNumber + "');";
	}
}

com.evoca.players.displayEmbedWidget = function(embedCodeID, embedToID, themeNumber) {
	
	if($(embedToID) && $(embedToID).innerHTML != '') {
		Element.show(embedToID);
	}
	else {
		var lightColor = '<background frame-color="#BFBFBF" background-color="#FFFFFF" gradient-color-begin="#ffffff" gradient-color-end="#F4F4F4" corner-roundness="4;4;4;4"></background><controls color="#202020" corner-roundness="4;4;4;4" gradient-color-begin="#EAEAEA" gradient-color-end="#F4F4F4" bold="false"><snbuttons type="textUnder" frame-color="#D5D5D5" background-color="#fafafa" over-frame-color="#60BFFF" over-background-color="#ebebeb" color="#808080" gradient-color-begin="#FFFFFF" gradient-color-end="d4d6d7" size="10" bold="false" down-frame-color="#60BFFF" down-gradient-color-begin="#6DDADA" over-gradient-color-end="#6DDADA" down-gradient-color-end="#F4F4F4" over-color="#52A4DA" down-color="#52A4DA" over-bold="false"><more frame-color="#A4DBFF" over-frame-color="#A4DBFF" gradient-color-begin="#F4F4F4" gradient-color-end="#BBE4FF" over-gradient-color-begin="#A4DBFF" over-gradient-color-end="#F4F4F4"></more><previous frame-color="#BBE4FF" over-frame-color="#A4DBFF" gradient-color-begin="#FFFFFF" gradient-color-end="#A4DBFF" over-gradient-color-begin="#A4DBFF" over-gradient-color-end="#F4F4F4"></previous></snbuttons><textboxes frame-color="#CACACA" color="#757575" gradient-color-begin="#ffffff" bold="false"><codeboxes color="#757575" frame-color="#DFDFDF" background-color="#FFFFFF" gradient-color-begin="#ffffff" gradient-color-end="#FFFFFF" size="10"></codeboxes><inputs frame-color="#CACACA" color="#757575" gradient-color-begin="#F4F4F4" gradient-color-end="#ffffff"></inputs><dropdowns list-item-over-color="#52A4DA" frame-color="#CACACA"></dropdowns></textboxes><buttons frame-color="#CACACA" gradient-color-begin="#F4F4F4" gradient-color-end="#CACACA" color="#000000" bold="false" over-frame-color="#60BFFF" over-gradient-color-begin="#BBE4FF" down-gradient-color-begin="#BBE4FF" over-gradient-color-end="#FFFFFF" down-gradient-color-end="#ffffff"><post-buttons frame-color="#CACACA" gradient-color-end="#CACACA"></post-buttons></buttons><listboxes frame-color="#CACACA" corner-roundness="4;4;4;4" gradient-color-begin="#F4F4F4" gradient-color-end="#FFFFFF"></listboxes><checkboxes checkmark-color="#00B600" frame-color="#D5D5D5" corner-roundness="3;3;3;3" gradient-color-begin="#F4F4F4" gradient-color-end="#FFFFFF"></checkboxes><servicemarker gradient-color-begin="#ffffff" gradient-color-end="#D5D5D5"></servicemarker><tooltips color="#6D5128" gradient-color-begin="#FFFFFF" gradient-color-end="#FFE4BB" size="10" frame-color="#FFDBA4"></tooltips></controls><texts color="#202020"><headers color="#202020"></headers><messages color="#202020"></messages><links color="#52A4DA" underline="false" over-color="#353535" down-color="#353535" down-bold="false"></links></texts>';
		var oceanBlue = '<background gradient-color-begin="#00006D" gradient-color-end="#28516D"></background><controls><snbuttons type="textUnder" background-color="#FFFFFF" over-background-color="#FFFFFF" color="DEE8EC" corner-roundness="0;10;0;10" gradient-color-begin="" gradient-color-end="" bold="true" over-color="#FFFFC8"></snbuttons><textboxes><codeboxes color="#6A6A6A" frame-color="#0D1B6D" background-color="DEE8EC"></codeboxes><inputs gradient-color-begin="E9F0F3" gradient-color-end="E9F0F3"></inputs><dropdowns list-item-over-color="#1B0D6D" gradient-color-begin="E9F0F3" gradient-color-end="E9F0F3" list-item-over-gradient-color-end="#28516D"></dropdowns></textboxes><buttons gradient-color-begin="#0099FF" gradient-color-end="#223276" color="#FFFFFF" corner-roundness="0;8;0;8" bold="true" over-gradient-color-begin="#0099FF" over-gradient-color-end="#0099FF"></buttons><servicemarker gradient-color-begin="Transparent" gradient-color-end="#0098FE"></servicemarker></controls><texts color="#FFFFFF" bold="true"><privacy color="#AAAAAA"></privacy><labels color="C1D7E5"></labels><messages color="#F4F4F4" background-color="#1B366D"></messages><links color="E9F0F3" underline="false" over-color="#ADC8FF"></links></texts>'
		var redAndBlack = '<background frame-color="Transparent" gradient-color-begin="#353535" gradient-color-end="#606060"></background><controls bold="true"><snbuttons type="textUnder" frame-color="#6D0000" background-color="#8A8A8A8A" over-background-color="#FFFFFF" color="#CACACA" corner-roundness="0;8;8;8" gradient-color-begin="" gradient-color-end="" bold="false" over-gradient-color-begin="#AAAAAA" over-gradient-color-end="#000000" over-color="#F4F4F4" down-color="#000000"><more frame-color="Transparent"></more></snbuttons><textboxes frame-color="#000000" color="#AAAAAA" corner-roundness="0;0;0;0" gradient-color-begin="#202020" gradient-color-end="#0B0B0B" bold="false"><codeboxes color="#EAEAEA" frame-color="#8A8A8A" gradient-color-begin="#000000"></codeboxes><inputs frame-color="#6D0000"></inputs><dropdowns frame-color="#6D0000" handle-gradient-color-begin="#B60000" handle-gradient-color-end="#6D0000" handle-over-gradient-color-begin="#FF0000" handle-over-gradient-color-end="#DA0000" handle-down-gradient-color-begin="#FF0000" handle-down-gradient-color-end="#6D0000" background-color="#6D0000" gradient-color-begin="#000000"></dropdowns></textboxes><buttons frame-color="#FF0000" gradient-color-begin="#FF2424" gradient-color-end="#6D0000" color="#F4F4F4" corner-roundness="0;8;8;8" size="10" bold="false" down-frame-color="#000000" over-gradient-color-begin="#DA0000" down-gradient-color-begin="#910000" over-gradient-color-end="#DA0000" down-gradient-color-end="#FF0000" over-color="#F4F4F4"><post-buttons gradient-color-begin="#FF4949"></post-buttons></buttons><listboxes corner-roundness="5;5;5;5"></listboxes><servicemarker gradient-color-begin="#DA0000" gradient-color-end="#DA0000"></servicemarker></controls><texts color="#FFFFFF" size="10"><privacy color="#959595" size="11"></privacy><headers size="11" bold="true"></headers><labels size="11" bold="true"></labels><messages color="#D5D5D5" frame-thickness="0" corner-roundness="0;0;0;0" gradient-color-begin="#B60000" gradient-color-end="#000000" size="11" bold="true"></messages><links color="#DFDFDF" underline="false" size="11" bold="true" over-color="#FFFFFF"></links></texts>';
		var pinkAndRed = '<background frame-color="Transparent" gradient-color-begin="#DA0000" gradient-color-end="#FFC8AD"></background><controls bold="true"><snbuttons type="textUnder" frame-color="#DA0000" background-color="#910000" over-frame-color="#F4F4F4" over-background-color="#FFFFFF" color="#6D0000" corner-roundness="0;8;8;8" gradient-color-begin="" gradient-color-end="" down-frame-color="#6D0000" over-gradient-color-begin="#FFAD9F" down-gradient-color-begin="#910000" over-gradient-color-end="#6D0D1B" down-gradient-color-end="#FFAD9F" over-color="#F4F4F4" down-color="#000000"><more frame-color="#AAAAAA" over-frame-color="#AAAAAA" gradient-color-begin="#DA0000" over-gradient-color-begin="#FF5B40"></more><previous frame-color="#AAAAAA" background-color="DBDBDB" over-frame-color="#6D0000" over-background-color="#6A6A6A" gradient-color-begin="#FF5B40" gradient-color-end="#6D0D1B" down-frame-color="6D0000" down-background-color="DBDBDB" over-gradient-color-begin="#910000" down-gradient-color-begin="FF5B40" over-gradient-color-end="#FFAD9F" down-gradient-color-end="6D0D1B"></previous></snbuttons><textboxes frame-color="#353535" color="#F4F4F4" corner-roundness="0;0;0;0" gradient-color-begin="#202020" gradient-color-end="#0B0B0B" bold="false"><codeboxes color="#1B366D" frame-color="#DA0000" gradient-color-begin="#EAEAEA" gradient-color-end="#F4F4F4"></codeboxes><inputs frame-color="#B60000" color="#606060" gradient-color-begin="#DFDFDF" gradient-color-end="#DFDFDF"></inputs><dropdowns list-item-over-color="#FF2424" frame-color="#B60000" handle-gradient-color-begin="#AEC8F7" handle-gradient-color-end="#6D0000" handle-over-gradient-color-begin="#AEC8F7" handle-over-gradient-color-end="#AEC8F7" handle-down-gradient-color-begin="#FF0000" handle-down-gradient-color-end="#6D0000" background-color="#EAEAEA" color="#4A4A4A" gradient-color-begin="#EAEAEA" gradient-color-end="#EAEAEA" list-item-over-gradient-color-end="#F4F4F4"></dropdowns></textboxes><buttons frame-color="#DA0000" gradient-color-begin="#FF0000" gradient-color-end="#910000" color="#F4F4F4" corner-roundness="0;8;8;8" size="10" over-frame-color="#DA0000" down-frame-color="#F4F4F4" over-gradient-color-begin="#DA0000" down-gradient-color-begin="#910000" over-gradient-color-end="#910000" down-gradient-color-end="#0D1B6D" over-color="#F4F4F4"><post-buttons gradient-color-begin="#FF4949" gradient-color-end="#6D0000"></post-buttons></buttons><listboxes corner-roundness="5;5;5;5" bold="false"></listboxes><servicemarker gradient-color-begin="#555555" gradient-color-end="#555555"></servicemarker></controls><texts color="#FFFFFF" size="10" bold="true"><privacy color="#910000" size="11" bold="false"></privacy><headers size="11"></headers><labels color="#B60000" size="11"></labels><messages color="#FFC8AD" background-color="#1B366D" frame-thickness="0" corner-roundness="3;3;3;3" gradient-color-begin="#912412" gradient-color-end="#6D1B0D" size="11"></messages><links color="#F4F4F4" underline="false" size="11" over-color="#FFFFFF"></links></texts>';
		var earchTones = '<background frame-color="Transparent" gradient-color-begin="#A4DA52" gradient-color-end="#6D9136" corner-roundness="8;8;8;8"></background><controls bold="true"><snbuttons type="textUnder" frame-color="#6D9136" background-color="#489124" over-frame-color="#D5D5D5" over-background-color="#FFFFFF" color="#1B6D0D" corner-roundness="0;8;0;8" gradient-color-begin="" gradient-color-end="" over-gradient-color-begin="#88B644" down-gradient-color-begin="#DADA6D" over-gradient-color-end="#000000" down-gradient-color-end="#6D9136" over-color="#F4F4F4" down-color="#000000"><more frame-color="#BABABA" gradient-color-begin="#516D28" gradient-color-end="#516D28"></more><previous frame-color="#BABABA" gradient-color-begin="#516D28" gradient-color-end="#516D28"></previous></snbuttons><textboxes frame-color="#000000" color="#AAAAAA" corner-roundness="0;8;0;8" gradient-color-begin="#6D5128" gradient-color-end="#6D5128" bold="false"><codeboxes color="#EAEAEA" frame-color="6D1B0D" background-color="#B6B65B" gradient-color-begin="#919148" gradient-color-end="#919148"></codeboxes><inputs frame-color="#6D1B0D" color="#FFFFC8" gradient-color-begin="#919148" gradient-color-end="#919148"></inputs><dropdowns list-item-over-color="6D1B0D" frame-color="#6D1B0D" handle-gradient-color-begin="#FFFFC8" handle-gradient-color-end="#DADA6D" handle-over-gradient-color-begin="#FFFFC8" handle-over-gradient-color-end="#FFFFB6" handle-down-gradient-color-begin="#DADA6D" handle-down-gradient-color-end="#DADA6D" background-color="#FFFFC8" color="#FFFFC8" gradient-color-begin="#919148" gradient-color-end="#919148" list-item-over-gradient-color-end="#FFFFC8"></dropdowns></textboxes><buttons frame-color="6D1B0D" gradient-color-begin="#FFFFC8" gradient-color-end="#B6B65B" corner-roundness="0;8;8;8" over-frame-color="#6D1B0D" down-frame-color="#F4F4F4" over-gradient-color-begin="#FFFFC8" down-gradient-color-begin="#F4F4F4" over-gradient-color-end="#DADA6D" down-gradient-color-end="#FFFF92" over-color="#28516D"><post-buttons frame-color="#6D1B0D" background-color="#FFFFC8" gradient-color-end="B6B65B"></post-buttons></buttons><listboxes corner-roundness="5;5;5;5" bold="false"></listboxes><servicemarker gradient-color-begin="#A4DA52" gradient-color-end="#516D28"></servicemarker></controls><texts color="#FFFFFF" bold="true"><privacy color="#6D361B"></privacy><headers color="#EAEAEA"></headers><labels color="#6D1B0D"></labels><messages color="#6D6D36" background-color="#1B366D" frame-thickness="0" corner-roundness="0;0;0;0" gradient-color-begin="#FFFFC8" gradient-color-end="#FFFFC8"></messages><links color="#FFFFFF" underline="false" over-color="#6D1B0D" down-color="#366D1B"></links></texts>';
		var skyBlue = '<background gradient-color-begin="#ADC8FF"></background><controls><snbuttons type="textUnder" background-color="#FFFFFF" over-background-color="#FFFFFF" color="#376DDA" corner-roundness="0;10;0;10" gradient-color-begin="" gradient-color-end="" bold="false" over-color="#0D1B6D"></snbuttons><textboxes><codeboxes color="#6A6A6A" frame-color="#1B366D" background-color="#F4F4F4"></codeboxes></textboxes><buttons gradient-color-begin="#0099FF" gradient-color-end="#223276" color="#FFFFFF" corner-roundness="0;8;0;8" bold="true" over-gradient-color-begin="#0099FF" over-gradient-color-end="#0099FF"></buttons><servicemarker gradient-color-begin="#F4F4F4" gradient-color-end="#F4F4F4"></servicemarker></controls><texts color="#FFFFFF" bold="true"><privacy color="#AAAAAA"></privacy><labels color="#1B366D"></labels><messages color="#F4F4F4" background-color="#1B366D"></messages><links color="#376DDA" underline="false" over-color="#1B366D"></links></texts>';

		var color = lightColor;
		
		switch(themeNumber) {
			case '1':
				color = oceanBlue;
				break;
			case '2':
				color = redAndBlack;
				break;
			case '3':
				color = pinkAndRed;
				break;
			case '4':
				color = earchTones;
				break;
			case '5':
				color = skyBlue;
				break;
			case '6':
				color = lightColor;
				break;
			default:
				color = lightColor;
		}
	
		var pconf={
			defaultContent: embedCodeID, 
			widgetTitle: 'Evoca Recording',	
			UIConfig: '<config><display showDesktop="false" showEmail="true" useTransitions="true" showBookmark="true" codeBoxHeight="auto" showCloseButton="true"></display><body>' + color + '</body></config>'
		};
		
		var partner = '597482';
		Wildfire.initPost(partner, embedToID, 400, 300, pconf);
	}
	
	if($('previewShareLink')) {
		$('previewShareLink').href = "javascript:com.evoca.players.hideDisplayWidget('" + embedCodeID + "', '" + embedToID + "', '" + themeNumber + "');";
	}
}

/**
  * CreateWindow
  */

com.evoca.players.CreateWindow = function(record, parent) {	
	//parent.disable(true);
	this.record = record;
	this.parent = parent;
	
	this.disableParent();
	
	var shareButtonThemeData = [
		['light', '6'],
		['ocean', '1'],
		['redAndBlack', '2'],
		['pinkAndRed', '3'],
		['earthTones', '4'],
		['skyBlue', '5']
	];
	
	
	var nameValueReader = new Ext.data.ArrayReader({}, [
		{name: 'name'},
		{name: 'value'}
	]);
	
	var shareButtonThemeStore = new Ext.data.Store({
		reader: nameValueReader,
		data: shareButtonThemeData
	});

	this.orientationDefaults = {defaultImage:'',swfFilename:'playlistDefault',type:'HYBRID_CUSTOMIZED',file:'static/config/players/xml/playlist.xml',swfheight:0,swfwidth:0,frontcolor:'0x000000',backcolor:'0xffffff',lightcolor:'0x000000',screencolor:'0x000000',width:'', height:'', location:'static/config/players/swf/ev-pl-4x.swf',logo:'',stretching:'uniform',displayclick:'play',autostart:'false',repeat:'false',shuffle:true,volume:80, skin:'evoca-rounded-skin.swf'};
	this.orientations = {
			defaults:{},
			normal:{swfFilename:'playlistDefault', type:'HYBRID_CUSTOMIZED',file:'static/config/players/xml/playlist.xml',swfheight:'140',swfwidth:'320', playlist:'right', playlistsize:'320'},
			below:{swfFilename:'playlistDefault', type:'HYBRID_CUSTOMIZED',file:'static/config/players/xml/playlist.xml',swfheight:'140',swfwidth:'320', playlist:'bottom', playlistsize:'120'},
			line:{swfFilename:'playlistDefault', type:'HYBRID_CUSTOMIZED',file:'static/config/players/audio/MTVHotline3.mp3',swfheight:'20',swfwidth:'320', playlist:'none'},
			rightlist:{swfFilename:'playlistDefault', type:'HYBRID_CUSTOMIZED',file:'static/config/players/xml/playlist.xml',swfheight:'140',swfwidth:'320', width:'120', height: '120', playlist:'right', playlistsize:'200'},
			abovebelow:{swfFilename:'playlistDefault', type:'HYBRID_CUSTOMIZED',file:'static/config/players/xml/playlist.xml',swfheight:'240',swfwidth:'320', width:'320', height: '120', playlist:'bottom', playlistsize: '100'}
	}

	this.trueFalseStore = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['false', 'false'],
				['true', 'true']]
	});
	
	this.skinStore = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['evoca-rounded-skin.swf', 'Rounded skin'],
				['jw-default-skin.swf', 'Square skin']]
	});
	
	this.skin = new Ext.form.ComboBox({
		id: 'skin',
		name: 'skin',
		fieldLabel: 'Skin',
		autoWidth: true,
		store: this.skinStore,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		emptyText:'Choose an skin below:',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: this.skinStore.getAt(0).get('value')
	});
	
	// FORM FIELDS
	this.store = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['normal', 'No display, playlist above'],
				['below', 'No display, playlist below'],
				['line', 'A line with single recording'],
				['rightlist', 'Display to the left, playlist to the right'],
				['abovebelow', 'Display above, and playlist on the bottom']]
	});
	
	this.picker = new Ext.form.ComboBox({
		id: 'picker',
		name: 'picker',
		height: 400,
		width: 343,
		store: this.store,
		hideLabel: true,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		emptyText:'Choose an orientation below:',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false
	});
	
	this.picker.on ( 'select', function() {
		var fieldValue = this.form.getForm().findField('picker').getValue();
		
		var orientationName;
		for(var i = this.store.getCount() - 1; i >= 0; i--) {
			if(this.store.getAt(i).get('value') == fieldValue) {
				orientationName = this.store.getAt(i).get('value');
				break;
			}
		}
				
		this.loadOrientation(orientationName);
	},this);
	
	this.swfheight = new Ext.form.TextField({
		id: 'swfheight',
		name: 'swfheight',
		fieldLabel: 'Height of the player',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: 0,
		vtype: 'wholenum',
		maxLength: 100,
		maxLengthText: 'The height can only be 100 characters long'
	});
	
	this.swfwidth = new Ext.form.TextField({
		id: 'swfwidth',
		name: 'swfwidth',
		fieldLabel: 'Width of the player',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: 0,
		vtype: 'wholenum',
		maxLength: 100,
		maxLengthText: 'The width can only be 100 characters long'
	});

	this.backcolor = new Ext.form.TextField({
		id: 'backcolor',
		name: 'backcolor',
		fieldLabel: 'Background color: (<a href="javascript:pickColor(\'backcolorpalette\', \'backcolor\');">pick</a>)<span id="backcolorpalette" name="backcolorpalette"></span>',
		labelSeparator: '',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: '0xffffff',
		maxLength: 8,
		maxLengthText: 'This field may only contain 8 characters',
		vtype: 'hexnum'
	});
		
	this.frontcolor = new Ext.form.TextField({
		id: 'frontcolor',
		name: 'frontcolor',
		fieldLabel: 'Foreground color: (<a href="javascript:pickColor(\'frontcolorpalette\', \'frontcolor\');">pick</a>)<span id="frontcolorpalette" name="frontcolorpalette"></span>',
		labelSeparator: '',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: '0x000000',
		maxLength: 8,
		maxLengthText: 'This field may only contain 8 characters',
		vtype: 'hexnum'
	});
	
	this.lightcolor = new Ext.form.TextField({
		id: 'lightcolor',
		name: 'lightcolor',
		fieldLabel: 'Highlight color: (<a href="javascript:pickColor(\'lightcolorpalette\', \'lightcolor\');">pick</a>)<span id="lightcolorpalette" name="lightcolorpalette"></span>',
		labelSeparator: '',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: '0x000000',
		maxLength: 8,
		maxLengthText: 'This field may only contain 8 characters',
		vtype: 'hexnum'
	});
	
	this.screencolor = new Ext.form.TextField({
		id: 'screencolor',
		name: 'screencolor',
		fieldLabel: 'Screen color: (<a href="javascript:pickColor(\'screencolorpalette\', \'screencolor\');">pick</a>)<span id="screencolorpalette" name="screencolorpalette"></span>',
		labelSeparator: '',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: '0x000000',
		maxLength: 8,
		maxLengthText: 'This field may only contain 8 characters',
		vtype: 'hexnum'
	});
	
	this.displaywidth = new Ext.form.TextField({
		id: 'width',
		name: 'width',
		fieldLabel: 'Display width',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: true,
		style: {height: '22px'},
		width: 164,
		vtype: 'wholenum',
		maxLength: 100,
		maxLengthText: 'The display width can only be 100 characters long'
	});
	
	this.displayheight = new Ext.form.TextField({
		id: 'height',
		name: 'height',
		fieldLabel: 'Display height',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: true,
		style: {height: '22px'},
		width: 164,
		vtype: 'wholenum',
		maxLength: 100,
		maxLengthText: 'The display height can only be 100 characters long'
	});
	
	// On displaywidth blur, update the playlistsize
	this.displaywidth.on ( 'blur', function() {
		var playlistLocation = this.form.getForm().findField('playlist').getValue();
		var width = this.form.getForm().findField('width').getValue();
		var height = this.form.getForm().findField('height').getValue();
		var swfwidth = this.form.getForm().findField('swfwidth').getValue();
		var swfheight = this.form.getForm().findField('swfheight').getValue();
		this.form.getForm().findField('playlistsize').setValue(
			com.evoca.players.util.calculatePlaylistSize(playlistLocation, swfwidth, swfheight, width, height)
		);
	},this);
	
	// On displaywidth blur, update the playlistsize
	this.displayheight.on ( 'blur', function() {
		var playlistLocation = this.form.getForm().findField('playlist').getValue();
		var width = this.form.getForm().findField('width').getValue();
		var height = this.form.getForm().findField('height').getValue();
		var swfwidth = this.form.getForm().findField('swfwidth').getValue();
		var swfheight = this.form.getForm().findField('swfheight').getValue();
		this.form.getForm().findField('playlistsize').setValue(
			com.evoca.players.util.calculatePlaylistSize(playlistLocation, swfwidth, swfheight, width, height)
		);
	},this);
	
	this.logo = new Ext.form.TextField({
		id: 'logo',
		name: 'logo',
		fieldLabel: 'Logo to put over the display',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: true,
		style: {height: '22px'},
		width: 164,
		vtype: 'url'
	});
	
	this.defaultImage = new Ext.form.TextField({
		id: 'defaultImage',
		name: 'defaultImage',
		fieldLabel: 'Default image',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: true,
		style: {height: '22px'},
		width: 164,
		vtype: 'url'
	});
	
	this.stretchingstore = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['uniform', 'to fit the display'],
				['fill', 'to fill the display'],
				['exactfit', 'disproportionally to fit'],
				['none', 'don\'t stretch at all']]
	});

	this.stretching = new Ext.form.ComboBox({
		id: 'stretching',
		name: 'stretching',
		fieldLabel: 'Stretch movies/images',
		autoWidth: true,
		store: this.stretchingstore,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		emptyText:'Choose an example below:',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: this.stretchingstore.getAt(0).get('value')
	});
	
	this.displayclickStore = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['play', 'play/pause the recording'],
				['link', 'follow a recording link'],
				['none', 'show nothing'],
				['mute', 'mute the player'],
				['next', 'advance to the next recording']]
	});
	
	this.displayclick = new Ext.form.ComboBox({
		id: 'displayclick',
		name: 'displayclick',
		fieldLabel: 'Display click behavior',
		autoWidth: true,
		store: this.displayclickStore,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: this.displayclickStore.getAt(0).get('value')
	});
	
	this.autostartStore = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['false', 'false'],
				['true', 'true'],
				['muted', 'muted']]
	});

	this.autostart = new Ext.form.ComboBox({
		id: 'autostart',
		name: 'autostart',
		fieldLabel: 'Automatically start playing',
		autoWidth: true,
		store: this.autostartStore,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		emptyText:'Choose an example below:',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: this.autostartStore.getAt(0).get('value')
	});
	
	this.repeatStore = new Ext.data.SimpleStore({
		fields: ['value', 'text'],
		data : [['false', 'false'],
				['true', 'true'],
				['list', 'list']]
	});

	this.repeat = new Ext.form.ComboBox({
		id: 'repeat',
		name: 'repeat',
		fieldLabel: 'Repeat playing',
		autoWidth: true,
		store: this.repeatStore,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		emptyText:'Choose an example below:',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: this.repeatStore.getAt(0).get('value')
	});
	
	
	this.shuffle = new Ext.form.ComboBox({
		id: 'shuffle',
		name: 'shuffle',
		fieldLabel: 'Shuffle playback',
		autoWidth: true,
		store: this.trueFalseStore,
		displayField:'text',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: this.trueFalseStore.getAt(1).get('value')
	});
		
	this.volume = new Ext.form.TextField({
		id: 'volume',
		name: 'volume',
		fieldLabel: 'Volume at startup',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		style: {height: '22px'},
		width: 164,
		value: 80,
		vtype: 'wholenum',
		maxLength: 100,
		maxLengthText: 'The volume can only be 100 characters long'
	});
	
	this.playerName = new Ext.form.TextField({
		id: 'playerName',
		name: 'playerName',
		fieldLabel: 'Name ',
		inputType: 'text',
		validateOnBlur: false,
		allowBlank: false,
		autoCreate: {tag: "input", type: "text", maxLength: "30"},
		style: {height: '22px'},
		width: 164,
		minLength: 1,
		minLengthText: 'The name of the player must be at least 1 character long.',
		regex: /^[0-9a-zA-Z_]+$/,
		validator: (function(curValue) {
			var retVal = true;
			
			var msg = 'Name must be unique.  A player already exists called \'' + curValue + '\'.';
			var regexStr = '/^(' + curValue + '){1}$/i';
			var regex = eval(regexStr);
			var tmprec = this.parent.store.find('name', regex);

			if(tmprec > -1 && record != null) {
				if(record.get('index') != tmprec)
					retVal = msg;
				else
					retVal = true;
			}
			else if(tmprec > -1) {
				retVal = msg;
			}
			else {
				retVal = true;
			}

			return retVal;
		}).createDelegate(this),
		scope: this
	});
	
	var htmlHeader = new Ext.form.TextArea({
		id: 'htmlHeader',
		fieldLabel: 'HTML Header',
		width: 260
	});
	
	var htmlFooter = new Ext.form.TextArea({
		id: 'htmlFooter',
		fieldLabel: 'HTML Footer',
		width: 260
	});
	
	this.shareButtonTheme = new Ext.form.ComboBox({
		id: 'shareButtonTheme',
		name: 'shareButtonTheme',
		fieldLabel: 'Theme',
		autoWidth: true,
		store: shareButtonThemeStore,
		displayField:'name',
		valueField: 'value',
		typeAhead: true,
		mode: 'local',
		triggerAction: 'all',
		emptyText:'Choose a theme:',
		selectOnFocus:true,
		resizable:true,
		forceSelection: true,
		editable: false,
		value: (this.record == null) ? shareButtonThemeStore.getAt(0).get('value') : this.record.get('shareButtonTheme')
	});
	
	this.enableShareButton = new Ext.form.Checkbox({
		name: 'enableShareButton',
		id: 'enableShareButton',
		fieldLabel: 'Show share button',
		checked: (this.record == null) ? false : (this.record.get('enableShareButton') + '') == 'true'
	});
	
	var formParent = this;
	
	// FIELD LISTENERS
	htmlHeader.on('render', function(){
		this.trigger = new Ext.form.TriggerField({
			id: 'htmlHeaderWrapper',
			triggerClass: 'configure-column',
			scope: this
		});
		
		this.trigger.onTriggerClick = function(){
			var headerValue = htmlHeader.getValue();
			var htmlEditor = new com.evoca.players.HtmlWizard(headerValue, formParent, 'htmlHeader', 'Edit HTML Header');
			htmlEditor.show();
			
			htmlEditor.on('destroy', function(){
				this.preview.enable();
				this.preview.removeClass('x-item-disabled');
				this.preview.syncSize(); 
			});
		};
		
		this.trigger.applyToMarkup('htmlHeader');
	})
	
	this.enableShareButton.on('check', function() {
		if(this.enableShareButton.checked) {
			this.showField(this.shareButtonTheme);
		}
		else {
			this.hideField(this.shareButtonTheme);
		}
		
		this.syncSize();
	},
	this);
	
	htmlFooter.on('render', function(){
		this.trigger = new Ext.form.TriggerField({
			id: 'htmlFooterWrapper',
			triggerClass: 'configure-column',
			scope: this
		});
		
		this.trigger.onTriggerClick = function(){
			var footerValue = htmlFooter.getValue();
			var htmlEditor = new com.evoca.players.HtmlWizard(footerValue, formParent, 'htmlFooter', 'Edit HTML Footer');
			htmlEditor.show();
		};
		
		this.trigger.applyToMarkup('htmlFooter');
	})
	
	// FIELD SETS
	this.htmlHeaderFooter = new Ext.form.FieldSet({
		title: 'Header and Footer HTML',
		autoWidth: true,
		autoHeight: true,
		labelWidth: 79,
		items: [htmlHeader, htmlFooter]
	});
	
	this.orientationSetup = new Ext.form.FieldSet({
		title: 'Orientation',
		autoWidth: true,
		autoHeight: true,
		items: [this.picker]
	});
	
	this.basicOptions = new Ext.form.FieldSet({
		title: 'Basic Options',
		autoWidth: true,
		autoHeight: true,
		items: [this.playerName, this.swfwidth, this.swfheight, this.displaywidth, this.displayheight, this.skin, this.enableShareButton, this.shareButtonTheme]
	});
	
	this.colorOptions = new Ext.form.FieldSet({
		title: 'Color Options',
		autoWidth: true,
		autoHeight: true,
		items: [this.backcolor, this.frontcolor, this.lightcolor, this.screencolor]
	});
	
	this.displayOptions = new Ext.form.FieldSet({
		title: 'Display appearance',
		autoWidth: true,
		autoHeight: true,
		items: [this.logo, 
				this.defaultImage, 
				this.stretching, 
				this.displayclick]
	});
	
	this.playbackBehaviorOptions = new Ext.form.FieldSet({
		title: 'Playback behaviour',
		autoWidth: true,
		autoHeight: true,
		items: [this.autostart, this.repeat, this.shuffle, this.volume]
	});

	// HIDDEN FORM FIELDS
	this.file = new Ext.form.Hidden({
		id: 'file',
		name: 'file'
	});

	this.location = new Ext.form.Hidden({
		id: 'location',
		name: 'location'
	});
	
	this.flashVars = new Ext.form.Hidden({
		id: 'flashVars',
		name: 'flashVars',
		value: record == null ? '' : record.get('playerParams')
	});
	
	this.swfFilename = new Ext.form.Hidden({
		id: 'swfFilename',
		name: 'swfFilename',
		value: record == null ? '' : record.get('swfFilename')
	});
	
	this.oldPlayerName = new Ext.form.Hidden({
		id: 'oldPlayerName',
		name: 'oldPlayerName',
		value:  record == null ? '' : record.get('name')
	});
	
	this.type = new Ext.form.Hidden({
		id: 'type',
		name: 'type',
		value: record == null ? '' : record.get('type')
	});
	
	this.fileField = new Ext.form.TextField({
		fieldLabel: 'File to Upload',
		inputType: 'file',
		validateOnBlur: false,
		name: 'userfile',
		allowBlank: false,
		style: {height: '22px'},
		width: 260
	});
	
	this.playlistsize = new Ext.form.Hidden({
		id: 'playlistsize',
		name: 'playlistsize',
		value: record == null ? '' : record.get('playlistsize')
	});
	
	this.playlist = new Ext.form.Hidden({
		id: 'playlist',
		name: 'playlist',
		value: record == null ? '' : record.get('playlist')
	});
	
	this.version = new Ext.form.Hidden({
		id: 'v',
		name: 'v',
		value: '4'
	});
	
	this.pluginsField = new Ext.form.Hidden({
		id: 'plugins',
		name: 'plugins',
		value: 'ems-plugin.swf'
	});
	
	// Quick Tips
	var autoHide = true;
	var dismissDelay = 60000;
	
	this.pickerTip = 'Choose an orientation for the display, controlbar, and playlist.';
	this.heightTip = '<span class="tipLabel">height</span> (320): Sets the overall height of the player.';
	this.widthTip = '<span class="tipLabel">width</span> (260): Sets the overall width of the player.';
	this.backcolorTip = '<span class="tipLabel">backcolor</span> (0xFFFFFF): Backgroundcolor of the controls, in HEX format.';
	this.frontcolorTip = '<span class="tipLabel">frontcolor</span> (0x000000): Texts & buttons color of the controls, in HEX format.';
	this.lightcolorTip = '<span class="tipLabel">lightcolor</span> (0x000000): Rollover color of the controls, in HEX format.';
	this.screencolorTip = '<span class="tipLabel">screencolor</span> (0x000000): Color of the display area, in HEX format.';
	this.displaywidthTip = '<span class="tipLabel">displaywidth</span> (260): Controls the width of the image display.';
	this.displayheightTip = '<span class="tipLabel">displayheight</span> (260): Controls the height of the image display.';
	this.logoTip = '<span class="tipLabel">logo</span> (undefined): Set this to the URL of an image that can be put as a watermark logo in the top right corner of the display. Transparent PNG files give the best results.';
	this.defaultImageTip = '<span class="tipLabel">defaultImage</span> (undefined): Set this to the URL of an image to be used as the default image for the display window.';
	this.stretchingTip = '<span class="tipLabel">stretching</span> (to fit the display): Sets how to stretch images/movies to make them fit the display. The default stretches to fit the display.';
	this.displayclickTip = '<span class="tipLabel">displayclick</span> (play): Controls what happens when a user clicks in the middle of the display.';
	this.autostartTip = '<span class="tipLabel">autostart</span> (false): Set this to true in the player to automatically start playing when the page loads.';
	this.repeatTip = '<span class="tipLabel">repeat</span> (false): Set this to true to automatically repeat playback of all files. Set this to list to playback an entire playlist once.';
	this.shuffleTip = '<span class="tipLabel">shuffle</span> (true): Set this to false to playback a playlist sequentially (first to last) instead of shuffled.';
	this.volumeTip = '<span class="tipLabel">volume</span> (80): sets the startup volume for playback of audiotracks.';
	this.playerNameTip = '<span class="tipLabel">name</span> (undefined): The name of the player.';
	this.htmlHeaderTip = '<span class="tipLabel">htmlHeader</span>: The HTML header that is viewable above the player.';
	this.htmlFooterTip = '<span class="tipLabel">htmlFooter</span>: The HTML footer that is viewable below the player.';
	this.shareTip = "With a share button,  offer options for online visitors to post player to 70+ destinations including Facebook, WordPress, and email and bookmark it";
	
	// Register the tips for the fields
	Ext.QuickTips.register({text:this.pickerTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.picker});
	Ext.QuickTips.register({text:this.heightTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.swfheight});
	Ext.QuickTips.register({text:this.widthTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.swfwidth});
	Ext.QuickTips.register({text:this.backcolorTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.backcolor});
	Ext.QuickTips.register({text:this.frontcolorTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.frontcolor});
	Ext.QuickTips.register({text:this.lightcolorTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.lightcolor});
	Ext.QuickTips.register({text:this.screencolorTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.screencolor});
	Ext.QuickTips.register({text:this.displaywidthTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.displaywidth});
	Ext.QuickTips.register({text:this.displayheightTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.displayheight});
	Ext.QuickTips.register({text:this.logoTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.logo});
	Ext.QuickTips.register({text:this.defaultImageTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.defaultImage});
	Ext.QuickTips.register({text:this.stretchingTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.stretching});
	Ext.QuickTips.register({text:this.displayclickTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.displayclick});
	Ext.QuickTips.register({text:this.autostartTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.autostart});
	Ext.QuickTips.register({text:this.repeatTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.repeat});
	Ext.QuickTips.register({text:this.shuffleTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.shuffle});
	Ext.QuickTips.register({text:this.volumeTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.volume});
	//Ext.QuickTips.register({text:this.playerNameTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.playerName});
	Ext.QuickTips.register({text:this.htmlHeaderTip,dismissDelay:dismissDelay,autoHide:autoHide,target:htmlHeader});
	Ext.QuickTips.register({text:this.htmlFooterTip,dismissDelay:dismissDelay,autoHide:autoHide,target:htmlFooter});
	Ext.QuickTips.register({text:this.shareTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.shareButtonTheme});
	Ext.QuickTips.register({text:this.shareTip,dismissDelay:dismissDelay,autoHide:autoHide,target:this.enableShareButton});
	
	this.form = new Ext.FormPanel({
		plugins: new Ext.ux.OOSubmit(),
		autoWidth: true,
		stateful: false,
		height: 400,
		autoScroll: true,
		labelWidth: 175,
		labelAlign: 'right',
		id:'createForm',
		url: 'data/createOrUpdatePlayer',
		fileUpload: false,
		items: [
				this.file, this.location, this.flashVars, this.swfFilename, this.oldPlayerName, this.type, this.playlist, this.playlistsize, this.version, this.pluginsField, // hidden fields
				this.orientationSetup,
				this.basicOptions,
				this.htmlHeaderFooter,
				this.colorOptions,
				this.displayOptions,
				this.playbackBehaviorOptions
		],
		border: false,
		bodyStyle:'position:relative;background:transparent;padding:10px;',
		errorReader: new Ext.data.XmlReader({
			record: 'error',
			success: '@success'
		},
		['detail'])
	});

	var operation = 'create';
	
	if(record != null)
		operation = 'edit';
	
	com.evoca.players.CreateWindow.superclass.constructor.call(this, {
		title: (operation == 'create') ? 'Create Player' : 'Edit Player',
		id: 'ev-create-window',
		autoHeight: true,
		width: 450,
		maskDisabled: false,
		bodyStyle: 'position:relative',
		resizable: true,
		titleBar: true,
		plain:true,
		modal: false,
		autoScroll: true,
		closable: true,
		labelWidth: 110, // label settings here cascade unless overridden
		buttons:[{
			text: 'Reload',
			scope: this,
			handler: function(){
				this.refreshPreview();
			}
		},{
			text: (operation == 'create') ? 'Create' : 'Save',
			scope: this,
			handler: function(){
				if (this.form.getForm().isValid()) {
					this.calculateFlashvars(this);
					this.preview.disable();
					
					this.form.getForm().submit({
						waitMsg: (operation == 'create') ? 'Creating...' : 'Saving...',
						style: 'position:absolute',
						success: function(form, action) {
							Ext.Msg.show({
								title: 'Success',
								buttonAlign: 'center',
								buttons: Ext.Msg.OK,
								msg: (operation == 'create') ? 'Player was successfully created.' : 'Player was successfully edited.',
								fn: function() {
									this.hide();
									this.preview.hide();
									window.location.reload();
								},
								scope: this
							});
						},
						failure: function(form, action) {
							// show the error dialog
							var errorsText = '';
							var errorsLength = (action.result.errors) ? action.result.errors.length : 0;
							if(errorsLength > 0) {
								errorsText = (errorsLength > 1) ? '<br/>Reasons: <br/>' : '<br/>Reason: ';
								
								var i = 1;
								action.result.errors.each(
									function(error) {
										errorsText += (((errorsLength > 1) ? (i + ') ') : '') + error.detail + '<br/>');
										i++;
									}
								);
							}
								
							Ext.Msg.show({
								title: 'Error',
								buttons: Ext.Msg.OK,
								msg: (operation == 'create') ? 'Player was not created.' + errorsText : 'Player was not edited.' + errorsText,
								scope:this,
								fn: function() {
									this.preview.enable();
								}
							});
						},
						scope: this
					});
				}
			},
			scope: this
		},{
			text: 'Cancel',
			handler: function() {
				this.destroy();
				this.preview.destroy();
				
				this.enableParent();
			},
			scope: this
		}],
		items: [this.form],
		scope: this
	});

}

Ext.extend(com.evoca.players.CreateWindow, Ext.Window, {
	show : function(){
		if(this.rendered){
			this.form.getForm().reset();
		}
		
		var type = this.record == null ? null : this.record.get('type');
		var nonEditable = false;
		if(type == 'HYBRID_DEFAULT' || type == 'DEFAULT')
			nonEditable = true;
		
		// Create the preview window	
		var showCloseButton = false;
		if(nonEditable)
			showCloseButton = true;
		
		this.preview = new com.evoca.players.PreviewWindow(showCloseButton, this.parent, this.record, {scope:this});
		

		if(nonEditable != true) {
			com.evoca.players.CreateWindow.superclass.show.apply(this, arguments);
			this.setPosition(30, 80);
			this.preview.show();
			this.preview.anchorTo('ev-create-window', 'tr');
			this.preview.enable();
			if(this.record != null) {
				this.loadPlayer(this.record);
			}
			else
				this.loadOrientation('defaults');
				
			if(!this.enableShareButton.checked)
				this.hideField(this.shareButtonTheme);
		}
		else {
			
			this.preview.show();
			this.preview.loadPlayer(this.record);
			this.preview.setPosition(30, 80);
		}
	},
	
	close : function() {
		this.destroy();
		this.preview.destroy();
		this.enableParent();
	},
		
	disableParent : function() {
		if(this.parent) {
			this.parent.addClass('x-item-disabled');
		}
	},
	
	enableParent : function() {
		if(this.parent)
			this.parent.removeClass('x-item-disabled');
	},
	
	loadOrientation: function(orientationName) {		
		// Reset form to defaults
		var field;
		for(var prm in this.orientationDefaults) {
			field = this.form.getForm().findField(prm);
			if(field.getValue() == null || field.getValue() == '') {
				field.setValue(this.orientationDefaults[prm]);
			}
		}
		
		// Load the example into the form fields
		if(orientationName) {
			for(var prm in this.orientations[orientationName]) {
				field = this.form.getForm().findField(prm);
				if(field.getValue() == null)
					field.setValue(this.orientations[orientationName][prm]);
			}
			
			this.updateOrientationValues();
			
			// Load the player
			if(orientationName != 'defaults') {
				this.refreshPreview();
			}
		}
	},
	
	updateOrientationValues: function(doc) {
		if(!doc)
			doc = this;

		var playerUtils = new com.evoca.players.PlayerUtils();
		
		var playlistlocation = doc.form.getForm().findField('playlist').getValue();
		var playlistsize = doc.form.getForm().findField('playlistsize').getValue();
		var orientation = doc.form.getForm().findField('picker').getValue();
		var displaywidth = doc.form.getForm().findField('width').getValue();
		var displayheight = doc.form.getForm().findField('height').getValue();
		var swfWidth = doc.form.getForm().findField('swfwidth').getValue();
		var swfHeight = doc.form.getForm().findField('swfheight').getValue();		
		
		// Put the player into the correct orientation
		if(orientation != null) {
			if(orientation == 'normal') {
				if(swfHeight <= 20)
					doc.form.getForm().findField('swfheight').setValue('140');
				if(swfWidth == 0)
					doc.form.getForm().findField('swfwidth').setValue('320');
				
				doc.form.getForm().findField('playlist').setValue('right');
				doc.form.getForm().findField('playlistsize').setValue(doc.form.getForm().findField('swfwidth').getValue());
			}
			else if(orientation == 'below') {
				if(swfHeight <= 20)
					doc.form.getForm().findField('swfheight').setValue('140');
				if(swfWidth == 0)
					doc.form.getForm().findField('swfwidth').setValue('320');
				
				doc.form.getForm().findField('playlist').setValue('bottom');
				doc.form.getForm().findField('playlistsize').setValue(eval(doc.form.getForm().findField('swfheight').getValue()) - 20);
			}
			else if(orientation == 'line') {
				doc.form.getForm().findField('swfheight').setValue('20');
				if(swfWidth == 0)
					doc.form.getForm().findField('swfwidth').setValue('320');
				doc.form.getForm().findField('playlist').setValue('right');
				doc.form.getForm().findField('playlistsize').setValue('0');
			}
			else if(orientation == 'rightlist') {
				doc.form.getForm().findField('playlist').setValue('right');
				if(swfHeight <= 20)
					doc.form.getForm().findField('swfheight').setValue('140');
				if(swfWidth == 0)
					doc.form.getForm().findField('swfwidth').setValue('320');
				if(playlistsize == 0 || playlistsize == swfWidth)
					doc.form.getForm().findField('playlistsize').setValue('120');
			}
			else if(orientation == 'abovebelow') {
				doc.form.getForm().findField('playlist').setValue('bottom');
				if(swfHeight <= 20) {
					doc.form.getForm().findField('swfheight').setValue('240');
					doc.form.getForm().findField('playlistsize').setValue('100');
				}
				else
					doc.form.getForm().findField('playlistsize').setValue((swfHeight / 2) - 20);
				if(swfWidth == 0)
					doc.form.getForm().findField('swfwidth').setValue('320');
			}
			
			this.form.getForm().findField('width').setValue(com.evoca.players.util.calculateDisplaywidthSize(orientation, swfWidth, doc.form.getForm().findField('playlistsize').getValue()));
			this.form.getForm().findField('height').setValue(com.evoca.players.util.calculateDisplayheightSize(orientation, swfHeight, doc.form.getForm().findField('playlistsize').getValue()));
		}
	},

	
	loadPlayer : function(record) {
		if(record != null) {
			this.loadForm(record);
			this.preview.loadPlayer(record);
		}
	},
	
	refreshPreview : function(doc) {
		if(!doc)
			doc = this;

		var playerUtils = new com.evoca.players.PlayerUtils();
		var record = playerUtils.createPlayerRecord();
		
		var orientation = doc.form.getForm().findField('picker').getValue();
		var w = doc.form.getForm().findField('width').getValue();
		var h = doc.form.getForm().findField('height').getValue();
		var l = doc.form.getForm().findField('location').getValue();
		var playerName = doc.form.getForm().findField('playerName').getValue();
		var swfWidth = doc.form.getForm().findField('swfwidth').getValue();
		var swfHeight = doc.form.getForm().findField('swfheight').getValue();
		var type = doc.form.getForm().findField('type').getValue();
		var swfFilename = doc.form.getForm().findField('swfFilename').getValue();
		var htmlHeader = doc.form.getForm().findField('htmlHeader').getValue();
		var htmlFooter = doc.form.getForm().findField('htmlFooter').getValue();
		
		var playlistLocation = this.form.getForm().findField('playlist').getValue();
		var playlistsize = this.form.getForm().findField('playlistsize').getValue();
		
		var enableShareButton = this.form.getForm().findField('enableShareButton').getValue();
		var shareButtonTheme = this.form.getForm().findField('shareButtonTheme').getValue();
		
		
		// Adjust the size of the display		
		this.form.getForm().findField('width').setValue(com.evoca.players.util.calculateDisplaywidthSize(orientation, swfWidth, playlistsize));
		this.form.getForm().findField('height').setValue(com.evoca.players.util.calculateDisplayheightSize(orientation, swfHeight, playlistsize));
		
		var so = new SWFObject(l,'mpl',swfWidth,swfHeight,'9');

		this.calculateFlashvars(doc);

		var playerRecord = new record({
			name: playerName,
			htmlHeader: htmlHeader,
			htmlFooter: htmlFooter,
			swfFilename: swfFilename,
			swfHeight: swfHeight,
			swfWidth: swfWidth,  
			type: type,
			playerParams: doc.form.getForm().findField('flashVars').getValue(),
			enableShareButton: enableShareButton,
			shareButtonTheme: shareButtonTheme
		});

		this.preview.loadPlayer(playerRecord);
		
	},
	
	calculateFlashvars : function(doc) {
		var flashVars = '';
		
		for(var prm in doc.form.getForm().getValues()) {
			if(	prm != 'picker' && 
				prm != 'flashVars' && 
				prm != 'type' && 
				prm != 'swfFilename' && 
				prm != 'oldPlayerName' && 
				prm != 'playerName' && 
				prm != 'htmlHeader' && 
				prm != 'htmlFooter' && 
				prm != 'swfwidth' && 
				prm != 'swfheight' &&
				prm != 'width' &&
				prm != 'height' &&
				prm != 'location' &&
				prm != 'enableShareButton' &&
				prm != 'shareButtonTheme') {
				if(prm != 'file') {
					flashVars += ',' + prm + '=' + doc.form.getForm().findField(prm).getValue();
				}
			}
		}
		
		doc.form.getForm().findField('flashVars').setValue(flashVars);
	},
	
	loadForm : function(record) {
		if(record != null) {
			// Reset form to defaults
			for(var prm in this.orientationDefaults) {
				this.form.getForm().findField(prm).setValue(this.orientationDefaults[prm])
			}
			
			this.form.getForm().findField('playerName').setValue(record.get('name'));
			
			var swfWidth = null
			var swfHeight = null;
			
			if(record.get('htmlHeader') != null && record.get('htmlHeader') != 'null')
				this.form.getForm().findField('htmlHeader').setValue(record.get('htmlHeader'));
				
			if(record.get('htmlFooter') != null && record.get('htmlFooter') != 'null')
				this.form.getForm().findField('htmlFooter').setValue(record.get('htmlFooter'));
				
			if(record.get('swfWidth') != null && record.get('swfWidth') != 'null') {
				swfWidth = record.get('swfWidth');
				this.form.getForm().findField('swfwidth').setValue(swfWidth);
			}
				
			if(record.get('swfHeight') != null && record.get('swfHeight') != 'null') {
				swfHeight = record.get('swfHeight');
				this.form.getForm().findField('swfheight').setValue(swfHeight);
			}
			
			var flashVars = record.get('playerParams') == null ? '' : record.get('playerParams');
			var flashParts = flashVars.split(',');
			alert(flashVars + '\n\n' + flashParts);
			var partt;
			var part;
			var playlistLocation = null;//, swfWidth, swfHeight, width
			var playlistsize = null;
			for(var i = 0; i <  flashParts.size(); i++) {
				partt = flashParts[i];
				
				if(partt != null && partt != '') {
					part = partt.split('=');
					
					this.form.getForm().findField(part[0]).setValue(part[1]);
					
					if(part[0] == 'playlistsize')
						playlistsize = part[1];
						
					else if(part[0] == 'playlist')
						playlistLocation = part[1];
				}		
			}
			
			var orientation = com.evoca.players.util.calculateOrientation(playlistLocation, swfWidth, playlistsize)
			this.form.getForm().findField('picker').setValue(orientation);
			this.form.getForm().findField('width').setValue(com.evoca.players.util.calculateDisplaywidthSize(orientation, swfWidth, playlistsize));
			this.form.getForm().findField('height').setValue(com.evoca.players.util.calculateDisplayheightSize(orientation, swfHeight, playlistsize));
			
			// Default version to 4
			var version = this.form.getForm().findField('v').getValue(); 
			if(version == null || version == '') {
				this.form.getForm().findField('v').setValue('4');
			}
		}
	},
	
	/*
	 * hideField
	 */ 
	hideField : function(field) {
		if(field) {
			var labelEl = field.getEl();
			
			if(labelEl && labelEl.up('.x-form-item')) {
				field.disable();
				field.hide();
				labelEl.up('.x-form-item').setDisplayed(false);
			}
		}
	},
	
	/*
	 * showField
	 */ 
	showField : function(field) {
		if(field) {
			var labelEl = field.getEl();
			
			if(labelEl && labelEl.up('.x-form-item')) {
				field.enable();
				field.show();
				labelEl.up('.x-form-item').setDisplayed(true);
			}
		}
	}
});


com.evoca.players.HtmlWizard = function(rawHtml, parent, formFieldID, title) {	
	///parent.preview.disable();
	this.preview = parent.preview;
	this.playerCode = $('flashPlayerCode').innerHTML;
	$('flashPlayerCode').innerHTML = '';
	this.parent = parent;
	this.htmlEditor = new Ext.form.HtmlEditor({
		id: 'htmlEditor',
		width: 570,
		height: 350,
		hideLabel: true,
		enableLists: false,
		value: rawHtml
	});
	
	this.form = new Ext.FormPanel({
		border: false,
		labelAlign:'right',
		bodyStyle:'background:transparent;padding:10px;',
		items: [this.htmlEditor]
	});

	if(title == null)
		title = 'HTML Editor';

	com.evoca.players.HtmlWizard.superclass.constructor.call(this, {
		title: title,
		id: 'ev-html-window',
		height: 450,
		width: 610,
		bodyStyle: 'background:transparent;position:relative',
		resizable: false,
		stateful: false,
		titleBar: true,
		//plain:true,
		modal: true,
		closable: true,
		items: [this.form],
		scope: this,
		closeAction: 'close',
		buttons:[{
			text: 'Save',
			scope: this,
			handler: function(){
				if (this.form.getForm().isValid()) {
					$('flashPlayerCode').innerHtml = this.playerCode;
					parent.form.getForm().findField(formFieldID).setValue(this.form.getForm().findField('htmlEditor').getValue());
					//parent.removeClass('x-item-disabled');
					//parent.preview.removeClass('x-item-disabled');

					parent.refreshPreview();
					
					this.destroy();
					
				}
			}
		},{
			text: 'Cancel',
			handler: this.close.createDelegate(this, [])
		}]
	});
}

Ext.extend(com.evoca.players.HtmlWizard, Ext.Window, {
	show : function(){
		if(this.rendered){
			this.form.getForm().reset();
		}
		com.evoca.players.HtmlWizard.superclass.show.apply(this, arguments);
	},
	
	close : function(){
		$('flashPlayerCode').innerHtml = this.playerCode;
		//this.parent.removeClass('x-item-disabled');
		//this.parent.preview.removeClass('x-item-disabled');
		this.destroy();
	}
});

/**
  * PreviewWindow
  * 
  * If selectedRecording is not null (single recording), it will be used for the player. Otherwise
  * playlistURL will be used (playlist)
  */

com.evoca.players.PreviewWindow = function(showCloseButton, parent, record, playerStore, selectedRecording, playlistURL) {
	log('\n\nSTART: com.evoca.players.PreviewWindow');
	this.parent = parent;
	this.record = record;
	
	var isPlaylist = false; // we are generating a player for a single recording
	
	if(selectedRecording == null && playlistURL != null) {
		isPlaylist = true;
	}
	
	log('isPlaylist: ' + isPlaylist);

	this.showCloseButton = showCloseButton;
	
	var closable = false;
	var width = 50;
	
	if(record != null && record.get('swfWidth') != null)
		width += eval(record.get('swfWidth'));

	var closeButton = new Ext.Button({
		text: 'Close',
		scope: this,
		handler: function(){
			this.close();
		}
	});
	
	if(showCloseButton && record != null && record.get('swfWidth') != null) {
		width = 400;
		closable = true;
	}
	else {
		closable = false;
		closeButton.hide();
	}
	
	var tmpRecordingID = '-1';
	
	if(!isPlaylist) {
		tmpRecordingID = selectedRecording.get('recordingID');
	}
	
	log('tmpRecordingID: ' + tmpRecordingID);
	
	var copyid = 'playerClipButton' + tmpRecordingID;
	log('copyid: ' + copyid);
	var copyButton = '<div id="' + copyid + '" name="' + copyid + '" style="float:right" class="clipButton">Copy</div>';

	//var createWindow = new com.evoca.players.CreateWindow(record, this);
	//createWindow.show();
	
	var headerPanel = new Ext.Panel({
		id: 'headerPanel',
		border: false,
		html: '<span id="prefHtmlHeader">' + this.getHtmlHeader(record) + '</span>',
		bodyStyle: 'position:relative;background:transparent;padding:10px;',
		scope: this
	});

	/*
	name: 'Mini',
	swfFilename: 'wpaudioplayer.swf',
	swfHeight: 24,
	swfWidth: 290,
	type: 'HYBRID_WP',
	enableShareButton: true,
	shareButtonTheme: '6',
	transparent: true,
	playerParams: 'initialvolume=80'
	*/
	
	
	/*
	 * new Ext.data.Store({
			autoDestroy: true,
			reader: new Ext.data.ArrayReader({}, [
				{name: 'player'},
				{name: 'width'},
				{name: 'height'}
			]),
			data: [
				['Mini', 'Extends to 290', '24'],
				['Small', '126', '20'],
				['Medium', '223', '20'],
				['Large', '320', '20']
			]
	 */
	
	/*
	playerStore.filterBy(function(record, id) {
		if(record != null && record.get('name') != null && record.get('name') != '')
			return true;
		else
			return false;
	});
	*/
	
	
	var recordsForGrid = playerStore.queryBy(function(record, id) {
		if(record != null && record.get('name') != null && record.get('name') != '')
			return true;
		else
			return false;
	});
	log('recordsForGrid: ' + recordsForGrid.length);
	

	//playerStore.removeAt(0);
	
	var playerGrid = new Ext.grid.GridPanel({
		store: playerStore,
		colModel: new Ext.grid.ColumnModel({
			defaults: {
				width: 120,
				sortable: true
			},
			columns: [
				{id: 'player', header: 'Player', width: 50, sortable: true, dataIndex: 'name'},
				{id: 'width', header: '<center>Width</center>', css: 'text-align: center;', width: 90, sortable: true, dataIndex: 'swfWidth'},
				{id: 'height', header: '<center>Height</center>', css: 'text-align: center;', width: 50, sortable: true, dataIndex: 'swfHeight'}
			]
		}),
		/*
		viewConfig: {
			//forceFit: true,

			// Return CSS class to apply to rows depending upon data values
			getRowClass: function(record, index, rowParams, store) {
				var name = record.get('name');
				if (name == null || name == '') {
					log('hidding row');
					return 'progressBar-container';
				} 
			}
	    },
	    */
		autoHeight: true,
		autoHeight: true,
		frame: false,
		title: '<span style="color:black">Player dimensions</span>',
		iconCls: 'icon-grid'
	});
	
	var playerTypePanel = new Ext.Panel({
		id: 'playerTypePanel',
		border: false,
		bodyStyle: 'background:transparent;margin-left: 110px;',
		scope: this,
		width: 302,
		items: [playerGrid]
	});
	
	
	var html = '';
	html += '<center>';
	html += 	'<b>';
	html += 		'Save code to embed. Code is deleted when this window is closed.';
	html += 		' Or create a custom player using the <a href="javascript:expandPlayerWizard(); Ext.getCmp(\'ev-preview-window\').destroy();">player wizard</a>';
	html += 	'</b>';
	html += '</center>';
	
	var footerPanel = new Ext.Panel({
		id: 'footerPanel',
		border: false,
		html: html,
		bodyStyle: 'position:relative;background:transparent;padding:10px;',
		scope: this
	});
	
	var playerPanel = new Ext.Panel({
		id: 'playerPanel',
		border: false,
		html: '<div id="preview"><div id="flashPlayerCode" name="flashPlayerCode">&nbsp;</div><div id="prevFooter"></div><div id="hiddenTextArea"></div><div id="prevShareButton"></div></div>',
		bodyStyle: 'position:relative;background:transparent;padding:10px;',
		scope: this
	});
	
	var playerBox = new Ext.form.ComboBox({
		store: playerStore,
		//fieldLabel: 'Copy-n-Paste Code',
		fieldLabel: 'Copy-n-Paste Code',
		displayField: 'name',
		mode: 'local',
		selectOnFocus: false,
		editable: false,
		triggerAction: 'all',
		xtype: 'combo',
		forceSelection: true,
		scope: this,
		value: record.get('name'),
		listeners:{
			scope: this,
			'select': function(combo, record, index) {
				this.loadPlayer(record, selectedRecording, playlistURL);
				this.loadHtmlHeader(record);
			}
		}
	});
	
	var copyAndPastCode = new Ext.form.TextArea({
		id: 'copyAndPasteCode',
		//fieldLabel: 'Copy-n-Paste Code',
		hideLabel: true,
		width: width - 15,
		height: 100,
		scope: this,
		readOnly: true,
		selectOnFocus: true,
		listeners: {
			render: function() {
				this.selectText();
			}
			/*
			focus: function(sm) {
				this.selectText();
			},
			keypress: function(sm) {
				this.selectText();
			},
			keyup: function(sm) {
				this.selectText();
			}
			*/
		}
	});
	
			
	var codePanel = new Ext.form.FormPanel({
		id: 'codePanel',
		border: false,
		autoHeight: true,
		bodyStyle: 'position:relative;background:transparent;padding:10px;',
		scope: this,
		labelWidth: 214,
		labelAlign: 'right',
		html: copyButton,
		items: [playerBox, copyAndPastCode]
	});
	
	com.evoca.players.PreviewWindow.superclass.constructor.call(this, {
		title: 'Preview',
		id: 'ev-preview-window',
		plain: false,
		autoHeight: true,
		width: width,
		modal: true,
		stateful: false,
		closable: closable,
		frame: true,
		bodyStyle: 'position:relative;background:transparent;padding:10px;',
		buttons:[closeButton],
		buttonAlign: 'right',
		items: [headerPanel, playerPanel, codePanel, footerPanel/*, playerTypePanel*/]
	});
	
	this.on('render', function(){
		this.loadPlayer(record, selectedRecording, playlistURL);
	});
	
	this.on('afterlayout', function(){
		this.loadCopyButton(selectedRecording, playlistURL);
	});
	
	this.on('move', function(){
		this.loadCopyButton(selectedRecording, playlistURL);
	});
	

	this.on('destroy', function(){
		var combo = Ext.getCmp('playlistPlayerEditorColumn');
		
		if(combo)
			combo.clearValue();
	});

	log('END: com.evoca.players.PreviewWindow\n\n');
}

Ext.extend(com.evoca.players.PreviewWindow, Ext.Window, {
	loadHtmlHeader : function(player) {
		if($('prefHtmlHeader')) {
			//alert('foo');
			$('prefHtmlHeader').innerHTML = this.getHtmlHeader(player);
		}
	},
	getHtmlHeader : function(player) {
		if(player != null) {
			var extraText = '';
			
			if(player.get("type") == 'HYBRID_WP')
				extraText = 'expanded to ';
			
			var htmlHeader = '<center><span class="security_private">';
			htmlHeader += 'This preview shows the working player that is';
			htmlHeader += ' ' + extraText + player.get('swfWidth') + ' pixels wide';
			htmlHeader += ' x ' + player.get('swfHeight') + ' pixels high.';
			htmlHeader += ' The “share button” destination sites (e.g. Facebook, ';
			htmlHeader += ' LinkedIn, etc.) shown when you click on it are for';
			htmlHeader += ' illustration only. It is active when embedded.';
			htmlHeader += '</span></center>';
			
			return htmlHeader;
		}
	},
	loadCopyButton : function(recording, playlistURL) {
		var recordingID = "-1";
		
		if(recording != null) {
			recordingID = selectedRecording.get('recordingID');
		}

		var copyid = 'playerClipButton' + recordingID;
		//log('copyID: ' + copyid);
		
		var clip = getClipObject(copyid, 'copyAndPasteCode', root);
		log('clip: ' + clip);
	},
	show : function(){
		com.evoca.players.PreviewWindow.superclass.show.apply(this, arguments);
	},
	
	close: function() {
		this.destroy();
	},
	getPlayerCode: function(player, recording, playlistURL) {
		if(player != null && (recording != null || playlistURL != null )) {
			var isPlaylist = false;
			
			if(recording == null && playlistURL != null) {
				isPlaylist = true;
			}
			
			var shareURL = playlistURL;
			
			if(recording != null) {
				shareURL = recording.get('shareURL');
			}
				
			var hostParts = shareURL.split('.com');
			
			var host = '';
			
			if(hostParts != null && hostParts.length >= 1)
				host = hostParts[0] + '.com/';
			
			log('host: ' + host);
			
			var filename = player.get('swfFilename');
			var w = player.get('swfWidth');
			var h = player.get('swfHeight');
			var enableShareButton = player.get('enableShareButton');
			var shareButtonTheme = player.get('shareButtonTheme');
			var l = host + 'evocaPlayer/';
			var htmlHeader = (player.get('htmlHeader')) ? player.get('htmlHeader') : '';
			var htmlFooter = (player.get('htmlFooter')) ? player.get('htmlFooter') : '';
			
			if(filename == null || filename == '' || filename == 'playlistDefault')
				l += 'ev-pl-4x.swf';
			else
				l += filename;
			
			
			var src = l; // object param=movie, embed src
			var allowfullscreen = true;
			
			var object = '\r\n\t\t&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0" width="' + w + '" height="' + h + '"&gt;';
			object += '\r\n\t\t\t&lt;param name="movie" value="' + l + '"&gt;';
			object += '\r\n\t\t\t&lt;param name="quality" value="high"/&gt;';
			object += '\r\n\t\t\t&lt;param name="allowScriptAccess" value="always"/&gt;';
			
			if(player.get('transparent'))
				object += '\r\n\t\t\t&lt;param name="wmode" value="transparent"&gt;';
			
			var embed = '\r\n\t\t\t&lt;embed src="' + l + '" width="' + w + '" height="' + h + '" allowfullscreen="true" allowscriptaccess="always" ';
			
			if(player.get('transparent'))
				embed += ' wmode="transparent" ';
			
			embed += ' flashvars="';
			
						
			var flashVars = player.get('playerParams') == null ? '' : player.get('playerParams');
			var flashParts = flashVars.split(',');
			var partt;
			var part;
			var flashVarsToUse = '';
			var count = 0;
			
			for(var i = 0; i <  flashParts.length; i++) {
				partt = flashParts[i];
				
				if(partt != null && partt != '') {
					part = partt.split('=');
					
					if(part[0] == 'skin' || part[0] == 'plugins')
						part[1] = host + 'evocaPlayer/' + part[1];
					
					
					if(count > 0)
						flashVarsToUse += '&';
						
					flashVarsToUse += part[0] + '=' + part[1];
					
					count++;
				}		
			}
			
			var type = player.get('type');
			
			if(type && type == 'HYBRID_WP') {
				var title = recording.get('title');
				
				if(!title)
					title = "";
				
				log("title before: " + title);
				title = title.replace(/"/g, "%22");
				log("title after: " + title);
				
				flashVarsToUse += '&titles=' + title;
				flashVarsToUse += '&rid=' + recording.get('recordingID');
				flashVarsToUse += '&soundFile=' + recording.get('directURL');
				flashVarsToUse += '&host=' + host;
			}
			
			if(isPlaylist) {
				flashVarsToUse += '&file=' + playlistURL;
			}
			else {
				log('\n\n#####host: ' + host);
				flashVarsToUse += '&listenURL=' + host + 'lc.jsp?rid=' + recording.get('recordingID');
				flashVarsToUse += '&file=' + recording.get('directURL');
			}
			
			object += '\r\n\t\t\t&lt;param name="flashVars" value="' + flashVarsToUse + '" /&gt;';
			
			embed += flashVarsToUse + '"&gt;&lt;/embed&gt;';
			
			object = object + embed + '\r\n\t\t&lt;/object&gt;';
	
			var code = ''; 
			code += '&lt;div style="width:' + w + ';" id="flashPlayerHTML-' + player.get('name') + '"&gt;';
			code += '\r\n\t&lt;div id="playerHeader"&gt;' + htmlHeader + '&lt;/div&gt;';
			
			code += '\r\n\t&lt;div class="evocaFlashPlayer" id="playerCode"&gt;' + object + '\r\n\t&lt;/div&gt;';
			
			code += 	'\r\n\t&lt;div id="playerFooter"&gt;' + htmlFooter + '&lt;/div&gt;';
			// add gigya player
			code += '\r\n&lt;/div&gt;';
			
			if(enableShareButton != null && (enableShareButton == 'true' || enableShareButton == true)) {
				var textAreaName = 'codeInfo' + player.get('name');
				var gigaycodestart = '\r\n&lt;textarea style="display:none" id="' + textAreaName + '"&gt;';
				var gigaycodeend = '\r\n&lt;/textarea&gt;';
				var gigaycodeScript = "&lt;script src='http://cdn.gigya.com/wildfire/JS/WFButton.js?defaultContent=" + textAreaName + "&module=post&widgetTitle=Evoca%20Recording&partner=597482&cid=codefield&theme=6&b=click&btnurl=http%3A%2F%2Fwww.evoca.com%2Fimages%2Fshare-button.jpg'&gt;&lt;/script&gt;";
			}
			
			var fullCode = code + gigaycodestart + '\r\n' + code + gigaycodeend + gigaycodeScript;
			//return "&lt;a href=''&gt;foo&lt;/a&gt;";
			return fullCode;
		}
	},
	
	loadPlayer : function(player, recording, playlistURL) {
		if(player != null) {
			var isPlaylist = false;
			//alert(recording == null);
			//alert(playlistURL != null);
			if(recording == null && playlistURL != null) {
				isPlaylist = true;
			}
			
			var host = '';
			
			var shareURL = playlistURL;
			
			
			if(!isPlaylist) {
				shareURL = recording.get('shareURL');
			}
		
			var hostParts = shareURL.split('.com');
			
			
			if(hostParts != null && hostParts.length >= 1)
				host = hostParts[0] + '.com/';
			
			var playerUtils = new com.evoca.players.PlayerUtils();
			//playerUtils.isPlaylistPlayer(player);
			
			var filename = player.get('swfFilename');
			var w = player.get('swfWidth');
			var h = player.get('swfHeight');
			
			var enableShareButton = player.get('enableShareButton');
			var shareButtonTheme = player.get('shareButtonTheme');
			
			var windowWidth = eval(w) + 50;
			
			var minShareButtonWidth = 440;
			if((enableShareButton == "true" || enableShareButton == true) && windowWidth < minShareButtonWidth)
				windowWidth = minShareButtonWidth;
			
			this.setWidth(windowWidth); 
			this.doLayout();
			
			var l = host + 'evocaPlayer/';
			
			if(filename == null || filename == '' || filename == 'playlistDefault')
				l += 'ev-pl-4x.swf';
			else
				l += filename;
			
			
			var so = new SWFObject(l,'embeddedPlayer',w,h,'9');
			so.addParam('allowfullscreen',true);
			
			if(player.get('transparent')) {
				so.addParam('wmode', 'transparent');
			}

			var file = shareURL;
			
			if(!isPlaylist) {
				file = recording.get('directURL');
			}
			
			
			so.addVariable('file', file);
			so.addVariable('allowScriptAccess', "always");
			
			var flashVars = player.get('playerParams') == null ? '' : player.get('playerParams');
			var flashParts = flashVars.split(',');
			var partt;
			var part;
			
			for(var i = 0; i <  flashParts.length; i++) {
				partt = flashParts[i];
				
				if(partt != null && partt != '') {
					part = partt.split('=');
					
					if(part[0] == 'skin' || part[0] == 'plugins')
						part[1] = host + 'evocaPlayer/' + part[1];
						
					log('adding: ' + part[0] + '=' + part[1]);
					so.addVariable(part[0], part[1]);
				}		
			}
			
			var tmpRecordingID = "-1";
			
			if(!isPlaylist) {
				tmpRecordingID = recording.get('recordingID');
			}

			var directURL = file;
				
			var type = player.get('type');
			log('type: ' + type);
			
			if(type && type == 'HYBRID_WP') {
				
				var title = recording.get('title');
				
				if(!title)
					title = "";
				
				log("title before: " + title);
				title = title.replace(/"/g, "%22");
				log("title after: " + title);
				
				so.addVariable('titles', title);
				so.addVariable('rid', tmpRecordingID);
				so.addVariable('soundFile', file);
				
			}
			
			so.write('flashPlayerCode');

			if(player.get('htmlHeader') != null && player.get('htmlHeader') != 'null')
				$('prevHeader').innerHTML = player.get('htmlHeader');
				
			if(player.get('htmlFooter') != null && player.get('htmlFooter') != 'null')
				$('prevFooter').innerHTML = player.get('htmlFooter');
				
			// TODO: Make sure we're using the correct gigya widget
			$('hiddenTextArea').innerHTML = "";
			$('prevShareButton').innerHTML = "";
			if(enableShareButton != null && (enableShareButton == 'true' || enableShareButton == true)) {
				var shareButton3 = "";
				shareButton3 += '<a id="previewShareLink" href="javascript:com.evoca.players.displayEmbedWidget(\'codeInfo\', \'gigyaWidget\', \'' + shareButtonTheme + '\');"><img src="' + host + 'images/share-button.jpg"><div id="gigyaWidget" name="gigyaWidget"></div></a>';
				
				var textAreaStart = "<textarea style=\"display:none\" id=\"codeInfo\" name=\"codeInfo\">";
				var textAreaEnd = "</textarea>";
				var textArea = textAreaStart + $('preview').innerHTML + textAreaEnd;
				$('hiddenTextArea').innerHTML = textArea;
				$('prevShareButton').innerHTML = shareButton3;
			}
			
			if($('copyAndPasteCode'))
				$('copyAndPasteCode').innerHTML = this.getPlayerCode(player, recording, playlistURL);
		}
	}
});

Ext.apply(Ext.form.VTypes, {
	'hexnum': function(){
		var re = /0\x[a-fA-F\d]{6}/;
		return function(v){
			return re.test(v);
		}
	}(),
	'hexnumText' : 'The format is wrong, ie: 0xFFFFFF'
});

Ext.apply(Ext.form.VTypes, {
	'wholenum': function() {
		var whole = /^[0-9]+$/;
		return function(v){
			return whole.test(v);
		}
	}(),
	'wholenumText': 'The field must be a valid whole number'
});

com.evoca.players.PlayerUtils = function() {
	/**
	 * Returns a player list object based off xml string
	 */
	this.createPlayerRecord = function() {
		var playerRecord = Ext.data.Record.create([
			{name: 'name', mapping: '@name', type:'string'},
			{name: 'swfFilename'},
			{name: 'swfHeight'},
			{name: 'swfWidth'},  
			{name: 'transparent'},  
			{name: 'type'},
			{name: 'playerParams'},
			{name: 'index'},
			{name: 'htmlHeader'},
			{name: 'htmlFooter'},
			{name: 'enableShareButton'},
			{name: 'shareButtonTheme'}
		]);
		
		return playerRecord;
	},
	
	this.getPlayerArrayReader = function() {
		var reader = new Ext.data.ArrayReader({}, [
			{name: 'name'},
			{name: 'swfFilename'},
			{name: 'swfHeight'},
			{name: 'swfWidth'},  
			{name: 'transparent'},
			{name: 'type'},
			{name: 'playerParams'},
			{name: 'index'},
			{name: 'htmlHeader'},
			{name: 'htmlFooter'},
			{name: 'enableShareButton'},
			{name: 'shareButtonTheme'}
		]);
		
		return reader;
	},
	
	/*
	 * Single recording players
	 */
	this.getEvocaStandardPlayerRecords = function() {
		var playerRecord = this.createPlayerRecord();
		
		var hiddenPlayer = new playerRecord({
			name: '',
			swfHeight: 20,
			swfWidth: 126,
			//swfWidth: 145,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'playlist=none,playlistsize=0,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs-simple.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var miniPlayer = new playerRecord({
			name: 'Mini',
			swfFilename: 'wpaudioplayer.swf',
			swfHeight: 24,
			swfWidth: 290,
			type: 'HYBRID_WP',
			enableShareButton: true,
			shareButtonTheme: '6',
			transparent: true,
			playerParams: 'initialvolume=80'
		});
		
		var smallPlayer = new playerRecord({
			name: 'Small',
			swfHeight: 20,
			swfWidth: 126,
			//swfWidth: 145,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'playlist=none,playlistsize=0,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs-simple.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var mediumPlayer = new playerRecord({
			name: 'Medium',
			swfHeight: 20,
			swfWidth: 223,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'showrepeate=false,playlist=none,playlistsize=0,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var largePlayer = new playerRecord({
			name: 'Large',
			swfHeight: 20,
			swfWidth: 320,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'showrepeate=false,playlist=none,playlistsize=0,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		if(!Ext.isGecko)
			return [hiddenPlayer, miniPlayer, smallPlayer, mediumPlayer, largePlayer];
		else
			return [miniPlayer, smallPlayer, mediumPlayer, largePlayer];
	},
	
	/*
	 * Playlist players
	 */
	this.getEvocaStandardPlaylistPlayerRecords = function() {
		var playerRecord = this.createPlayerRecord();
		
		var hiddenPlayerPlaylist = new playerRecord({
			name: '',
			swfHeight: 20,
			swfWidth: 126,
			//swfWidth: 145,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'maxResults=20,playlist=right,playlistsize=290,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var smallPlayerPlaylist = new playerRecord({
			name: 'Small',
			swfHeight: 100,
			swfWidth: 126,
			//swfWidth: 145,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'maxResults=20,playlist=bottom,playlistsize=80,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs-simple.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var mediumPlayerPlaylist = new playerRecord({
			name: 'Medium',
			swfHeight: 100,
			swfWidth: 223,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'maxResults=20,showrepeate=false,playlist=bottom,playlistsize=80,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var largePlayerPlaylist = new playerRecord({
			name: 'Large',
			swfHeight: 150,
			swfWidth: 320,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			playerParams: 'maxResults=20,showrepeate=false,playlist=bottom,playlistsize=130,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		var extraLargePlaylist = new playerRecord({
			name: 'Extra Large',
			//swfFilename: 'wpaudioplayer.swf',
			swfHeight: 210,
			swfWidth: 500,
			type: 'HYBRID_DEFAULT',
			enableShareButton: true,
			shareButtonTheme: '6',
			transparent: true,
			playerParams: 'maxResults=20,showrepeate=false,playlist=bottom,playlistsize=190,v=4,plugins=ee-plugin.swf,skin=jw-default-skin-no-thumbs.swf,backcolor=0xffffff,frontcolor=0x000000,lightcolor=0x000000,screencolor=0x000000,stretching=uniform,displayclick=play,autostart=false,repeat=false,shuffle=false,volume=80'
		});
		
		
		
		if(!Ext.isGecko)
			return [hiddenPlayerPlaylist, smallPlayerPlaylist, mediumPlayerPlaylist,largePlayerPlaylist , extraLargePlaylist];
		else
			return [smallPlayerPlaylist, mediumPlayerPlaylist,largePlayerPlaylist , extraLargePlaylist];
	},
	
	/*
	 * Get single player store
	 */
	this.getPlayerStore = function(root, userID) {
		//var url = root + 'Request?action=getAlbums&userID=' + userID;
	
		var store = new Ext.data.Store({});
		
		/*
		var store = new Ext.data.Store({
			url: url,
			autoLoad: true,
			sortInfo: {
				field: 'albumName',
				direction: 'ASC'
			},
			reader: new Ext.data.XmlReader({
				record : 'album',
				totalRecords: 'totalAlbums'
			}, this.createAlbumRecord())
		});
		*/
		
		store.add(this.getEvocaStandardPlayerRecords());
		
		
		return store;
	},
	
	this.getPlaylistPlayerStore = function(root, userID) {
		var store = new Ext.data.Store({});
		
		store.add(this.getEvocaStandardPlaylistPlayerRecords());
		
		return store;
	},
	
	this.isPlaylistPlayer = function(record) {
		var retVal = false;
		
		if(record != null && record.get('type')) {
			var type = record.get('type');
			
			if(type != null && (type == 'HYBRID_DEFAULT' || type == 'HYBRID_CUSTOMIZED'))
				retVal = true;
		}

		return retVal;
	},
	
	this.isDefaultPlayer = function(record) {
		var retVal = false;
		
		if(record != null && record.get('type')) {
			var type = record.get('type');
			
			if(type != null && (type == 'HYBRID_DEFAULT' || type == 'DEFAULT'))
				retVal = true;
		}

		return retVal;
	}
};

com.evoca.players.PlayerListXMLReader = function(meta, recordType){
	com.evoca.players.PlayerListXMLReader.superclass.constructor.call(this, meta, recordType);
};
Ext.extend(com.evoca.players.PlayerListXMLReader, Ext.data.DataReader, {
	/**
	 * This method is only used by a DataProxy which has retrieved data from a remote server.
	 * @param {Object} response The XHR object which contains the parsed XML document.  The response is expected
	 * to contain a method called 'responseXML' that returns an XML document object.
	 * @return {Object} records A data block which is used by an {@link Ext.data.Store} as
	 * a cache of Ext.data.Records.
	 */
	read : function(response){
		var doc = response.responseXML;
		if(!doc) {
			throw {message: "XmlReader.read: XML Document not available"};
		}
		
		return this.readRecords(doc);
	},

	/**
	 * Create a data block containing Ext.data.Records from an XML document.
	 * @param {Object} doc A parsed XML document.
	 * @return {Object} records A data block which is used by an {@link Ext.data.Store} as
	 * a cache of Ext.data.Records.
	 */
	readRecords : function(doc){
		/**
		 * After any data loads/reads, the raw XML Document is available for further custom processing.
		 * @type XMLDocument
		 */
		this.xmlData = doc;
		var root = doc.documentElement || doc;
		var q = Ext.DomQuery;
		var recordType = this.recordType, fields = recordType.prototype.fields;
		var sid = this.meta.id;
		var totalRecords = 0, success = true;
		if(this.meta.totalRecords){
			totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
		}

		if(this.meta.success){
			var sv = q.selectValue(this.meta.success, root, true);
			success = sv !== false && sv !== 'false';
		}
		var records = [];
		var ns = q.select(this.meta.record, root);
		
		for(var i = 0, len = ns.length; i < len; i++) {
			var n = ns[i];
			var values = {};
			var id = sid ? q.selectValue(sid, n) : undefined;
			
			for(var j = 0, jlen = fields.length; j < jlen; j++){
				var f = fields.items[j];
				var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
			
				v = f.convert(v);
				
				values[f.name] = v;
			}
			
			
			// START CUSTOM
			var tmpns = q.select("playerParams/playerParam", n);

			var playerparamvalues = '';
			for(var k = 0, tmplen = tmpns.length; k < tmplen; k++) {
				var playerParam = tmpns[k];
				var name = q.selectValue("name", playerParam);
				var val = q.selectValue("value", playerParam);
				playerparamvalues += ',' + name + '=' + val;
			} 

			values['playerParams'] = playerparamvalues;
			values['index'] = records.length;
			// END CUSTOM
			
			var record = new recordType(values, id);
			record.node = n;
			records[records.length] = record;
			
		}

		return {
			success : success,
			records : records,
			totalRecords : totalRecords || records.length
		};
	}
});

com.evoca.players.util.calculatePlaylistSize = function(playlistLocation, swfWidth, swfHeight, width, height) {
	var retVal = 0;
	
	if(playlistLocation != null) {
		if(playlistLocation == 'right' && swfWidth != null && width != null)
			retVal = eval(swfWidth) - eval(width);
		else if(playlistLocation == 'bottom' && swfHeight != null && height == null)
			retVal = eval(swfHeight) - 20;
		else if(playlistLocation == 'bottom' && swfHeight != null && height != null)
			retVal = eval(swfHeight) - 20 - eval(height);
	}

	return retVal;
}

com.evoca.players.util.calculateDisplaywidthSize = function(orientation, swfWidth, playlistsize) {
	var retVal = 0;
	
	if(orientation != null) {
		if(orientation == 'normal' || orientation == 'below' || orientation == 'line')
			retVal = 0
		else if(orientation == 'rightlist')
			retVal = eval(swfWidth) - playlistsize;
		else if(orientation == 'abovebelow')
			retVal = eval(swfWidth);
	}

	return retVal;
}

com.evoca.players.util.calculateDisplayheightSize = function(orientation, swfHeight, playlistsize) {
	var retVal = 0;
	
	if(orientation != null) {
		if(orientation == 'normal' || orientation == 'below' || orientation == 'line')
			retVal = 0
		else if(orientation == 'rightlist')
			retVal = eval(swfHeight) - 20;
		else if(orientation == 'abovebelow')
			retVal = eval(swfHeight) - eval(playlistsize) - 20;
	}

	return retVal;
}

com.evoca.players.util.calculateOrientation = function(playlistLocation, swfWidth, playlistsize) {
	var retVal = 'default';
	
	if(playlistLocation != null) {
		if(playlistLocation == 'none')
			retVal = 'line';
		else if(playlistLocation == 'right' && playlistsize == swfWidth)
			retVal = 'normal';
		else if(playlistLocation == 'bottom' && playlistsize == swfWidth)
			retVal = 'bottom';
		else if(playlistLocation == 'right' && playlistsize < swfWidth)
			retVal = 'rightlist';
		else if(playlistLocation == 'bottom')
			retVal = 'abovebelow';
	}

	return retVal;
}

/**
 * This submit action is basically the same as the normal submit action,
 * only that it uses the fields getSubmitValue() to compose the values to submit,
 * instead of looping over the input-tags in the form-tag of the form.
 *
 * To use it, just use the OOSubmit-plugin on either a FormPanel or a BasicForm,
 * or explicitly call form.doAction('oosubmit');
 *
 * @param {Object} form
 * @param {Object} options
 */
Ext.ux.OOSubmitAction = function(form, options){
	Ext.ux.OOSubmitAction.superclass.constructor.call(this, form, options);
};

Ext.extend(Ext.ux.OOSubmitAction, Ext.form.Action.Submit, {
	/**
	* @cfg {boolean} clientValidation Determines whether a Form's fields are validated
	* in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.
	* Pass <tt>false</tt> in the Form's submit options to prevent this. If not defined, pre-submission field validation
	* is performed.
	*/
	type : 'oosubmit',

	// private
	/**
	 * This is nearly a copy of the original submit action run method
	 */
	run : function(){
		var o = this.options;
		var method = this.getMethod();
		var isPost = method == 'POST';

		//retrieve the forms values and put them into formValues
		var formValues = {};
		this.form.items.each(function(field) {
			//check if the form item provides a specialized getSubmitValue() and use that if available
			if (typeof field.getSubmitValue == "function") formValues[field.getName()] = field.getSubmitValue();
			else formValues[field.getName()] = field.getValue();
		});

		if(o.clientValidation === false || this.form.isValid()) {
			Ext.Ajax.request(Ext.apply(this.createCallback(o), {
				url:this.getUrl(!isPost),
				method: method,
				params:formValues, //add our values
				isUpload: this.form.fileUpload
			}));

		}
		else if (o.clientValidation !== false){ // client validation failed
			this.failureType = Ext.form.Action.CLIENT_INVALID;
			this.form.afterAction(this, false);
		}
	}

});

/**
 * This plugin can be either used on BasicForm or FormPanel.
 * In both cases it changes the behaviour of submit() to use
 * the 'oosubmit' action instead of the 'submit' action.
 */
Ext.ux.OOSubmit=function() {
	this.init=function(_object) {
		var form=null;
		if (typeof _object.form=="object") { 
			//we are a formpanel:
			form=_object.form;
		}
		else form=_object;

		//Save the old submit method:
		form.oldSubmit=form.submit;

		//create a new submit method which calls the oosubmit action per default:
		form.submit=function(options) {
			this.doAction('oosubmit', options);
			return this;
		};
	};

};

Ext.form.Action.ACTION_TYPES['oosubmit'] = Ext.ux.OOSubmitAction;
// end of file
