//
//this file contains functions to control the playback and position of the embedded quicktime player
//

var timeCheck = "";

function FLV(FLVEmbedded) {
	this.player = FLVEmbedded;
	this.runTimeInSeconds = 0;
	this.isLooping = false;
	this.URL = "";
}

FLV.prototype.play = function() {
	this.player.play();
}

FLV.prototype.stop = function() {
	this.player.stop();
}


FLV.prototype.playSection = function (start,end) {
	this.stop();
	var startInSec = this.timeToSeconds(start)-2;
	var endInSec = this.timeToSeconds(end);
	this.player.playSection(startInSec,endInSec);
}

FLV.prototype.loopSection = function (start,end) {
	this.stop();
	var startInSec = this.timeToSeconds(start)-2;
	var endInSec = this.timeToSeconds(end);
	this.player.loopSection(startInSec,endInSec);
}

FLV.prototype.defaultPlay = function() {
	//
	this.player.defaultPlay();
}

FLV.prototype.loadURL = function(url) {
	this.player.loadURL(url);
	this.URL = url;
}


/*************************************************************************/
/*    time functions for quicktime player 
/*************************************************************************/
//return the current time in the movie
FLV.prototype.getCurrentTime = function() {
	if (this.URL != "") {
		var curTime = Math.round(this.player.getTime());
		return curTime;
	}
}

//format the time to hh:mm:ss
FLV.prototype.formatTime = function(curTime) {
	//format hours
	if (curTime > 60*60)
	{
		hours = Math.floor(curTime/(60*60));
		curTime = curTime - hours*60*60;
		
		if (hours < 10) {
			hours = "0" + hours;
		}

	}
	else
	{
		hours = "00";
	}

	//format minutes
	if (curTime >= 60) {
		minutes = Math.floor(curTime/60);
		curTime = curTime - minutes*60;
		
		if (minutes < 10) {
			minutes = "0" + minutes;
		}
		
	} else { 
		minutes = "00";
	}
	
	//format seconds
	seconds = Math.floor(curTime%60);
	if (seconds < 10) { 
		seconds = "0" + seconds; 
	}
	
	//prepare new time
	newTime = hours + ":" + minutes + ":" + seconds;
	return newTime;
	
	//return curTime;
}

FLV.prototype.timeToSeconds = function(_time) {
	var timeunits = new Array();
	timeunits = _time.split(':');
	
	var hours = Number(timeunits[0]);
	var minutes = Number(timeunits[1]);
	var seconds = Number(timeunits[2]);
	
	var frames = ((hours*3600) + (minutes*60) + seconds);
	return frames;
}

FLV.prototype.increaseTime = function(_time) {
	//convert to frames
	var seconds = this.timeToSeconds(_time) * 1; //*1 to convert to a number

	//add one second
	seconds = seconds + 1;

	//convert to readable time
	var newTime = this.formatTime(seconds);
	
	return newTime;
}

FLV.prototype.decreaseTime = function(_time) {
	//convert to frames
	var seconds = this.timeToSeconds(_time) * 1; //*1 to convert to a number

	//remove one second
	seconds = seconds - 1;

	//convert to readable time
	var newTime = this.formatTime(seconds);
	
	return newTime;
}



