// realplayercontrols.js
// v1.0
// mz 02-09-05 v1.2
// mz/gz 02-10-08 added slider, uses lang_xx.js for Mouse-over texts
// mz/gz 02-12-12 a_/b_ Folder Struktur angepasst

playercontrols = new toolbar("playercontrols",t_start);
volumecontrols = new toolbar("volumecontrols","");
playercontrols.addButton(t_start, "../a_images/p-play.gif",    "../a_images/p-play_akt.gif",  "../a_images/p-play_o.gif");
playercontrols.addButton(t_stop,  "../a_images/p-stop.gif",    "../a_images/p-stop_akt.gif",  "../a_images/p-stop_o.gif");
playercontrols.addButton(t_pause, "../a_images/p-pause.gif",   "../a_images/p-pause_akt.gif",  "../a_images/p-pause_o.gif");
volumecontrols.addButton(t_vol_up,  "../a_images/p-volplus.gif", "../a_images/p-volplus.gif", "../a_images/p-volplus_o.gif");
volumecontrols.addButton(t_vol_down, "../a_images/p-volmin.gif",  "../a_images/p-volmin.gif",  "../a_images/p-volmin_o.gif");

var isstate = -1;
var wasstate = -1;
var clipDuration = -1;

function init() {
	if (!(navigator.appVersion.indexOf("NT;",0)>0) || (navigator.platform.indexOf("95")>0))
		window.setInterval("Playerstate()",500)
	
	if (!document.MediaPlayer.GetLiveState()) {
		//wait for player getting into a valid state
		if (clipDuration <= 0){
			window.setTimeout("init()",500);	
		}
		clipDuration = Math.round(document.MediaPlayer.GetLength()/1000);
	}
	
	window.setTimeout("setTime()",1000);

} //End init

function Playerstate() {
	isstate = document.MediaPlayer.GetPlayState();

	if (wasstate != isstate) {
		wasstate = isstate;
		switch (wasstate) {
			case 0:
			playercontrols.setButton(document.images[t_stop]);
			break;
			case 4:
			playercontrols.setButton(document.images[t_pause]);
			break;
			case 3:
			playercontrols.setButton(document.images[t_start]);
			break;
		}
	}
} //End Playerstate

function leiser(){
	currVolume = document.MediaPlayer.GetVolume();
	newVolume = currVolume - 25;
	if (newVolume < 0) newVolume = 0;
	document.MediaPlayer.SetVolume(newVolume);
}

function lauter(){
	currVolume = document.MediaPlayer.GetVolume();
	newVolume = currVolume + 25;
	if (newVolume > 100) newVolume = 100;
	//alert (newVolume);
	document.MediaPlayer.SetVolume(newVolume);	
}

function fastForward(){
	// Playing?
	if(document.MediaPlayer.GetPlayState() == 3){
		// seekable?
		if(document.MediaPlayer.GetCanSeek()){
			currPosition = document.MediaPlayer.GetPosition();
			clipLength = document.MediaPlayer.GetLength();
			newPosition = currPosition + 30000;
			if (newPosition > clipLength) newPosition = clipLength;
			document.MediaPlayer.SetPosition(newPosition);
		}
		else alert(t_fforward_error);
	}
	//else alert("Sorry, clip has to be playing.");
}

function fastReverse(){
	// Playing?
	if(document.MediaPlayer.GetPlayState() == 3){
		// seekable?
		if(document.MediaPlayer.GetCanSeek()){
			currPosition = document.MediaPlayer.GetPosition();
			newPosition = currPosition - 30000;
			if (newPosition < 0)newPosition = 0;
			document.MediaPlayer.SetPosition(newPosition);
		}
		else alert(t_frewind_error);
	}
	//else alert("Sorry, clip has to be playing.");
}


function TBaction(s_buttoname) {
	//alert("TBaction")
	switch (s_buttoname) {
		case t_start:
			document.MediaPlayer.DoPlay();
			break;
		case t_stop:
			document.MediaPlayer.DoStop();
			break;
		case t_pause:
			document.MediaPlayer.DoPause();
			break;
		case t_vol_up:
			lauter();
			return false;
		case t_vol_down:
			leiser();
			return false;
		default:
			//alert(s_buttoname);
	}
	return true;
} //End TBaction



// Function for Displaying Video in Fullscreen Mode
function goFullscreen() {
	document.MediaPlayer.SetFullScreen();
}

// Funktion zum Anspringen einer bestimmten Position
// Übergabeparameter: Zeit in Sekunden vom Anfang des Clips bis zur gewünschten Position
function jumpTo(tsec){
	var newPosition = tsec*1000;

	// if not playing
	if (document.MediaPlayer.GetPlayState() == 0){
		document.MediaPlayer.DoPlay();
		
		//wait for player getting out of stop state
		while (document.MediaPlayer.GetPlayState() == 0){
			window.status = document.MediaPlayer.GetPlayState();	
		}
	}

	// not seeking?
	if(document.MediaPlayer.GetPlayState() != 5){
		// seekable?
		if(document.MediaPlayer.GetCanSeek()){
			clipLength = document.MediaPlayer.GetLength();
			if (newPosition > clipLength) newPosition = clipLength;
			document.MediaPlayer.SetPosition(newPosition);
			
		}
		else alert(document.MediaPlayer.GetPlayState() + t_function_not_available);
	}
	//else alert(document.MediaPlayer.GetPlayState() + "...Sorry, clip has to be playing first");
}

function setVideoPosition(pos){
	if (pos >= 0) {
		newPos = Math.round(pos*clipDuration);
		//temp = window.status;
		//window.status = temp + "|" + newPos;
	}
	document.MediaPlayer.SetPosition(newPos);
}

function setTime() {

	var curPos = Math.round(document.MediaPlayer.GetPosition()/1000);
	var clipPosition = 0;

	if (curPos > 0) {
		clipPosition = Math.round((curPos/clipDuration)*1000);
	}
	
	if (!dragOn) setSliderPos(clipPosition);
	
	window.setTimeout("setTime()",1000);

}
