function YouTubeCallback(p_Json, p_Div) {
    if (p_Div == null) return;
    if (typeof p_Div == "string") p_Div = document.getElementById(p_Div);
    if (p_Div == null) return;
    var l_objPlayerOrThumb = p_Div.firstChild;
    if (l_objPlayerOrThumb != null && l_objPlayerOrThumb.nodeType != 1) {
        l_objPlayerOrThumb = NextSiblingElement(l_objPlayerOrThumb);
    }
    if (l_objPlayerOrThumb == null) return;
    var l_objTitle = NextSiblingElement(l_objPlayerOrThumb);
    if (l_objTitle == null) return;
    var l_objStats = NextSiblingElement(l_objTitle);
    if (l_objStats == null) return;
    var l_Entry = p_Json.entry;
    if (l_Entry == null) l_Entry = p_Json.feed.entry[0];
    if (l_Entry == null) return;
    if (l_Entry.media$group == null) return;
    var l_strUploaded = l_Entry.media$group.yt$uploaded != null ? l_Entry.media$group.yt$uploaded.$t : null;
    var l_dtUploaded = new Date(l_strUploaded.replace(/[a-z]/gi, ' ').replace(/\.\d\d\d\s?$/gi, '').replace(/-/gi, '/'));
    var l_strTitle = NodeText(l_objTitle);
    if (l_strTitle == null || l_strTitle.length == 0) {
        l_strTitle = l_Entry.media$group.media$title != null ? l_Entry.media$group.media$title.$t : null;
    }
    var l_strViewcount = l_Entry.yt$statistics != null ? l_Entry.yt$statistics.viewCount : null;
    l_objTitle.firstChild.nodeValue = l_strTitle;
    l_objStats.firstChild.nodeValue = l_strViewcount + ' keer bekeken - ' + formatDate(l_dtUploaded, 'dd.MM.yyyy');
}

function NodeText(p_objNode) {
    return p_objNode.firstChild == null ? null : p_objNode.firstChild.nodeValue;
}

function onYouTubePlayerReady(playerId) {
    playerId = unescape(playerId); //In Safari, the _ in an id is replaced with %5F
    eval(playerId + "_onYouTubePlayerReady()");
}

function TogglePlay(playerId, p_strUrl, p_blnAllowPause) {
    if (p_blnAllowPause == null) p_blnAllowPause = true;
    var l_objPlayer = document.getElementById(playerId);
    if (l_objPlayer == null || l_objPlayer.getPlayerState == null) {
        if (p_strUrl != null) {
            location.href = p_strUrl;
        } else {
            return;
        }
    }
    var l_State = l_objPlayer.getPlayerState();
    //alert(l_objPlayer.getVideoEmbedCode());
    //-1 unstarted, 0 ended, 1 playing, 2 paused, 3 buffering, 5 cued
    if (l_State == 0 && p_strUrl != null) {
        location.href = p_strUrl;
    } else if (l_State != 1) {
        l_objPlayer.playVideo();
    } else if (p_blnAllowPause) {
        l_objPlayer.stopVideo();
    } else if (p_strUrl != null) {
        location.href = p_strUrl;
    }
}

function HidePreview(p_objElement, p_intOpacity) {
    if (p_intOpacity == null) p_intOpacity = 90;
    p_objElement.style.opacity = p_intOpacity / 100;
    p_objElement.style.filter = 'alpha(opacity=' + p_intOpacity + ')';
    if (p_intOpacity <= 0) {
    } else {
    window.setTimeout(function() { HidePreview(p_objElement, p_intOpacity - 10); }, 50);
    }
}
