/// <reference path="jquery-vsdoc.js" /> 

jQuery(function()
{
	jQuery("#advanced").hide();
	
	jQuery("input[type=checkbox][name=showAdvanced]").click(function()
	{
		var action = this.checked ? "show" : "hide";
		jQuery("#advanced").animate({height:action,opacity:action});
	});
	
	jQuery("#chooseColor").click(function()
	{
		colorDialog.show();
		return false;
	});
	
	jQuery("input[name^=movie],select[name^=movie]").change(function()
	{
		var movieSource = jQuery.trim(jQuery("input[name=movieSource]").val());
		if (0 === movieSource.length)
		{
			jQuery("textarea[name=movieOutput]").val("");
		}
		else
		{
			if (-1 == movieSource.indexOf('.'))
			{
				movieSource += ".swf";
			}
			
			var sb = new Sys.StringBuilder();
			
			sb.writeAttribute = function(name, value)
			{
				if ("string" !== typeof(name) || 0 === name.length) { return; }
				if ("string" !== typeof(value) || 0 === value.length) { return ;}
				
				this.append(" ");
				this.append(name);
				this.append("=\"");
				this.append(value.replace(/\"/g, "&quot;"));
				this.append("\"");
			};
			
			sb.writeParam = function(name, value)
			{
				if ("string" !== typeof(name) || 0 === name.length) { return; }
				if ("string" !== typeof(value) || 0 === value.length) { return ;}
				
				this.append("\t<param");
				this.writeAttribute("name", name);
				this.writeAttribute("value", value);
				this.append(" />\n");
			};
			
			sb.append("<object");
			sb.writeAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");
			sb.writeAttribute("codebase", "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0");
			sb.writeAttribute("type", "application/x-shockwave-flash");
			sb.writeAttribute("id", jQuery("input[name=movieID]").val());
			sb.writeAttribute("width", jQuery("input[name=movieWidth]").val());
			sb.writeAttribute("height", jQuery("input[name=movieHeight]").val());
			sb.append(">\n");
			
			sb.writeParam("movie", movieSource);
			sb.writeParam("quality", jQuery("select[name=movieQuality]").val());
			sb.writeParam("scale", jQuery("select[name=movieScale]").val());
			sb.writeParam("wmode", jQuery("select[name=movieWindowMode]").val());
			sb.writeParam("bgcolor", jQuery("input[name=movieBackgroundColor]").val());
			sb.writeParam("menu", 1 === jQuery("input[name=movieContextMenu]:checked").length ? "true" : "false");
			sb.writeParam("play", 1 === jQuery("input[name=movieAutoStart]:checked").length ? "true" : "false");
			sb.writeParam("loop", 1 === jQuery("input[name=movieLoop]:checked").length ? "true" : "false");
			
			var anchor = jQuery.makeArray(jQuery("input[name=movieAnchor]:checked").map(function(){return $(this).val();})).join("");
			sb.writeParam("salign", anchor);
			
			sb.append("\n\t<embed");
			sb.writeAttribute("pluginspage", "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
			sb.writeAttribute("type", "application/x-shockwave-flash");
			sb.writeAttribute("src", movieSource);
			sb.writeAttribute("width", jQuery("input[name=movieWidth]").val());
			sb.writeAttribute("height", jQuery("input[name=movieHeight]").val());
			sb.writeAttribute("quality", jQuery("select[name=movieQuality]").val());
			sb.writeAttribute("scale", jQuery("select[name=movieScale]").val());
			sb.writeAttribute("wmode", jQuery("select[name=movieWindowMode]").val());
			sb.writeAttribute("bgcolor", jQuery("input[name=movieBackgroundColor]").val());
			sb.writeAttribute("menu", 1 === jQuery("input[name=movieContextMenu]:checked").length ? "true" : "false");
			sb.writeAttribute("play", 1 === jQuery("input[name=movieAutoStart]:checked").length ? "true" : "false");
			sb.writeAttribute("loop", 1 === jQuery("input[name=movieLoop]:checked").length ? "true" : "false");
			sb.writeAttribute("swliveconnect", 1 === jQuery("input[name=movieLiveConnect]:checked").length ? "true" : "false");
			sb.writeAttribute("salign", anchor);
			sb.append("></embed>\n");
			sb.append("</object>");
			
			jQuery("textarea[name=movieOutput]").val(sb.toString());
		}
	});
});
