/*
 * -----------------------------------------------------------------
 * Copyright (c) Fluid, Inc. All Right Reserved.
 * This software is the proprietary information of Fluid, Inc.
 * Use is subject to strict licensing terms.
 * -----------------------------------------------------------------
 *
 * CVS Information:
 * $Author: fluiddev $
 * $Date: 2007/08/15 22:20:52 $
 * $Revision: 1.1 $
 *
 */

var conceptretail = (conceptretail == null) ? new Object() : conceptretail;

	/**
	 * Sort function to perform case insensitive sorts on strings
	 * @private
	 */
	conceptretail.caseInsensitiveSort = function(item1, item2)
	{
		return ((item1.toLowerCase() < item2.toLowerCase()) ? -1 : 1);
	}

/**
 * Static ConfigurableImageRenderer Object - This object provides an API to the
 * Configurable Image Renderering Engine
 */
conceptretail.ConfigurableImageRenderer = new Object();
	
	conceptretail.ConfigurableImageRenderer.TYPE_SWF_URL = "swfUrl";
	conceptretail.ConfigurableImageRenderer.TYPE_CONFIGURATION = "configuration";
	conceptretail.ConfigurableImageRenderer.TYPE_LAYER_CONFIGURATION = "layerConfiguration";
	
	/**
	 * Creates and returns a variable identifier that targets a specific renderer and operation in the swf.
	 * @private
	 * @param type - The type of variable. TYPE_SWF_URL, TYPE_CONFIGURATION, or TYPE_LAYER_CONFIGURATION
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 * @return String - A variable identifier used to control a specific renderer in the swf.
	 */
	conceptretail.ConfigurableImageRenderer.getVariableIdentifier = function(type, categoryIds)
	{
		var id = "conceptretail_ConfigurableImageRendererJavaScriptProxy_" + type;
		if(categoryIds != null && categoryIds.length > 0)
		{
			categoryIds.sort(conceptretail.caseInsensitiveSort);
			id += "_" + categoryIds.join("_");
		}
		return id;
	}
	 
	
	/**
	 * Loads a new Configurable Image SWF into the renderer
	 * @param id - the ID of the renderer swf
	 * @param url - the url of the Configurable Image SWF to load
	 */
	conceptretail.ConfigurableImageRenderer.setSwfUrl = function(id, url, categoryIds)
	{
		var type = conceptretail.ConfigurableImageRenderer.TYPE_SWF_URL;
		var variableId = conceptretail.ConfigurableImageRenderer.getVariableIdentifier(type, categoryIds);
		window.document[id].SetVariable(variableId, url);
	};
	
	/**
	 * Assigns a new configuration
	 * @param id - the ID of the swf
	 * @param configurationString - A string encoding a configuration.
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 * Below is an example.
	 * 
	 * layer1:{color:0xddceb7},layer2:{color:0xcccccc,luminance:145}
	 * 
	 * Note that while the grammar supports the idea of nested objects and arrays the
	 * parser does not currently handle this.
	 */
	conceptretail.ConfigurableImageRenderer.setConfiguration = function(id, configuration, categoryIds)
	{
		var type = conceptretail.ConfigurableImageRenderer.TYPE_CONFIGURATION;
		var variableId = conceptretail.ConfigurableImageRenderer.getVariableIdentifier(type, categoryIds);
		window.document[id].SetVariable(variableId, configuration);
	};
	
	/**
	 * Sets a single layers configuration
	 * @param id - the ID of the swf
	 * @param configuration - A string that encodes a single layers configuration
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 */
	conceptretail.ConfigurableImageRenderer.setLayerConfiguration = function(id, configuration, categoryIds)
	{
		var type = conceptretail.ConfigurableImageRenderer.TYPE_LAYER_CONFIGURATION;
		var variableId = conceptretail.ConfigurableImageRenderer.getVariableIdentifier(type, categoryIds);
		window.document[id].SetVariable(variableId, configuration);
	};
	
	/**
	 * Sets a single layers color
	 * @param id - the ID of the swf
	 * @param layer - the name of the layer to tint
	 * @param color - the color to apply to the layer
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 */
	conceptretail.ConfigurableImageRenderer.setLayerColor = function(id, layer, color, categoryIds)
	{
		var configuration = layer + ":{color:" + color + "}";
		conceptretail.ConfigurableImageRenderer.setLayerConfiguration(id, configuration, categoryIds);
	};
	
	/**
	 * Sets a single layers luminance
	 * @param id - the ID of the swf
	 * @param layer - the name of the layer to apply the luminance to
	 * @param luminance - the amount of luminance to apply
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 */
	conceptretail.ConfigurableImageRenderer.setLayerLuminance = function(id, layer, luminance, categoryIds)
	{
		var configuration = layer + ":{luminance:" + luminance + "}";
		conceptretail.ConfigurableImageRenderer.setLayerConfiguration(id, configuration, categoryIds);
	};
	
	/**
	 * Controls a single layers visibility
	 * @param id - the ID of the swf
	 * @param layer - the name of the layer to tint
	 * @param visible - true or false
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 */
	conceptretail.ConfigurableImageRenderer.setLayerVisibility = function(id, layer, visible, categoryIds)
	{
		var configuration = layer + ":{visible:" + ((visible) ? "true" : "false") + "}";
		conceptretail.ConfigurableImageRenderer.setLayerConfiguration(id, configuration, categoryIds);
	};
	
	/**
	 * Sets a single layers depth
	 * @param id - the ID of the swf
	 * @param layer - the name of the layer to tint
	 * @param depth - uint
	 * @param categoryIds - An Array of categoryIds - Used by Display to target specific images. This argument is optional.
	 */
	conceptretail.ConfigurableImageRenderer.setLayerDepth = function(id, layer, depth, categoryIds)
	{
		var configuration = layer + ":{depth:" + depth + "}";
		conceptretail.ConfigurableImageRenderer.setLayerConfiguration(id, configuration, categoryIds);
	};
	
//


