/*
 * -----------------------------------------------------------------
 * 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: paul $
 * $Date: 2006/08/01 20:57:47 $
 * $Revision: 1.4 $
 *
 */

var conceptretail = (conceptretail == null) ? new Object() : conceptretail;

/**
 * Manages a collection of recently viewed image (products) for use with the Scroller
 * NOTE: This class require swfobject.js
 * @param swfUrl: String - The URL to the Scroller SWF file
 * @param swfId: String - A unique per page ID that identifies the Scroller
 * @param width: Number - The width of the Scroller
 * @param height: Nunmber - The height of the Scroller
 * @param userInterfaceXmlUrl: String - The URL to the user interface XML file which describes the Scroller
 * @param scrollerId: String - The id of the Scroller as specified in the user interface XML file
 * @param imagesXml: String - XML string describing the image data the scroller will consume
 * @param eventHandler: String - An optional JavaScript method name that will execute when the image in the Scroller changes
 */
conceptretail.Scroller = function(swfUrl, swfId, width, height, userInterfaceXmlUrl, scrollerId, imagesXml, eventHandler)
{
	this.swfUrl = swfUrl;
	this.swfId = swfId;
	this.width = width;
	this.height = height;
	this.userInterfaceXmlUrl = userInterfaceXmlUrl;
	this.scrollerId = scrollerId;
	this.imagesXml = imagesXml;
	this.eventHandler = eventHandler;
	
	this.createFSCommandProxy();
}

	conceptretail.Scroller.prototype.swfUrl = null;
	conceptretail.Scroller.prototype.swfId = null;
	conceptretail.Scroller.prototype.width = null;
	conceptretail.Scroller.prototype.height = null;
	conceptretail.Scroller.prototype.backgroundColor = "#ffffff";
	conceptretail.Scroller.prototype.userInterfaceXmlUrl = null;
	conceptretail.Scroller.prototype.scrollerId = null;
	conceptretail.Scroller.prototype.imagesXml = null;
	conceptretail.Scroller.prototype.eventHandler = null;

	/**
	 * Writes the Scroller to the div specified
	 * @param container: Div
	 */
	conceptretail.Scroller.prototype.write = function(container)
	{
		var swf = new SWFObject(this.swfUrl, this.swfId, this.width, this.height, "7", this.backgroundColor);
		swf.addParam("wmode", "opaque");
		swf.addParam("swLiveConnect", "true");
		swf.addVariable("userInterfaceXmlUrl", this.userInterfaceXmlUrl);
		swf.addVariable("scrollerId", this.scrollerId);
		swf.addVariable("imagesXml", this.imagesXml);
		if(this.eventHandler != null) swf.addVariable("eventHandler", this.eventHandler);
		swf.write(container);
	}
	
	//
	
	/**
	 * Creates the functions that will handle fscommand calls from the Scroller
	 * @private
	 */
	conceptretail.Scroller.prototype.createFSCommandProxy = function()
	{
		var scriptToWrite = '';
		scriptToWrite += '<script language="VBScript">';
		scriptToWrite += 'Sub ' + this.swfId + '_FSCommand(ByVal command, ByVal args)';
		scriptToWrite += 'call ' + this.swfId + '_DoFSCommand(command, args)';
		scriptToWrite += 'end sub';
		scriptToWrite += '</script>';
		document.writeln(scriptToWrite);

		window[this.swfId + "_DoFSCommand"] = function(command, args)
		{
			var func = window[command];
			if(func != null) func.apply(window, args.split(","));
		}
	}
	
//
	
