/* OCULUS TV */

var $filmzeit = 0;
var $zeitleiste_width = 740;
var $play = false;
var $fullscreen = false;
var $video = false;
var $sound = true;
var $videotyp = false;
var $drag = false;
var $canplay = false;

function controls_startvideo($id){
	document.location.href=$id;
}

function control_init($zeit, $typ, $seek){
	$video = document.getElementById('flashplayer_netstream');
	$filmzeit = $zeit;
	$videotyp = $typ;
	control_seteventsandfunctions();
	control_settime(0);
}

function control_seteventsandfunctions(){
	$("#div_zeitleiste_marker").draggable({ axis: 'x', containment: 'parent', start: function(event, ui) {
		$drag = true;
		control_pause();
	}, stop: function(event, ui) {
		$drag = false;
		$x = ui.position["left"];
		$time = $filmzeit/($zeitleiste_width/$x);
		$time = Math.round($time)-1;
		if($time>($filmzeit-5)){ $time = $filmzeit-5;}
		if($time<1){$time=0;}
		control_settime($time);
		control_seek($time);
	}, drag: function(event, ui) {
		$x = ui.position["left"];
		$time = $filmzeit/($zeitleiste_width/$x);
		$time = Math.round($time)-1;
		if($time>($filmzeit-5)){ $time = $filmzeit-5;}
		if($time<1){$time=0;}
		//$video.currentTime=$time;
		control_settime($time);
	}});
	
	$('#div_zeitleiste').click(function(e) {
		var $left = Math.floor(($(window).width()-1202)/2); //- e.pageX - this.offsetLeft;
		var $x = e.pageX - this.offsetLeft;
		$x = $x-$left;
		$x = $x-17;
		$time = $filmzeit/($zeitleiste_width/$x);
		$time = Math.round($time)-1;
		if($time>($filmzeit-5)){ $time = $filmzeit-5;}
		if($time<1){$time=0;}
		//$video.currentTime=$time;
		//$video.play();
		control_settime($time);
	});
}

function control_event_timeupdate($s, $playing, $sounding) {
	if($drag==false){control_settime(Math.floor($s));}
	//Play und Pause
	if($playing==true && $play==false){
		setcontrol_play();
	} else if ($playing==false && $play==true){
		setcontrol_pause();
	}
	if($sounding==true && $sound==false){
		setcontrol_sound_on();
	} else if($sounding==false && $sound==true){
		setcontrol_sound_off();
	}
}

function control_info_ein(){
	$height = document.getElementById("div_info_content").offsetHeight + 30 + 10;
	$("#div_info").animate({height:''+$height+'px'},"fast");
	$("#div_button_info_ein").hide();
	$("#div_button_info_aus").show();
}

function control_info_aus(){
	$("#div_info").animate({height:'30px'},"fast");
	$("#div_button_info_ein").show();
	$("#div_button_info_aus").hide();
}

function control_video($typ, $src){
	if($typ=="charts"){
		$("#div_button_charts").hide();
		$("#div_button_charts_akt").show();
		$("#div_button_speaker").show();
		$("#div_button_speaker_akt").hide();
	} else {
		$("#div_button_charts").show();
		$("#div_button_charts_akt").hide();
		$("#div_button_speaker").hide();
		$("#div_button_speaker_akt").show();		
	}
	$("#a_text").html("js_loading#"+$src);
	$("#a_text").click();
}

function control_seek($time){
	$play = true;
	$("#a_text").html("js_seeking#"+$time);
	$("#a_text").click();
	$("#div_button_play").hide();
	$("#div_button_pause").show();
}

function control_play(){
	$("#a_text").html("js_play");
	$("#a_text").click();
	setcontrol_play();
}

function setcontrol_play(){
	$play = true;
	$("#div_button_play").hide();
	$("#div_button_pause").show();
}

function control_pause(){
	$("#a_text").html("js_pause");
	$("#a_text").click();
	setcontrol_pause();
}

function setcontrol_pause(){
	$play = false;
	$("#div_button_play").show();
	$("#div_button_pause").hide();
}

function control_sound_on(){
	$("#a_text").html("js_sound");
	$("#a_text").click();
	setcontrol_sound_on();
}

function setcontrol_sound_on(){
	$sound = true;
	$("#div_button_sound").show();
	$("#div_button_sound_off").hide();
}

function control_sound_off(){
	$("#a_text").html("js_mute");
	$("#a_text").click();
	setcontrol_sound_off();
}

function setcontrol_sound_off(){
	$sound = false;
	$("#div_button_sound").hide();
	$("#div_button_sound_off").show();
}

function control_fullscreen(){
	$("#a_text").html("js_fullscreen");
	$("#a_text").click();
}

function control_settime($zeit){
	$x = 0;
	$("#div_zeitleiste_akt").stop();
	$("#div_zeitleiste_marker").stop();
	if($filmzeit>0 && $zeit>0){
		if($zeit>$filmzeit){$zeit=$filmzeit;}
		$v = $zeit/$filmzeit;
		$x = Math.round($zeitleiste_width*$v);
		
		//$("#div_zeitleiste_akt").animate({width:''+$x+'px'},5000,'linear');
		//$("#div_zeitleiste_marker").animate({left:''+$x+'px'},5000,'linear');
	} else {
		$x = 0;
	}
	
	if($drag==false){
		$("#div_zeitleiste_akt").css('width', $x+'px');
		$("#div_zeitleiste_marker").css('left', $x+'px');
	}
	control_zeitausgabe($zeit);
}

function control_zeitausgabe($zeit){
	$("#div_laufzeit").html(control_zeitformat($zeit)+" | "+control_zeitformat($filmzeit));
}

function control_zeitformat($s){
	$m = Math.floor($s/60);
	$s = $s-$m*60;
	if($s<=9){ $s = "0"+$s;}
	if($m<=9){ $m = "0"+$m;}
	return $m+":"+$s;
}

