
/*** FLASH TO JAVASCRIPT ***/

	page["flash_loaded"]=[];
	page["flash_created"]=[];

	function flashToJs(id,type,value)
		{

			// => the flash file has loaded
				page["flash_loaded"][id]=true;

			// => on a mac "FSCommand: " is sent at the beginning of each argument, so get rid of it
				var type=type.replace(/^FSCommand:\s*/i,"");
				var value=value.replace(/^FSCommand:\s*/i,"");

			// => evaluate the function for this movie
				eval("if(typeof flashToJs"+id+"!='undefined'){flashToJs"+id+"(\""+type+"\",\""+value+"\");}");

		}


/*** MAKE FLASH PLAYER ***/

	function flashMake(id,source,width,height,return_str,create_regardless,javascript_callback_used)
		{

			// => don't create flash if the file has already been loaded
				if(!create_regardless&&page["flash_created"][id])
					{
						return false;
					}

				page["flash_created"][id]=true;

			// => flash to javascript callback
				if(page["browser_ie"]) // => ie
					{

						if(page["loaded"])
							{
								if(source.indexOf("?")==-1)
									{
										source+="?callback=1";
									}
								else
									{
										source+="&callback=1";
									}
							}
						else
							{
								document.write("<scr"+"ipt language=vbscript>on error resume next\nSub flashMovie"+id+"_FSCommand(ByVal A0,ByVal A1)\ncall flashToJs(\""+id+"\",A0,A1)\nend sub</scr"+"ipt>");
							}

						if(source.indexOf("?")==-1)
							{
								source+="?id="+id;
							}
						else
							{
								source+="&id="+id;
							}

					}
				else // => mozilla and other browsers
					{

						eval("flashMovie"+id+"_DoFSCommand=function(A0,A1){flashToJs(\""+id+"\",A0,A1)}");

					}

			// => initialise the flash file if needed
				if(javascript_callback_used)
					{
						pageLoadedAdd("flashLoaded('"+id+"');");
					}

			// => create movie
				var a="<object id='flashMovie"+id+"' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+width+"' height='"+height+"'>";
				a+="<param name='movie' value='"+source+"'>";
				a+="<param name='quality' value='high'>";
				a+="<param name='swLiveConnect' value='true'>";
				a+="<param name='allowScriptAccess' value='always'>";
				a+="<param name='wmode' value='transparent'>";
				a+="<embed name='flashMovie"+id+"' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' src='"+source+"' quality='high' swLiveConnect='true' allowScriptAccess='always' wmode='transparent' width='"+width+"' height='"+height+"'></embed>";
				a+="</object>";

				if(return_str||!page["loaded"])
					{
						return a;
					}
				else
					{
						var div_obj=document.createElement("div");

						div_obj.innerHTML=a;

						document.getElementsByTagName("body")[0].appendChild(div_obj);
					}

		}

	function flashMakeMovie(id,skin_src,movie_src,width,height)
		{

			return flashMake(id,"/flash/movie/20090323v14.swf?width="+width+"&height="+height+(skin_src?"&skin="+skin_src:"")+"&movie="+movie_src,width,height,true,false,true);

		}

	function flashLoaded(id)
		{

			if(!page["flash_loaded"][id])
				{
					flashToFlash(id,"Loaded");

					setTimeout("flashLoaded('"+id+"');",1000);
				}

		}


/*** UPLOAD FILE ***/

	// maxsize => the maximum file size allowed (mb)
	function flashUpload(id,maxsize,width,height)
		{

			// => string for the maximum file size
				page["flash_upload_limit"]=maxsize>=1?maxsize+" MB":(maxsize*1000)+ " KB";

			// => the flash file has loaded - this is needed since the "loading" call to Flash that uses "SetVariable" causes focus to be lost on any field that currently has focus
				page["flash_loaded"][id]=true;

			// => create the movie for file upload
				return flashMake(id,"/flash/upload/20090414v1.swf?maxsize="+(maxsize*1048576),width,height,true,true,true);

		}

	// => upload a file to the server
		// url => the url to upload the file to
	function flashUploadFile(id,url,file_index)
		{

			// => upload file to the server
				flashToFlash(id,"Upload",url,file_index);

		}



/*** JAVASCRIPT TO FLASH ***/

	// id => id
	// function => function to run in flash
					 // 0 => DEFAULT "CALLflash" function will be used
	// all other arguments => arguments to pass to the function to run => OPTIONAL
	function flashToFlash(id,function_do)
		{

			// => get the current value of "flashTrigger" from flash
				//D=flashMethod(id,"GetVariable","flashTrigger")

			// => set the flash function to use
				//flashMethod(id,"SetVariable","FUNCTIONname",function_do?function_do:"callFlash")

			// => set flash variables
				var b=2;

				while(true)
					{
						if(typeof arguments[b]!="undefined")
							{
								flashMethod(id,"SetVariable","A"+(b-2),arguments[b]);

								b++;
							}
						else
							{
								break;
							}
					}

			// => change the "triggerFunctionName" variable in flash which is being watched for a change in value
				flashMethod(id,"SetVariable","trigger"+function_do,numberRandom());

		}



/*** CALL A FLASH METHOD ***/

	// id
	// method => method name
		// => eg, "GetVariable", "SetVariable"
		// => for a list of methods see: http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html
	// variable => variable name => OPTIONAL
	// value => value => OPTIONAL
	function flashMethod(id,method,variable,value)
		{

			// => the string to run
				var eval_str="window.document['flashMovie"+id+"']."+method+"("+(typeof variable!="undefined"?"'"+variable+"'"+(typeof value!="undefined"?",'"+value+"'":""):"")+");";

			// => continue depending on whether the flash file has loaded
				// => allow the "triggerLoaded" variable value to by-pass this since this is needed to initialise the flash window
				if(window.document["flashMovie"+id]&&(page["flash_loaded"][id]||variable=="triggerLoaded"))
					{
						return eval(eval_str);
					}
				else
					{
						if(typeof page["flash_wait_"+id+"_interval"]=="undefined")
							{
								page["flash_wait_"+id+"_items"]=[eval_str];
								
								page["flash_wait_"+id+"_interval"]=setInterval("flashWait('"+id+"');",500);
							}
						else
							{
								page["flash_wait_"+id+"_items"].push(eval_str);
							}
					}

		}



/*** WAIT FOR FLASH FILE TO LOAD ***/

	function flashWait(id)
		{

			// => if the flash file has loaded
				if(window.document["flashMovie"+id]&&page["flash_loaded"][id])
					{

						// => stop the interval
							clearInterval(page["flash_wait_"+id+"_interval"]);
							page["flash_wait_"+id+"_interval"]=null;

						// => perform all scripts that have been stored to be run once this flash file has loaded
							for(var b in page["flash_wait_"+id+"_items"])
								{
									eval(page["flash_wait_"+id+"_items"][b]);
								}

							page["flash_wait_"+id+"_items"]=undefined;

					}

		}





/*** DETECT FLASH PLUGIN ***/

	function flashVersion()
		{
			return 8;
		}

	function flashDetect()
		{

			var is_flash=false;

			if(navigator.plugins&&navigator.plugins.length) // => mozilla
				{

					if(navigator.plugins["Shockwave Flash"])
						{
							is_flash=navigator.plugins["Shockwave Flash"].description.split(" ")[2].split(".")[0]>=flashVersion();
						}

				}
			else if(window.ActiveXObject) // => ie
				{

					try
						{
							is_flash=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+flashVersion())?true:false;
						}
					catch(e)
						{

						}

				}

			return is_flash;

		}

	function flashInstallUrl()
		{

			return "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";

		}
