//	tools to assist with the viewpoint scenes

//	these scripts are for communication INTO the Viewpoint DOM only

//	REVISED 21 Jan 2005

//	note the VET scene is embedded with the 'scene' variable

//	the set_Flash_Vars function was provided by Mustard Lab



var ua        = navigator.userAgent.toLowerCase(); 

var is_pc_ie  = ((ua.indexOf('msie') != -1 ) && ( ua.indexOf('win') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ));

var is_mac_ie  = ((ua.indexOf('msie') != -1 ) && ( ua.indexOf('mac') != -1 ) && ( ua.indexOf('opera') == -1 ) && ( ua.indexOf('webtv') == -1 ));





function r3d_get_camera()

{

	var my_rot_str = scene.GetProperty('MTSCamera','look','mts_pnt3d');

	var my_rot_array =  my_rot_str.split(" ");

	var my_loc_str = scene.GetProperty('MTSCamera','loc_','mts_pnt3d');

	var my_loc_array =  my_loc_str.split(" ");

	

	var my_heading_radians = my_rot_array[0];

	var my_heading_degrees = (360-(180 * (my_heading_radians/3.1415)))%360;

	var my_vars_str = "cam_rot="+my_heading_degrees+"&cam_x="+my_loc_array[0]+"&cam_y="+my_loc_array[2];

	set_Flash_Vars("myFlash",my_vars_str);

}



function r3d_reset_view()

{

	var my_parameter_str = "0 0 1.8326";

	r3d_set_camera(my_parameter_str);

	r3d_get_camera();

}



function r3d_trigger_anim(my_anim)

{

	scene.SetProperty('MTSTimeElem.'+my_anim,'trgr','1');

}



function r3d_load_me(my_file,my_button_name)

{

	if(document.getElementById){

		my_radio = document.getElementById(my_button_name);

	}else{

		my_radio = eval("document."+my_button_name);

	}

	my_radio.checked=false;



	var myMTX = "materials/" + my_file + ".mtx";

	scene.LoadMTX(myMTX);

}



function r3d_test()

{

	set_Flash_Vars("myFlash","myVar=OK");

}



function set_Flash_Vars(movieid, flashquery){

	var i,values;

	if(is_pc_ie){

		var chunk = flashquery.split("&");

		for(i in chunk){

			values = chunk[i].split("=");

			document[movieid].SetVariable(values[0],values[1]);

		}

	}else{

		var divcontainer = "flash_setvariables_"+movieid;

		if(!document.getElementById(divcontainer)){

			var divholder = document.createElement("div");

			divholder.id = divcontainer;

			document.body.appendChild(divholder);

		}

		document.getElementById(divcontainer).innerHTML = "";

		var divinfo = "<embed src='../../../../fall/3D/pulte/gateway.swf' FlashVars='lc="+movieid+"&fq="+escape(flashquery)+"' width='0' height='0' type='application/x-shockwave-flash'></embed>";

		document.getElementById(divcontainer).innerHTML = divinfo;

	}

}

function r3d_set_camera(my_parameter_str)

{

	var my_separator = " ";

	var my_parameter_array = my_parameter_str.split(my_separator);

	//	x y z coordinates (y-up)

	var my_x = my_parameter_array[0];

	var my_y = -1.5;

	var my_z = my_parameter_array[1];

	var my_loc_str = my_x + " " + my_y + " " + my_z

	// heading pitch bank = x y z rotation

	var my_heading = 0-my_parameter_array[2];

	var my_pitch = 0;

	var my_bank = 0;

	var my_rot_str = my_heading + " " + my_pitch + " " + my_bank;

	// different methods for different browsers?

	if (is_pc_ie)

	{

		scene.SetProperty('MTSCamera','look',my_rot_str,'mts_pnt3d');

		scene.SetProperty('MTSCamera','loc_',my_loc_str,'mts_pnt3d');

		var my_rot = scene.GetProperty('MTSCamera','rot_','mts_pnt3d');

	} else if (is_mac_ie) { 

		scene.SetProperty('MTSCamera','look',my_rot_str,'mts_pnt3d');

		scene.SetProperty('MTSCamera','loc_',my_loc_str,'mts_pnt3d');

		var my_rot = scene.GetProperty('MTSCamera','rot_','mts_pnt3d');

	} else {

		scene.SetProperty('MTSCamera','look',my_rot_str,'mts_pnt3d');

		scene.SetProperty('MTSCamera','loc_',my_loc_str,'mts_pnt3d');

		var my_rot = scene.GetProperty('MTSCamera','rot_','mts_pnt3d');

	}

}