﻿
//--- scripts for Flash Video handling (note: supplerende script i imageupload ) ----

var FLVregisterArr = new Array()
function FLVregisterMovie(FLVid) {FLVregisterArr.push(FLVid)}

var FLVautoPlay = true
function FLVdisableAutoPlay() {FLVautoPlay = false;}

function FLVcompleteCallback(FLVid) {FLVstartNextMovie(FLVid)}

//--- ready callback: start if first - else go poster ---

var FLVcountReady = 0

function FLVreadyCallback(FLVid)
{
    FLVcountReady++;
    if (FLVregisterArr.length == 1) //if only one -> play or poster according to autoplaysetting
    {
        if (FLVautoPlay) {FLVcallFlashObj(FLVid, 'rewindandplay');}
        else {FLVcallFlashObj(FLVid, 'poster');}
    }
    else //if more than one : poster all until all ready -> play first according to autoplaysetting
    {
        FLVcallFlashObj(FLVid, 'poster'); 
        if (FLVcountReady == FLVregisterArr.length && FLVautoPlay) {FLVcallFlashObj(FLVregisterArr[0], 'rewindandplay');}
    }
}



//--- click callback   ---
function FLVclickCallback(FLVid) 
{
   FLVcallFlashObj(FLVid, 'rewindandplay')
   FLVposterAllExcept(FLVid)
}

//--- enlarge callback   ---
function FLVclickCallbackEnlarge(FLVid, imageid, moview, movieh) 
{
   var url = 'videoviewer.asp?id=' + imageid + '&w=' + moview + '&h=' + movieh
   var moviewin = window.open(url,'video','resizable=no,scrollbars=no,status=no,left=100,top=100,width=' + (moview+50) + ',height=' + (movieh + 90))
}

//--- start next movie ---
function FLVstartNextMovie(lastflvidentifier)
{
    var lastix = -1;
    for(var i=0; i< FLVregisterArr.length;i++) {if(lastflvidentifier == FLVregisterArr[i]) {lastix = i;}}
    if (lastix != -1)
    {
        var nextix = lastix + 1
        if (nextix >= FLVregisterArr.length) {nextix = 0}
        FLVcallFlashObj(FLVregisterArr[nextix], 'rewindandplay')
        FLVposterAllExcept(FLVregisterArr[nextix])
    }
}

//--- everybody else go poster ---
function FLVposterAllExcept(exceptFLVid)
{
   for(var i=0; i< FLVregisterArr.length;i++)
    {
        if(FLVregisterArr[i] != exceptFLVid) {FLVcallFlashObj(FLVregisterArr[i], 'poster')}
    } 
}

//--- call flashobject by name ... with commands registered with externalinterface in the swf
function FLVcallFlashObj(FLVid, action)
{
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    var FLVobj = (isIE) ? window[FLVid] : document[FLVid];
    switch (action)
    {
        case 'play': FLVobj.playVideo();break;
        case 'rewindandplay': FLVobj.rewindAndPlayVideo();break;
        case 'stop': FLVobj.stopVideo();break;
        case 'poster': FLVobj.goPoster();break;
        case 'requestcurrenttime' : FLVobj.requestForCurrentTime();break;
        default:
    }
}
