// JavaScript Document
$(document).ready(function(){
	//global variables
	var video;
	var playing;
	playing = false; //use this variable to keep track of whether the video is playing or not
	
	//get the video element and make sure it exists before continuing
	if($('video')) {
		video = $('video');
	}
	if(video){
	//Function to play the video... 	
	function fPlay() {
			//make sure the video isn't playing
			if(playing == false) {
				//play the video and change the variable keeping track of that
				video.play()
				playing = true;
			}
			else {
				//run the pause function in case, for some reason the
				//play function runs while the video is already playing
				fPause();
			}
		}
	function fPause() {
				//make sure the video is playing
				if(playing == true) {
					//remove the click event that plays the video
					video.removeEventListener("click", fPlay, false);
					//add a click event to to pause the video
					video.addEventListener("click", rePlay, false);
				}
				else { 
					fPlay();
				}
			}
	//function to pause the video, 
	//and set it up to play again
	function rePlay() {
			video.pause();
			playing = false;
			//remove pause event, and re-add play event
			video.removeEventListener("click", fPause, false);
			video.addEventListener("click", fPlay, false);
	}
	//a test for IE
	if(video.addEventListener) {
		video.addEventListener("click", fPlay, false);
		video.addEventListener("playing", fPause, false);
	}
	}
});
