    function PrintVideoList(aVideos,strVideoTemplate,$ul){
        var strDate="";
        var strTitle;
        for (i=0;i<aVideos.length;i++){
            if (aVideos[i].vidDate)
                strDate=new Date(aVideos[i].vidDate.substring(0,4), aVideos[i].vidDate.substring(5,7) - 1, aVideos[i].vidDate.substring(8,10)).format("longDate");
            else
                strDate="";
            if (aVideos[i].vidTitle)
                strTitle=aVideos[i].vidTitle;
            else
                strTitle="Video "+ (i+1);
            if (bYouTube){
                if (aVideos[i].vidYouTubeId)
                    $ul.append(sprintf(strVideoTemplate,
                        aVideos[i].vidYouTubeId,
                        "http://i3.ytimg.com/vi/" + aVideos[i].vidYouTubeId + "/default.jpg","\n",
                        strTitle,strDate
                    ));                
            }
            else if (bViddler){
                if (aVideos[i].vidViddlerId)
                    $ul.append(sprintf(strVideoTemplate,
                        aVideos[i].vidViddlerId,
                        "http://cdn-thumbs.viddler.com/thumbnail_1_" + aVideos[i].vidViddlerId + ".jpg","\n",
                        strTitle,strDate
                    ));
            }
            else
                if (aVideos[i].vidLocalURL)
                    $ul.append(sprintf(strVideoTemplate,
                        window.location.protocol+'//'+ window.location.host+aVideos[i].vidLocalURL,
                        "/images/icon_video.png","\n",
                        strTitle,strDate
                    ));
        }
    }

    function ShowVideoPlayer(i){
        strInitVideoId=i;
        if (spkCurrent.spkFirstName && spkCurrent.spkLastName)
            strSpkFullName= spkCurrent.spkFirstName + ' ' + spkCurrent.spkLastName;
        else if (spkCurrent.spkFirstName && !spkCurrent.spkLastName)
            strSpkFullName=spkCurrent.spkFirstName;
        else if (!spkCurrent.spkFirstName && spkCurrent.spkLastName)
            strSpkFullName=spkCurrent.spkLastName;

        $dlg_VideoPlayer.dialog('option', 'width', 800);
        $dlg_VideoPlayer.dialog('option', 'title', strSpkFullName + ' Videos');
        /*$dlg_VideoPlayer.dialog('option', 'buttons', {
            "Full Speaker Profile": function() {
                        window.location=
                            sprintf('%1$s//%2$s%3$s',
                            window.location.protocol,
                            window.location.host,
                            spkCurrent.spkPageURL
                        );
                    }
        });*/
        $.post(
            "/php/loadvid.php",
            { spkId: spkCurrent.spkId},
            function(vidCurrent) {
                $('#ul_vid_List').html('');
                if(vidCurrent){
                     PrintVideoList(vidCurrent,str_li_Video_Template,$('#ul_vid_List'));

                    if ($('#ul_vid_List').html())
                        $dlg_VideoPlayer.dialog('open');                    
                    else
                        alert("There are no videos available for " +strSpkFullName);
                }
                else
                    alert("There are no videos available for " +strSpkFullName);
            },
            "json"
        );                
    }

    $(function() {
        str_YouTubeVideoTemplate=$('#div_YouTubeVideo').html();
        $('#div_YouTubeVideo').remove();
        str_ViddlerVideoTemplate=$('#div_ViddlerVideo').html();
        $('#div_ViddlerVideo').remove();
        str_LocalVideoTemplate=$('#div_LocalVideo').html();
        $('#div_LocalVideo').remove();
        str_li_Video_Template=$('#ul_vid_List').html();
        $('#ul_vid_List').html("");
        $dlg_VideoPlayer = $('#div_VideoPlayer').dialog({
            bgiframe: true,
            autoOpen: false,
            modal: true,
            open: function(event, ui) {
                    if (bYouTube)
                        strVideoEmbedTemplate=str_YouTubeVideoTemplate;
                    else if (bViddler)
                        strVideoEmbedTemplate=str_ViddlerVideoTemplate;
                    else
                        strVideoEmbedTemplate=str_LocalVideoTemplate;
                $("a.a_LoadVideo").click(function() {
                    $("#div_Video").html(sprintf(strVideoEmbedTemplate,
                        $(this).attr("id").replace(/a_vidId_/,"")
                    ));
                    $('#ul_vid_List li').each(function(){
                        $(this).removeAttr('style');
                    });
                    $(this).parent().attr('style','background-color: #D1DC8E');
                });
                if(!strInitVideoId)
                    strInitVideoId= $('#ul_vid_List:first-child a').attr("id");
                $('#ul_vid_List a').each(function(){
                    if (strInitVideoId==$(this).attr("id")){
                        $("#div_Video").html(sprintf(strVideoEmbedTemplate,
                            $(this).attr("id").replace(/a_vidId_/,"")
                        ));
                        $(this).parent().attr('style','background-color: #D1DC8E');
                        return false;
                    }
                });
            },
            close: function(event, ui) {
                $("#div_Video").html("");
            }
        });        
    });        
    
    var $dlg_VideoPlayer;
    var strVideoEmbedTemplate;
    var str_YouTubeVideoTemplate;
    var str_LocalVideoTemplate;
    var str_li_Video_Template;
    var bYouTube=true;
    var bViddler=true;
    var imgYouTube = $("<img src='http://s.ytimg.com/yt/img/master-vfl141814.png' onerror='bYouTube=false;' style='display:none;' />");
    var imgViddler = $("<img src='http://cdn-static-00.viddler.com/css/images/viddler.gif' onerror='bViddler=false;' style='display:none;' />");
    var iTimeoutMS = 2000; //timeout at 2 seconds    setTimeout(generateVideoLinks, iTimeoutMS);
    var strInitVideoId;