var video ;

function Video(htmlID, src, poster, type, isLooped) {
	this.video = document.getElementById(htmlID);
	this.video.poster = poster;
	this.video.src = src;
	this.video.type = (type == undefined) ? "video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"" : type;
	this.isLooped = (isLooped == undefined) ? false : isLooped;
	this.playVideo = playVideo;
	this.restartVideo = restartVideo;
	this.pauseVideo = pauseVideo;
	this.resumeVideo = resumeVideo;
	this,playPause = playPause;
	this.setVolume = setVolume;
	this.playing = false;
	this.addEventListeners = addEventListeners;
	this.checkMovieSupport = checkMovieSupport;
}

function playVideo(e){
	//console.log("playVideo");
	this.video.load();
	this.video.play();
	this.playing = true;
	this.setVolume(0);
}

function restartVideo(e){
	//console.log("playVideo");
	  this.video.currentTime = 0.1;
	  this.video.play();
}

function resumeVideo() {
	this.video.play();
	this.playing = true;
}

function pauseVideo(e) {
	this.video.pause();
	this.playing = false;
}

function playPause(e) {
     if (video.paused) {
    	this.video.play();
    	this.playing = true;
     } else {
    	 video.pause();
     	this.playing = false;
     }	
}

function stopVideo(e) {
	this.playing = false;
}

function setVolume(volumeVal) {
	//console.log("setVolume > " + volumeVal)
	//console.log(this.video);
	this.video.volume = volumeVal;
	
}

function getPercentProg(e) {
	var video = e.currentTarget;
	var soFar = parseInt(((video.buffered.end(0) / video.duration) * 100));
	//console.log(soFar);
    //document.getElementById("loadStatus").innerHTML =  soFar + '%';
}

function addEventListeners() {
	this.video.addEventListener('progress',getPercentProg,false);
}

function checkMovieSupport() {
 
	var playAny = 0;
    myTypes = new Array ("video/mp4","video/ogg","video/divx");
    var nonePlayable = "Your browser cannot play these movie types."
    for (x = 0; x < myTypes.length; x++) { 
    	var canPlay = this.video.canPlayType(myTypes[x]);
    	//console.log(myTypes[x] + " > canPlay: " + canPlay);
    	if ((canPlay=="maybe") || (canPlay=="probably")) playAny = 1;
    }
    if (playAny==0) console.log(nonePlayable)
}


