

	// => create video/slides
	function videoMake(video_files,video_dimensions,autoplay,slide_dimensions_view,slide_dimensions_popup,slide_dir,slide_indexes,slide_versions,slide_times,slide_titles,slide_position,slide_markers,video_end_html,slide_html)
		{

			// => values
				VIDEO=[];

				VIDEO["directory"]=[];
				VIDEO["directory"]["slides"]=slide_dir;
				VIDEO["directory"]["images"]="/media/itv/new_2009/player/";

				VIDEO["video"]=[];
				VIDEO["video"]["dimensions"]=[];
				VIDEO["video"]["dimensions"]["width"]=video_dimensions["width"];
				VIDEO["video"]["dimensions"]["height"]=video_dimensions["height"];

				VIDEO["toolbar_ignore"]=1; // => ignore changes to the slide for a short period
				VIDEO["timeline_bar_width"]=slide_times?300:VIDEO["video"]["dimensions"]["width"]-300; // => width of the timeline depends on whether slides are used
				VIDEO["slider_active"]=""; // => no slider is active to begin with

				VIDEO["video"]["playing"]=autoplay?true:false; // => the video is not playing to begin with

				VIDEO["video"]["duration"]=0;

				VIDEO["video"]["position"]=[];
				VIDEO["video"]["position"]["current"]=0;
				VIDEO["video"]["position"]["furthest"]=0;
				VIDEO["video"]["position"]["recorded"]=0;

				VIDEO["video"]["percent"]=0;

				VIDEO["video"]["volume"]=[];
				VIDEO["video"]["volume"]["level"]=cookieGet("video_volume");
				VIDEO["video"]["volume"]["level_restore"]=VIDEO["video"]["volume"]["level"];

				if(!VIDEO["video"]["volume"]["level"])
					{
						VIDEO["video"]["volume"]["level"]=100;
					}

				if(VIDEO["video"]["volume"]["level_restore"]==0)
					{
						VIDEO["video"]["volume"]["level_restore"]=100;
					}


				VIDEO["video"]["random_id"]=randomLetters(8); // => random id for the user viewing this video

				VIDEO["video"]["files"]=video_files; // => an array of video files

				VIDEO["video"]["video_end_html"]=video_end_html; // => an array of video files

				VIDEO["video"]["current_index"]=0; // => the video file to load to begin with
		
				VIDEO["video"]["video_index"]=video_files.length-1; // => the index of the "video" video
		
				if(slide_times)
					{
						VIDEO["slides"]=[];

						VIDEO["slides"]["dimensions"]=[];

						VIDEO["slides"]["dimensions"]["view"]=[];
						VIDEO["slides"]["dimensions"]["view"]["width"]=slide_dimensions_view["width"];
						VIDEO["slides"]["dimensions"]["view"]["height"]=slide_dimensions_view["height"];

						VIDEO["slides"]["dimensions"]["popup"]=[];
						VIDEO["slides"]["dimensions"]["popup"]["width"]=slide_dimensions_popup["width"];
						VIDEO["slides"]["dimensions"]["popup"]["height"]=slide_dimensions_popup["height"];

						VIDEO["slides"]["current"]=0; // => begin at the first slide
						VIDEO["slides"]["indexes"]=slide_indexes;
						VIDEO["slides"]["versions"]=slide_versions;
						VIDEO["slides"]["titles"]=slide_titles;
						VIDEO["slides"]["times"]=slide_times;
						VIDEO["slides"]["markers"]=slide_markers;
						VIDEO["slides"]["html"]=slide_html;
					}



			// => create the presentation area
				styleAddPNG(".video_loading_98x125",VIDEO["directory"]["images"]+"video_loading_98x125.png");

				var a="<table cellpadding='0' cellspacing='0'>";

				a+="<tr>";

				a+="<td style='text-align:left;'>";

					a+="<table cellpadding='0' cellspacing='0'>";
					a+="<tr>";

						// => slides (left position)
							if(VIDEO["slides"]&&slide_position==1)
								{
									a+=videoSlideMake();
									a+="<td style='padding-left:5px;'></td>";
								}

						// => video
							a+="<td>";

							if(flashDetect())
								{
									styleAddPNG(".play_61x85",VIDEO["directory"]["images"]+"play_61x85.png");

									a+="<div style='position:relative;width:"+(VIDEO["video"]["dimensions"]["width"]+1)+"px;height:"+(VIDEO["video"]["dimensions"]["height"]+1)+"px;'>";
										a+=flashMakeMovie("video",0,VIDEO["video"]["files"][VIDEO["video"]["current_index"]],VIDEO["video"]["dimensions"]["width"],VIDEO["video"]["dimensions"]["height"]);
									a+="</div>";
									
									a+="<div id='area_video_loading' style='position:relative;display:none;'>";
										a+="<div style='position:absolute;width:"+VIDEO["video"]["dimensions"]["width"]+"px;height:"+VIDEO["video"]["dimensions"]["height"]+"px;top:-"+(VIDEO["video"]["dimensions"]["height"]+1)+"px;background-color:#7C7C7C;'>";
											a+="<div style='position:relative;width:98px;height:125px;left:"+((VIDEO["video"]["dimensions"]["width"]/2)-(98/2))+"px;top:"+((VIDEO["video"]["dimensions"]["height"]/2)-(125/2))+"px;' class='video_loading_98x125'></div>";
										a+="</div>";
									a+="</div>";
									
									a+="<div style='position:relative;'>";
										a+="<div id='area_video_play' style='display:none;position:absolute;width:"+VIDEO["video"]["dimensions"]["width"]+"px;height:"+VIDEO["video"]["dimensions"]["height"]+"px;top:-"+(VIDEO["video"]["dimensions"]["height"]+1)+"px;'><div style='position:relative;width:61px;height:85px;left:"+((VIDEO["video"]["dimensions"]["width"]/2)-(61/2))+"px;top:"+((VIDEO["video"]["dimensions"]["height"]/2)-(85/2))+"px;' class='play_61x85'></div></div>";
										a+="<a href='javascript:videoPlay(VIDEO[\"video\"][\"playing\"]);'><img src='/media/blank.gif' style='position:absolute;width:"+VIDEO["video"]["dimensions"]["width"]+"px;height:"+VIDEO["video"]["dimensions"]["height"]+"px;top:-"+(VIDEO["video"]["dimensions"]["height"]+1)+"px;' title='Click to Play/Pause'></a>";
									a+="</div>";

									if(VIDEO["video"]["video_end_html"])
										{
											a+="<div style='position:relative;'><div id='area_video_end_html' style='display:none;position:absolute;top:-"+VIDEO["video"]["dimensions"]["height"]+"px;'></div></div>";
										}

								}
							else
								{
									styleAddPNG(".flash_required_233x170",VIDEO["directory"]["images"]+"flash_required_233x170.png");

									a+="<div style='position:relative;width:"+VIDEO["video"]["dimensions"]["width"]+"px;height:"+VIDEO["video"]["dimensions"]["height"]+"px;background-color:#7C7C7C;'>";
										a+="<div style='position:relative;width:233px;height:170px;left:"+((VIDEO["video"]["dimensions"]["width"]/2)-(233/2))+"px;top:"+((VIDEO["video"]["dimensions"]["height"]/2)-(170/2))+"px;' class='flash_required_233x170'></div>";
									a+="</div>";

									a+="<div style='position:relative;'>";
										a+="<a href='"+flashInstallUrl()+"' target='_blank'><img src='/media/blank.gif' style='position:absolute;width:"+VIDEO["video"]["dimensions"]["width"]+"px;height:"+VIDEO["video"]["dimensions"]["height"]+"px;top:-"+(VIDEO["video"]["dimensions"]["height"]+1)+"px;' title='Click to get Flash Player'></a>";
									a+="</div>";
								}

							a+="</td>";

						// => slides (right position)
							if(VIDEO["slides"]&&slide_position==0)
								{
									a+="<td style='padding-left:5px;'></td>";
									a+=videoSlideMake();	
								}

					a+="</tr>";
					a+="</table>";
				
				a+="</td>"

				a+="</tr>";

				a+="<tr>";
				a+="<td>";

				a+="<div style='height:5px;overflow:hidden;'></div>";

				a+="<div style='background-color:#7C7C7C;'>";

				a+="<table cellpadding='2' cellspacing='0' align='center' style='height:37px;'>";
				a+="<tr>";

					// => play/pause
						a+="<td><a href='javascript:videoPlay(VIDEO[\"video\"][\"playing\"]);'><img id='area_btn_play' src='"+VIDEO["directory"]["images"]+(VIDEO["video"]["playing"]?"pause":"play")+".gif' style='width:46px;height:23px;' title='Play/Pause'></a></td>";

					// => stop
						a+="<td><a href='javascript:videoPlay(true);"+(VIDEO["slides"]?"videoSlideLoad(0,true);":"videoChange(0);")+"'><img src='"+VIDEO["directory"]["images"]+"stop.gif' style='width:23px;height:23px;' title='Stop'></a></td>";

					// => previous/next slide if slides exist
						if(VIDEO["slides"])
							{
								a+="<td><a href='javascript:videoSlideLoad(VIDEO[\"slides\"][\"current\"]-1,true);'><img src='"+VIDEO["directory"]["images"]+"slide_prev.gif' style='width:22px;height:23px;' title='Previous slide'></a><a href='javascript:videoSlideLoad(VIDEO[\"slides\"][\"current\"]+1,true);'><img src='"+VIDEO["directory"]["images"]+"slide_next.gif' style='width:21px;height:23px;' title='Next slide'></a></td>";
							}

					// => timer
						a+="<td style='color:#FFFFFF;font-size:12px;padding-left:5px;' class='cursor' onclick='videoPositionPopup(\"open\");' title='Click to jump to a position'>";
						a+="<div style='position:relative;z-index:9999;'>";
						a+="<span id='area_timeline_position_popup' style='display:none;position:absolute;top:-6px;white-space:nowrap;'><input id='area_timeline_position_value' type='text' size='5' onkeyup='if(keyCode==13){videoPositionPopup(\"goto\");}else if(keyCode==27){videoPositionPopup(\"close\");}'><input type='button' value='Go' onclick='videoPositionPopup(\"goto\");'><input type='button' value='Cancel' onclick='videoPositionPopup(\"close\");'></span>";
						a+="</div>";
						a+="<span id='area_timeline_position'>00:00</span>&nbsp;/&nbsp;<span id='area_timeline_duration'>00:00</span>";
						a+="</td>";

					// => timeline
						a+="<td>";
						a+=videoBarMake("timeline",VIDEO["timeline_bar_width"],15,12);

						if(VIDEO["slides"])
							{
								a+="<div id='area_video_slide_markers' style='position:relative;height:5px;font-size:1px;margin-left:11px;margin-right:11px;'>&nbsp;</div>";
							}

						a+="</td>";

					// => volume
						a+="<td><a href='javascript:VIDEOvolume();'><img id='area_btn_volume' src='"+VIDEO["directory"]["images"]+(VIDEO["video"]["volume"]["level"]>0?"volume_on.gif":"volume_off.gif")+"' style='width:23px;height:23px;' title='Volume on/off'></a></td>";

						a+="<td>"+videoBarMake("volume",53,15,12)+"</td>";

					// => enlarge slides
						if(VIDEO["slides"])
							{
								a+="<td><a href='javascript:videoSlidePopup();'><img src='"+VIDEO["directory"]["images"]+"pop_up.gif' style='width:26px;height:24px;' title='Enlarge slides'></a></td>";
							}

				a+="</tr>";
				a+="</table>";
				
				a+="</div>";

				a+="</td>";
				a+="</tr>";

				a+="</table>";

				document.write(a);

				document.onkeyup=videoKeyUp;

		}


	// => on key-up
	function videoKeyUp()
		{

			// => "space" key stops/starts video
			if(keyCode==32)
				{
					// => ignore space-bar if the video duration is not known yet or an overlay is currently showing
					if(VIDEO["video"]["duration"]>0&&page["overlay_layer_current"]<0)
						{
							videoPlay(VIDEO["video"]["playing"]);
						}
				}

		}


	function videoPositionPopup(type)
		{
		
			if(type=="open") // => open
				{
					areaShow("area_timeline_position_popup");
					areaID("area_timeline_position_value").focus();
				}
			else if(type=="goto") // => go to the position entered
				{
					videoChange(videoTimeToSeconds(areaValueGet("area_timeline_position_value")),true);
					setTimeout("areaShow('area_timeline_position_popup',1);",99);
				}
			else if(type=="close") // => close
				{
					setTimeout("areaShow('area_timeline_position_popup',1);",99);
				}
		
		}


	// => convert time in format 12:34 to seconds
	function videoTimeToSeconds(time)
		{

			// => convert time given to seconds
				var seconds=time.replace(/\./,":");
				seconds=seconds.split(":");
								
				if(!seconds[1])
					{
						seconds[1]=0;
					}
								
				seconds[0]*=60;
				seconds[1]*=1;
								
				seconds=seconds[0]+seconds[1];
								
				return seconds;

		}


	// => convert seconds to format 12:34
	function videoTime(seconds)
		{

			var mins="00"+Math.floor(seconds/60);
			var secs="00"+Math.floor(seconds%60);

			return mins.substr(mins.length-2)+":"+secs.substr(secs.length-2);

		}


	// => create slides area
	function videoSlideMake()
		{

			var a="";

			if(VIDEO["slides"])
				{

					a+="<td>";

					a+="<div style='position:absolute;width:"+VIDEO["slides"]["dimensions"]["view"]["width"]+"px;height:"+VIDEO["slides"]["dimensions"]["view"]["height"]+"px;background-color:#7C7C7C;'>";
						a+="<div style='position:relative;width:98px;height:125px;left:"+((VIDEO["slides"]["dimensions"]["view"]["width"]/2)-(98/2))+"px;top:"+((VIDEO["slides"]["dimensions"]["view"]["height"]/2)-(125/2))+"px;' class='video_loading_98x125'></div>";
					a+="</div>";

					a+="<div style='position:relative;width:"+VIDEO["slides"]["dimensions"]["view"]["width"]+"px;height:"+VIDEO["slides"]["dimensions"]["view"]["height"]+"px;'>";
						a+="<a href='javascript:videoSlidePopup();' title='Click to view large slides'><img id='area_video_slide_img' src='"+VIDEO["directory"]["slides"]+"slide_medium_"+VIDEO["slides"]["indexes"][0]+".jpg"+(VIDEO["slides"]["versions"][0]?"?"+VIDEO["slides"]["versions"][0]:"")+"' style='width:"+VIDEO["slides"]["dimensions"]["view"]["width"]+"px;height:"+VIDEO["slides"]["dimensions"]["view"]["height"]+"px;'></a>";
					a+="</div>";
					
					a+="<div style='position:relative;'><div id='area_video_slide_html' style='position:absolute;top:-"+VIDEO["slides"]["dimensions"]["view"]["height"]+"px;'>"+(VIDEO["slides"]["html"][0]?VIDEO["slides"]["html"][0]:"")+"</div></div>";

					a+="</td>";

				}

			return a;

		}


	// => create slide pop-up
	function videoSlidePopup()
		{
		
			// => create the overlay area					
				var a="<div style='background-color:#7C7C7C;padding:3px;'><img id='area_video_slide_img_overlay' src='"+VIDEO["directory"]["slides"]+"slide_large_"+VIDEO["slides"]["indexes"][VIDEO["slides"]["current"]]+".jpg"+(VIDEO["slides"]["versions"][VIDEO["slides"]["current"]]?"?"+VIDEO["slides"]["versions"][VIDEO["slides"]["current"]]:"")+"' style='width:"+VIDEO["slides"]["dimensions"]["popup"]["width"]+"px;height:"+VIDEO["slides"]["dimensions"]["popup"]["height"]+"px;'></div>";
				
				a+="<div style='height:2px;overflow:hidden;'></div>";
				
				a+="<div style='padding:3px;background-color:#7C7C7C;'>";
				
				a+="<div style='width:"+VIDEO["slides"]["dimensions"]["popup"]["width"]+"px;'>";
				
				a+="<table cellpadding='2' cellspacing='0' style='width:100%;'>";
				a+="<tr>";
				
				a+="<td width='49%' align='right'>";
				
				a+="<a href='javascript:videoPlay(VIDEO[\"video\"][\"playing\"]);'><img id='area_btn_play' src='"+VIDEO["directory"]["images"]+"play.gif' style='width:46px;height:23px;' title='Play/Pause'></a>";
				a+="<img src='/media/blank.gif' style='width:5px;height:1px;'>";
				a+="<a href='javascript:videoPlay(true);videoSlideLoad(0,true);'><img src='"+VIDEO["directory"]["images"]+"stop.gif' style='width:23px;height:23px;' title='Stop'></a>";
				
				a+="</td>";

				a+="<td><a href='javascript:videoSlideLoad(VIDEO[\"slides\"][\"current\"]-1,true);'><img src='"+VIDEO["directory"]["images"]+"slide_prev.gif' style='width:22px;height:23px;' title='Previous Slide'></a></td>";
				
				a+="<td id='area_slide_number_big' style='color:#FFFFFF;padding-left:5px;padding-right:5px;'>"+(VIDEO["slides"]["current"]+1)+"</td>";
				
				a+="<td><a href='javascript:videoSlideLoad(VIDEO[\"slides\"][\"current\"]+1,true);'><img src='"+VIDEO["directory"]["images"]+"slide_next.gif' style='width:21px;height:23px;' title='Next Slide'></a></td>";
				
				a+="<td width='49%' align='right'><a href='javascript:overlayMake();'><img src='"+VIDEO["directory"]["images"]+"close.gif' style='width:23px;height:23px;' title='Close'></a></td>";
				
				a+="</tr>";
				a+="</table>";
				
				a+="</div>";
				
				a+="</div>";

				overlayMake(false,a,false,false,true);
		
		}


	// => create scrolling bar
	function videoBarMake(bar_type,bar_width,bar_height,knob_width)
		{

			var a;

			a="<div style='padding-left:"+(knob_width/2+5)+"px;padding-right:"+(knob_width/2+5)+"px;'>";

			a+="<div style='position:relative;'>";

				// => scrolling area
					a+="<div id='area_bar_"+bar_type+"' style='position:relative;width:"+bar_width+"px;height:"+bar_height+"px;background:url("+VIDEO["directory"]["images"]+""+bar_type+".gif) repeat-x;text-align:left;'>";



						// => progress bar for "timeline"
							if(bar_type=="timeline")
								{
									a+="<div id='area_bar_"+bar_type+"_progress' style='position:relative;width:0px;height:"+(bar_height-1)+"px;background-color:#9C9C9C;overflow:hidden;'></div>";
								}

						// => knob
							a+="<img id='area_bar_"+bar_type+"_knob' src='"+VIDEO["directory"]["images"]+"knob.gif' style='position:absolute;width:"+knob_width+"px;height:"+bar_height+"px;top:0px;left:"+(-(knob_width/2))+"px'>";

					a+="</div>";

			a+="<div onmousedown='VIDEO[\"slider_active\"]=\""+bar_type+"\";' onmouseup='var tmp_position=videoBar(event);"+(bar_type=="timeline"?"if(tmp_position){videoChange(tmp_position,true);}":"")+"VIDEO[\"slider_active\"]=\"\";' onmousemove='videoBar(event);' ondrag='return false' ondragstart='return false' onselectstart='return false' style='cursor:hand;cursor:pointer;position:absolute;left:-"+(knob_width/2)+"px;top:0px;width:"+(bar_width+knob_width)+"px;height:"+bar_height+"px;opacity:.0;-moz-opacity:.0;filter:alpha(opacity=0);background-color:#FFFFFF;'></div>";

			a+="</div>";

			a+="</div>";

			return a;

		}


	// => flash video to js
	function flashToJsvideo(type,value)
		{

			if(type=="position") // => playhead position
				{
					
					// => store current video position
						VIDEO["video"]["position"]["current"]=value/1;

					// => update the furthest position in the video if the current position is the furthest so far
						if(VIDEO["video"]["position"]["current"]>VIDEO["video"]["position"]["furthest"])
							{
								VIDEO["video"]["position"]["furthest"]=VIDEO["video"]["position"]["current"];
							}

					// => if at least one video still needs loading
						if(VIDEO["video"]["current_index"]!=VIDEO["video"]["video_index"])
							{

								// => the next video needs playing if the playhead is <=2 seconds from the end
									if(VIDEO["video"]["duration"]>0&&VIDEO["video"]["position"]["current"]>=(VIDEO["video"]["duration"]-2))
										{
											setTimeout("videoLoadNext("+(VIDEO["video"]["current_index"]+1)+");",2500);
										}

							}

					// => continue if the toolbar is not in "ignore" mode
						if(VIDEO["toolbar_ignore"]==0)
							{

								// => if slides exist
									if(VIDEO["slides"])
										{

											// => find the current slide position
												var tmpSlidePosition=0;

												while(VIDEO["slides"]["times"][tmpSlidePosition]<=VIDEO["video"]["position"]["current"])
													{
														tmpSlidePosition++;
													}

												tmpSlidePosition--;

											// => change slide if slide position has changed
												if(VIDEO["slides"]["current"]!=tmpSlidePosition)
													{
														videoSlideLoad(tmpSlidePosition);
													}

										}

								// => update the knob/time if the slider is not being used and the video is playing
									if(VIDEO["slider_active"]==""&&VIDEO["video"]["playing"])
										{

											// => update the timecode
												areaID("area_timeline_position").innerHTML=videoTime(VIDEO["video"]["position"]["current"]);

											// => update the knob position
												if(VIDEO["video"]["duration"]>0)
													{

														// => update the knob position
															videoBarPosition("timeline",VIDEO["video"]["position"]["current"],VIDEO["video"]["duration"]);

														// => if this is the end of the video, reset to the beginning
															// NOTE: the playhead never goes exactly to the end so set it to reset if the playhead is <=1 second before the end
															if(VIDEO["video"]["position"]["current"]>=(VIDEO["video"]["duration"]-1))
																{
																	if(VIDEO["video"]["video_end_html"])
																		{
																			setTimeout("videoPlay(true);areaShow('area_video_play',1);if(areaGet('area_video_end_html',true)==''){areaPut('area_video_end_html',VIDEO['video']['video_end_html']);};areaShow('area_video_end_html');",999);
																		}
																	else
																		{
																			setTimeout("videoPlay(true);"+(VIDEO["slides"]?"videoSlideLoad(0,true);":"videoChange(0);"),999);
																		}
																	
																	VIDEO["video"]["position"]["furthest"]=VIDEO["video"]["duration"];
																	
																	videoStat();
																}

													}

										}

							}

				}
			else if(type=="percent") // => percentage loaded
				{

					// => update percentage of video loaded
						VIDEO["video"]["percent"]=value/1;

					// => update the percentage loaded bar
						areaID("area_bar_timeline_progress").style.width=VIDEO["video"]["percent"]+"%";

					// => buffer video if currently playing
						if(VIDEO["video"]["playing"])
							{
						
								var video_loaded=(VIDEO["video"]["percent"]/100)*VIDEO["video"]["duration"];
								var buffer_seconds=5;
						
								if(VIDEO["video"]["position"]["current"]>(video_loaded-buffer_seconds))
									{
										VIDEO["video"]["playing_buffering"]=true;
										areaShow("area_video_loading");
										flashToFlash("video","Pause");
									}
								else if(VIDEO["video"]["playing_buffering"])
									{
										areaShow("area_video_loading",1);
										flashToFlash("video","Play");
									}
						
							}

					// => keep updating the bar until the video has loaded (ie, 100%)
						if(VIDEO["video"]["percent"]<100)
							{
								setTimeout("flashToFlash('video','Percent');",1000);
							}



				}
			else if(type=="duration") // => video duration
				{

					// => is the video duration known yet?
						if(!isNaN(value)&&value>0) // => duration is known
							{

								// => store video duration
									VIDEO["video"]["duration"]=value/1;

								// => begin playing the video if it is set to begin playing
									if(VIDEO["video"]["playing"])
										{
											VIDEO["video"]["playing_buffering"]=true;
										}

								// => begin progress bar
									flashToFlash("video","Percent");

								// => update the furthest position in the video so far
									videoStat(true);
								
									setInterval("videoStat();",60000);

								// => hide the "loading" area
									areaShow("area_video_loading",1);

								// => show the "play" area if the video is currently stopped
									if(!VIDEO["video"]["playing"])
										{
											areaShow("area_video_play");
										}

								// => if this is the last video
									if(VIDEO["video"]["current_index"]==VIDEO["video"]["video_index"])
										{

											// => allow changes to the slide
												VIDEO["toolbar_ignore"]=0;

											// => put video duration into "duration" area
												areaID("area_timeline_duration").innerHTML=videoTime(VIDEO["video"]["duration"]);

											// => create slide markers if slides are used
												if(VIDEO["slides"])
													{
														videoSlideMarkersMake();
													}

										}

							}
						else // => duration not known
							{

								// => try getting the duration again in a short period
									setTimeout("flashToFlash('video','Duration');",500);

							}

				}
			else if(type=="loaded") // => initialise video
				{

					// => get the video duration
						flashToFlash("video","Duration");

					// => set the video volume
						videoBarPosition("volume",VIDEO["video"]["volume"]["level"],100);
						flashToFlash("video","Volume",VIDEO["video"]["volume"]["level"]);

					// => continually update the knob position with the current video time
						setInterval("flashToFlash('video','Position');",1000);

				}

		}


	// => update viewing stats on web server
	function videoStat(send_regardless)
		{

			if(send_regardless||(VIDEO["video"]["position"]["furthest"]>VIDEO["video"]["position"]["recorded"]))
				{
					VIDEO["video"]["position"]["recorded"]=VIDEO["video"]["position"]["furthest"];
					
					scriptGet("/stats/video/",{"random_id":VIDEO["video"]["random_id"],"position":Math.round(VIDEO["video"]["position"]["furthest"])});
				}

		}


	// => load the next video
	function videoLoadNext(next_index)
		{
		
			// => the "next" video index mustn't be the same as the "current" video index
				if(VIDEO["video"]["current_index"]>=next_index)
					{
						return;
					}

			// => reset the duration
				VIDEO["video"]["duration"]=0;

			// => hide the "play" area
				areaShow("area_video_play",1);

			// => show the "loading" area
				areaShow("area_video_loading");

			// => update the current index
				VIDEO["video"]["current_index"]=next_index;

			// => load the next video
				flashToFlash("video","Load",VIDEO["video"]["files"][VIDEO["video"]["current_index"]],"1")
				
			// => try getting the duration again in a short period - do this again since a new video has been loaded
				setTimeout("flashToFlash('video','Duration');",500);

		}


	// => create slide markers
	function videoSlideMarkersMake()
		{

			var bar_width=parseInt(areaID("area_bar_timeline").style.width);

			var a="";

			for(var b=0; b<VIDEO["slides"]["times"].length; b++)
				{

					if(VIDEO["slides"]["markers"][b]=="1")
						{
							a+="<a href='javascript:videoSlideLoad("+b+",true);'><img id='area_video_slide_markers_"+b+"' src='"+VIDEO["directory"]["images"]+(b==VIDEO["slides"]["current"]?"slide_marker_on.gif":"slide_marker_off.gif")+"' style='width:6px;height:6px;position:absolute;left:"+(((VIDEO["slides"]["times"][b]/VIDEO["video"]["duration"])*bar_width)-3)+"px;z-index:"+(99-b)+";' title=\""+(VIDEO["slides"]["titles"][b]?VIDEO["slides"]["titles"][b]:"Slide "+(b/1+1))+"\"></a>";
						}

				}

			areaID("area_video_slide_markers").innerHTML=a;

		}


	// => load a slide
	// index => slide index
	// update => exists if to update the position marker on the timeline => OPTIONAL
	function videoSlideLoad(index,update)
		{

			// => the slide can only be changed if the flash movie has loaded and slides are used and the final "video" is being played
				if(page["flash_loaded"]["video"]&&VIDEO["slides"]&&VIDEO["video"]["current_index"]==VIDEO["video"]["video_index"])
					{

						if(typeof VIDEO["slides"]["times"][index]!="undefined") // => slide exists
							{

								// => update the slide
									VIDEO["slides"]["current"]=index;

								// => change the medium-sized slide
									areaID("area_video_slide_img").src=VIDEO["directory"]["slides"]+"slide_medium_"+VIDEO["slides"]["indexes"][index]+".jpg"+(VIDEO["slides"]["versions"][0]?"?"+VIDEO["slides"]["versions"][0]:"");

								// => update the large slide if shown
									if(areaID("area_slide_number_big"))
										{
											areaID("area_slide_number_big").innerHTML=VIDEO["slides"]["current"]+1;
								
											areaID("area_video_slide_img_overlay").src=VIDEO["directory"]["slides"]+"slide_large_"+VIDEO["slides"]["indexes"][index]+".jpg"+(VIDEO["slides"]["versions"][0]?"?"+VIDEO["slides"]["versions"][0]:"");
										}

								// => html over the slide
									if(VIDEO["slides"]["html"][index])
										{
											areaPut("area_video_slide_html",VIDEO["slides"]["html"][index]);
										}

									areaShow("area_video_slide_html",!VIDEO["slides"]["html"][index]);

								// => highlight the current slide
									var b;

									for(b=0; b<VIDEO["slides"]["times"].length; b++)
										{

											var slide_marker=areaID("area_video_slide_markers_"+b);
											
											if(!slide_marker)
												{
													continue;
												}

											if(slide_marker.src.match(/([a-z]+)\.gif$/)[1]!=(b==index?"on":"off"))
												{
													slide_marker.src=VIDEO["directory"]["images"]+"slide_marker_"+(b==index?"on":"off")+".gif";
										
												}
										
											// => if this marker is active, bring it to the front
												slide_marker.style.zIndex=b==index?"99":"0";
											
										}

								// => update the timeline bar if needed
									if(update)
										{
											videoChange(VIDEO["slides"]["times"][index]);
										}

							}

					}

		}


	// => play/pause video
	function videoPlay(play)
		{

			// => play/pause video
				if(play) // => go from "play" to "pause"
					{
						if(VIDEO["video"]["playing"])
							{
								flashToFlash("video","Pause");
								VIDEO["video"]["playing"]=false;
								areaShow("area_video_play");
								areaShow("area_video_loading",1); // => hide the "loading" area
							}
					}
				else // => go from "pause" to "play"
					{
						if(!VIDEO["video"]["playing"])
							{
								// => if the video position is at the end, go to the start
								if(VIDEO["video"]["position"]["current"]>=(VIDEO["video"]["duration"]-1))
									{
										VIDEO["video"]["position"]["current"]=0;
										videoChange(0);
										flashToFlash("video","Play");
									}
								else
									{
										flashToFlash("video","Play");
									}
								
								VIDEO["video"]["playing"]=true;
								areaShow("area_video_play",1);
							}
					}

			// => update "play" button
				areaID("area_btn_play").src=VIDEO["directory"]["images"]+(VIDEO["video"]["playing"]?"pause.gif":"play.gif");

		}


	// => change video playhead position
	function videoChange(time,start_video)
		{

			// => the video playhead position can only be changed if the final video is being played
				if(VIDEO["video"]["current_index"]!=VIDEO["video"]["video_index"])
					{
						return;
					}

			// => don't let the "interval" function change anything while the video position is changed
				VIDEO["toolbar_ignore"]=1;
				setTimeout("VIDEO['toolbar_ignore']=0;",500);

			// => there is a problem when setting the playhead to "0" so set it to "?.0001"
				flashToFlash("video","Playhead",Math.round(time)+".0001");

			// => update video position knob
				videoBarPosition("timeline",time,VIDEO["video"]["duration"]);

			// => update timecode
				areaID("area_timeline_position").innerHTML=videoTime(time);

			// => play the video if it is currently stopped
				if(start_video&&!VIDEO["video"]["playing"])
					{
						videoPlay(VIDEO["video"]["playing"]);
					}

			// => hide the video end html
				if(VIDEO["video"]["video_end_html"])
					{
						areaShow("area_video_end_html",1);
					}

		}


	// => update position of knob on video bar
	function videoBarPosition(type,position,total)
		{

			// => half the width of the knob
				var knob_adjust=parseInt(areaID("area_bar_"+type+"_knob").width)/2;

			// => bar width
				var bar_width=parseInt(areaID("area_bar_"+type).style.width);

			// => update position of the knob on the bar
				areaID("area_bar_"+type+"_knob").style.left=Math.round(((position/total)*bar_width)-knob_adjust)+"px";
	
		}


	// => move bar slider
	function videoBar(event)
		{

			// => the slider must be moving
				if(VIDEO["slider_active"]=="")
					{
						return;
					}

			// => the timeline slider cannot be used unless the video being played is the final video
				if(VIDEO["slider_active"]=="timeline"&&VIDEO["video"]["current_index"]!=VIDEO["video"]["video_index"])
					{
						return;
					}

			// => get cursor position on the slider area
				var cursor_pos=mousePosition(event);

			// => adjust the position because the knob goes outside the slider area
				var Xadjusted=parseInt(areaID("area_bar_"+VIDEO["slider_active"]+"_knob").width)/2;

			// => cursor must be >0
				if((cursor_pos["x"]-Xadjusted)<0)
					{
						return;
					}

			// => get the knob position as a percentage of the slider width
				var barPosition=(cursor_pos["x"]-Xadjusted)/parseInt(areaID("area_bar_"+VIDEO["slider_active"]).style.width);
				
				if(barPosition<0)
					{
						barPosition=0;
					}
				if(barPosition>1)
					{
						barPosition=1;
					}

			// => if the "timeline" bar is being moved
				if(VIDEO["slider_active"]=="timeline")
					{
	
						var tmpLoaded=(VIDEO["video"]["percent"]/100)*VIDEO["video"]["duration"];
						var tmpPosition=Math.min(barPosition,1)*VIDEO["video"]["duration"];
	
						if(VIDEO["video"]["duration"]==0||tmpPosition>tmpLoaded)
							{
								return false;
							}
	
					}

			// => move the slider knob
				areaID("area_bar_"+VIDEO["slider_active"]+"_knob").style.left=(cursor_pos["x"]-(Xadjusted*2))+"px";

			// => continue depending on the slider type
				if(VIDEO["slider_active"]=="timeline") // => timeline
					{

						// => return video position
							return Math.min(barPosition,1)*VIDEO["video"]["duration"];

					}
				else // => volume
					{

						// => volume level (0-100)
							VIDEO["video"]["volume"]["level"]=barPosition*100;

							if(VIDEO["video"]["volume"]["level"]>0)
								{
									VIDEO["video"]["volume"]["level_restore"]=VIDEO["video"]["volume"]["level"];
								}

						// => update volume level
							flashToFlash("video","Volume",VIDEO["video"]["volume"]["level"]);

						// => update "volume" button
							areaID("area_btn_volume").src=VIDEO["directory"]["images"]+"volume_"+(VIDEO["video"]["volume"]["level"]>0?"on":"off")+".gif";

						// => update the volume level in the cookie so that the volume level can be restored for other videos on the site
							cookieSet("video_volume",VIDEO["video"]["volume"]["level"]);

					}

		}


	// => video volume
	function VIDEOvolume()
		{

			// => update volume level value
				if(VIDEO["video"]["volume"]["level"]>0)
					{
						VIDEO["video"]["volume"]["level"]=0;
					}
				else
					{
						VIDEO["video"]["volume"]["level"]=VIDEO["video"]["volume"]["level_restore"];
					}

			// => update volume knob position
				videoBarPosition("volume",VIDEO["video"]["volume"]["level"],100);

			// => update "volume" button
				areaID("area_btn_volume").src=VIDEO["directory"]["images"]+(VIDEO["video"]["volume"]["level"]>0?"volume_on.gif":"volume_off.gif");

			// => update volume level in movie player
				flashToFlash("video","Volume",VIDEO["video"]["volume"]["level"]);

			// => update volume level in cookie
				cookieSet("video_volume",VIDEO["video"]["volume"]["level"]);

		}
