
// A simple map implementation
var Map = function() {
	var map = {};
	var public = {};
	public.put = function( key, value) {
		map[ key ] = value;
	};
	public.get = function( key ) {
		return map[ key ];
	};
	public.clear = function() { // <-- TODO: We may need to call this when the AJAX stuff happens probably.
		map = {};
	};
	return public;
};

// ContentPalyer 
var ContentPlayer = function() {
	var public = {};
	
	/**********************************
	 *   Some Convenience Variables
	 **********************************/
	public.GetElementRefs = function() {
		var refs = {};
		refs.flashElem = "contentMainFlashAlternative";
		refs.htmlTextContainer = jQuery("#"+refs.flashElem+" .htmlTextContainer");
		refs.htmlTextContainerPos = refs.htmlTextContainer.position();
		return refs;
	};
	
	/********************************
	 *   Embed a Content Player
	 ********************************/
	var currentMainCount = 0; // We need to use unique IDs in IE.
	public.EmbedPlayer = function( contentConfigKey, width, height, elementID ) { // elementID should not be used. It is not implemented anymore.
		if( BandwidthSetting.getValue() >= BandwidthSetting.NORMAL ) { // Note: Not best theoretical place to check but quick and works.
			// New One
			currentMainCount++;
			
			var refs = ContentPlayer.GetElementRefs();
			width = (width != undefined)? width : "711";
			height = (height != undefined)? height : "364";
			elementID = (elementID != undefined)? elementID : refs.flashElem;
			
			public.setMainFlashID( elementID + currentMainCount );
			
			var flashvars = { contentConfigKey: contentConfigKey };
			var params = { menu: "false", wmode: "transparent" };
			var attributes = { id: public.getMainFlashID() };
			
			jQuery("#"+elementID).wrap("<div style=\"position: relative; width:"+width+"px; height:"+height+"px;\"></div>"); // To hold the space.
			
			swfobject.embedSWF("assets/flash/content-player.swf", elementID, width, height, "9.0.0","assets/scripts/expressInstall.swf", flashvars, params, attributes);
		}
	};
	var mainFlashID;
	public.setMainFlashID = function( id ) {
		mainFlashID = id;
	};
	public.getMainFlashID = function() {
		return mainFlashID;
	};
	
	
	/***********************************
	 *   Content and Layer Configs
	 ***********************************/
	var contentConfigs = new Map();
	
	// Content Config
	public.GetContentConfig = function( key ) {
		return contentConfigs.get( key );
	};
	
	// New Content Video Config
	public.NewContentVideoConfig = function( key, options, layers ) {
		var defaultOptions = {
			src:	undefined,	// Note: Remember this is relative to the swf location.
			x:		0,
			y:		0,
			width:	712,
			height:	368,
			volume:	1,
			loop:	false
		};
		var value = jQuery.extend( true, {}, defaultOptions, options);

		value.impl = "com.plaudit.contentPlayer.content.iVideoConfig";
		value.layers = layers;
		
		contentConfigs.put( key, value );
		return value;
	};
	
	// Layer HTML Class
	public.LayerHTMLConfig = function( options ) {
		var refs = ContentPlayer.GetElementRefs();
		
		this.htmlText	= refs.htmlTextContainer.innerXHTML();			// Note: Remember this is relative to the swf location.
		this.cssURL		= "assets/styles/content-player.css";		// Note: This is relative to the html's base location.
		this.x			= (refs.htmlTextContainerPos == undefined)? 0 : refs.htmlTextContainerPos.left;
		this.y			= (refs.htmlTextContainerPos == undefined)? 0 : refs.htmlTextContainerPos.top;
		this.width		= (refs.htmlTextContainerPos == undefined)? 0 : refs.htmlTextContainer.width();
		this.show		= {
			when: 3,	// Seconds or "start" or "end" or "loop"
			duration: 1.5,
			curveType: "linear"
		};			
		this.hide		= {
			when: null,
			duration: 0.5,
			curveType: "linear"
		};	
		this.bitmapFilter = {
			type: "GlowFilter",
			color: "0x000000",
			alpha: 0.9,
			blurX: 10,
			blurY: 10,
			strength: 4
		};
		jQuery.extend( true, this, options).impl = "com.plaudit.contentPlayer.layer.iHTMLConfig";
	};
	
	// Layer Standard Options Class
	public.LayerStandardOptionsConfig = function( options ) {
		this.innerShadow		= true;
		this.click		= (!Paging.HasNext())? null : {
			funcName: "Paging.Next",
			arg: null
		};
		this.mouseFollower		= (this.click != null)? "anotherView" : null;
		jQuery.extend( true, this, options).impl = "com.plaudit.contentPlayer.layer.iStandardOptionsConfig";
	};
	
	// Layer Loader Config Class
	public.LayerLoaderConfig = function( options ) {
		this.url		= "";
		this.x			= 0;
		this.y			= 0;
		this.config		= null;				// Passed to the content.
		this.run		= [
		      { when: 3, funcName: "show" } //"funcName" will be ran on the loaded content at specified "when" (same as other when above). 
    	];
		jQuery.extend( true, this, options).impl = "com.plaudit.contentPlayer.layer.iLoaderConfig";
	};

	
	return public;
}();


