﻿
//--- 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) {
    if (FLVautoPlay) { FLVstartNextMovie(FLVid);}
    else { FLVcallFlashObj(FLVid, "poster") }
}

//--- ready callback: start if first - else go poster ---

var FLVcountReady = 0

var lastflvcalledid = '' //if an action has been issued to a specific flvid -> ignore flv in ready callback (avoid stopping play is issued)

function FLVreadyCallback(FLVid)
{
    if (FLVid == lastflvcalledid) { return; }  //ignore readycallback for last flv called (to avoid overruling action called before ready)
    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');}
    }
}

//utility for popins to show/hide flvs in the page to avoid bleeding
function FLVshowall() {
    for (var i = 0; i < FLVregisterArr.length; i++) {
        document.getElementById(FLVregisterArr[i]).style.visibility = 'visible';
    }
}
//utility for popins to show/hide flvs in the page to avoid bleeding
function FLVhideall() {
    for (var i = 0; i < FLVregisterArr.length; i++) {
        document.getElementById(FLVregisterArr[i]).style.visibility = 'hidden'; 
    }
}

//--- click callback   ---
function FLVclickCallback(FLVid) 
{
   FLVcallFlashObj(FLVid, 'rewindandplay')
   FLVposterAllExcept(FLVid)
}

function FLVenlargeCallback(w, h, popmodus, enlagemedialink) {
    //NOTE: Safari on PC: cannot use window.open when calling back from flash-movie ... so this wont work
    if (popmodus == 'POPIN') {
        popinmanager.showpopin(enlagemedialink, -1, -1, w, h)
    }
    else {
        opensimplepopup(enlagemedialink, w, h)
    }
    return true;
}

//--- 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))
}

//--- surroundings dont know the exact FLVid -> try to find one starting with FLV + itemid (the rest of the id is a random number)
function FLVtryStartMovieFromItemId(itemid) {
    FLVtryCallFlashObjFromItemId(itemid, 'play')
}

function FLVtryCallFlashObjFromItemId(itemid, action) {
    for (var i = 0; i < FLVregisterArr.length; i++) {
        var id = FLVregisterArr[i];
        var lookforid = 'FLV' + itemid;
        if (id.substring(0, lookforid.length) == lookforid) {
            FLVcallFlashObj(FLVregisterArr[i], action);
            if (document.getElementById(FLVregisterArr[i]).focus) { document.getElementById(FLVregisterArr[i]).focus(); }  //set focus to catch keyevents
            return;
        }
    }
}


//--- 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')}
    }
}

//--- everybody go poster ---
function FLVposterAll() {for (var i = 0; i < FLVregisterArr.length; i++) { FLVcallFlashObj(FLVregisterArr[i], 'poster') } }

function FLVstopAll() { for (var i = 0; i < FLVregisterArr.length; i++) { FLVcallFlashObj(FLVregisterArr[i], 'stop') } }

//--- 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];
    lastflvcalledid = FLVid
    var FLVobj = document.getElementById(FLVid);
    switch (action)
    {
        case 'play': if (FLVobj.playVideo) { FLVobj.playVideo(); } break;
        case 'playToggle': if (FLVobj.playVideo) { FLVobj.playToggle(); } break;
        case 'rewindandplay': if (FLVobj.rewindAndPlayVideo) { FLVobj.rewindAndPlayVideo();} break;
        case 'stop': if (FLVobj.stopVideo) { FLVobj.stopVideo(); } break;
        case 'poster': if (FLVobj.goPoster) { FLVobj.goPoster();  } break;
        case 'requestcurrenttime': if (FLVobj.requestForCurrentTime) { FLVobj.requestForCurrentTime(); } break;
        default:
    }

}
