/*
this file supports the flv player with interaction of minutes
Coded for NotuBiz, 2009
*/


var currentTime=0; // will cache values for current time of movie (updated by checkMediaStatus)
var systemType=''; // stores system (volledig/basis)
var playerType='audio'; // stores kind of player it is (audio/video)
var curspreker=0; // stores current speaker
var curagenda=0; // stores current agenda

var aspectRatio='4.3'; // default aspectRatio
var videoHeight=0;


function setSystem(nSystemType)
{
    systemType=nSystemType;
}

function setPlayerType(nPlayerType)
{
    playerType=nPlayerType;
}

function jumptoitem(notule)
{
    //console.log('jumptoitem('+notule+')');
    currentjump=notule;
    jumpto=timestr[notule];

    if($f().isPaused())
    {
	$f().toggle();
    }
    $f().seek(jumpto);
}

function init()
{
    setTimeout("checkMediaStatus()",1000);
}


function checkMediaStatus()
{
    //this function repeats itselves every second
    setTimeout("checkMediaStatus()",1000);
    
    currentTime=0;
    try{
	currentTimeT=$f().getTime();
        currentTime=parseInt(currentTimeT);
    }catch(err){
	currentTime=0;
    }
    
    //currentTimeT=$f().getTime();
    //if(typeof currentTimeT !== "undefined"){
    //	currentTime=parseInt(currentTimeT);
    //}else{
    //	currentTime=0;
    //}
    
    
    if(systemType=="volledig")
    {
        // als er andere spreker is : 
        ns=getSpreker();
        if(curspreker != ns && ns != 0)
        {
	    loadSprekerInfo(ns);
	    curspreker=ns;
	}
    }
    if(playerType=="audio")
    {
        // kijken of er een ander agenda-item gespeeld word : 
        ca=getAgenda();
        if(curagenda != ca && ca != 0)
	{
	    // div van spreker wijzigen
	    curagenda=ca;
	    document.getElementById('div_content_audiofragment').innerHTML=ca;
        }
    }
}


function getSecond(notule)
{
    return timestr[notule];
}

function getAgenda()
{
    retval="";
    for (var n in agendaid)
    {
	if(currentTime>=agendastart[n])
	{
    	    retval=agendatitel[n];
        }
        lastval=n;
    }
    return retval;
}

function getSpreker()
{
    foundlast=false
    lastval=0;
    retval=0;
    
    for (var n in sprekerid)
    {
	if(timestr[n]>=(currentTime+1) && ! foundlast && sprekerid[lastval]!=0)
	{
	    retval=sprekerid[lastval];
	    foundlast=true;
	}
	else
	{
	    if(!foundlast)
		lastval=n;
	}
    }
    if( ! retval) // nodig voor laatste agendapunt
        retval=sprekerid[n];
	
    return retval;
}

function setVideoHeight(height){
    videoHeight=height;
}
function getVideoHeight(){
    return videoHeight;
}
function setAspectRatio(ratio){
    aspectRatio=ratio;
}

// functie returned height in aspect. Default inputvars zijn de 4.3 vars
function getAspectHeightByWidth(width){
    if(aspectRatio=='4.3'){
	retHeight=Math.ceil((width/4)*3);
    }else{
	retHeight=Math.ceil((width/16)*9);
    }
    
    return retHeight;
}

