/* brightcove_player.js
*
*	BCPlayer -- a simple class for making Brightcove3 player
*
*	Author: Ronan Rafferty
*	Date: 10/03/2009
* 
* 	@param	bc_config:		A string with the JavaScript function name which will be called on completion
* 	@param	divId:		An object that provides div references to return content to the page
* 
* 	Sample Usage: 
* 
* 	var bc_config = {};
* 
* 	bc_config["id"] = "myExperience";
* 	bc_config["bgcolor"] = "#FFFFFF";
* 	bc_config["width"] = 486;
* 	bc_config["height"] = 345;
* 	bc_config["playerId"] = 1847329001;
*	bc_config["publisherID"] = 495713462;
* 	bc_config["@videoPlayer"] = null;
* 	bc_config["@playlistTabs"] = "1375780129,1375772162,1375780130,1485827977"; // String, not number, trust me
* 	bc_config["@playlistTabs.featured"] = null;
* 	bc_config["@playlistTabs.featured"] = 1375772162;
* 	bc_config["@videoList.featured"] = null;
* 	bc_config["@videoList.featured"] = 1375780115;
* 
* 	var myPlayer = new BCPlayer(bc_config, "bcPlayer");
* 
* 	myPlayer.create();
* 
*/
	function BCPlayer(bc_config, divId) 
	{			
		//if(window.console != undefined) console.log("BCPlayer class constructor")
			
		// Instance Properties	
		this.bc_params = bc_config; // holds the config
		this.e; // Used to throw any errors
		this.divId = divId;
		this.created = false;
		
		// Test that the config has the basic requirements of a player
		if(!(typeof bc_config["id"] == 'string')) {
			e = new Error("Not present or not a valid string");
			e.name = "id";
			throw e;
		}	
		if(!(typeof bc_config["bgcolor"] == 'string')) {
			e = new Error("Not present or not a valid number");
			e.name = "bgcolor";
			throw e;
		}	
		if(!(typeof bc_config["width"] == 'number')) {
			e = new Error("Not present or not a valid number");
			e.name = "width";
			throw e;
		}		
		if(!(typeof bc_config["height"] == 'number')) {
			e = new Error("Not present or not a valid number");
			e.name = "height";
			throw e;
		}		
		if(!(typeof bc_config["playerId"] == 'number')) {
			e = new Error("Not present or not a valid number");
			e.name = "playerId";
			throw e;
		}		
	}

/*	Static Properties
 */
	

/*	Methods
 */ 	
 	/* create
 	 * 
 	 * Creates a player based on the initial settings
 	 *
	 */
	BCPlayer.prototype.create = function ()
	{				
		//if(window.console != undefined) console.log("BabyChannel.create")
			
		var pHtml = "\n\n<!-- Start Brightcove Player -->";
		pHtml += "\n<object id=\"myExperience\" class=\"BrightcoveExperience\">";
		pHtml += "\n<param name=\"bgcolor\" value=\"" + this.bc_params["bgcolor"] + "\" />";
		pHtml += "\n<param name=\"width\" value=\"" + this.bc_params["width"] + "\" />";
		pHtml += "\n<param name=\"height\" value=\"" + this.bc_params["height"] + "\" />";
		pHtml += "\n<param name=\"playerID\" value=\"" + this.bc_params["playerId"] + "\" />";
	
		// Start Assigning Programming
		if(this.bc_params["publisherID"] != null) { 
			pHtml += "\n<param name=\"publisherID\" value=\"" + this.bc_params["publisherID"] + "\" />"; 
		} 
		if(this.bc_params["@videoPlayer"] != null) {
			pHtml += "\n<param name=\"@videoPlayer\" value=\"" + this.bc_params["@videoPlayer"] + "\" />";
		} else if(this.bc_params["@playlistTabs"] != null) {
			pHtml += "\n<param name=\"@playlistTabs\" value=\"" + this.bc_params["@playlistTabs"] + "\" />";
			if(this.bc_params["@playlistTabs.featured"] != null) { pHtml += "\n<param name=\"@playlistTabs.featured\" value=\"" + this.bc_params["@playlistTabs.featured"] + "\" />"; }
			if(this.bc_params["@videoList.featured"] != null) { pHtml += "\n<param name=\"@videoList.featured\" value=\"" + this.bc_params["@videoList.featured"] + "\" />"; }
		}
		// End Assigning Programming
	
		pHtml += "\n<param name=\"isVid\" value=\"true\" />";
		pHtml += "\n<param name=\"isUI\" value=\"true\" />";
		pHtml += "\n</object>";
		pHtml += "\n<!-- End Brightcove Player -->\n\n";
		
		document.getElementById(this.divId).innerHTML = pHtml;
	
		brightcove.createExperiences('0', this.bc_params["id"]);
		
		this.created = true;
	}


