
function enableVideos () {

    function getFlashHTML (flashLink) {
        var youtubeId = flashLink.getAttribute ("youtube_id");
        if (youtubeId) {
            return String.format ('<object width="768" height="480"><param name="movie" value="http://www.youtube.com/v/{0}&hl=en&fs=1&hd=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  id="video_player_embed" src="http://www.youtube.com/v/{0}&hl=en&fs=1&hd=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="768" height="480"></embed></object>',youtubeId);
        }
        var flashFile = flashLink.getAttribute ("for");
        return String.format ('<OBJECT  CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="768" HEIGHT="596" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=7,0,0,0">\
        <PARAM NAME=movie VALUE="/assets/ec/tour/{0}">\
        <PARAM NAME=play VALUE=true>\
        <PARAM NAME=loop VALUE=false>\
        <PARAM NAME=wmode VALUE=transparent>\
        <PARAM NAME=quality VALUE=low>\
        <EMBED SRC="/assets/ec/tour/{0}" id="video_player_embed" WIDTH=768 HEIGHT=596 quality=low loop=false wmode=transparent TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">\
        </EMBED>\
        </OBJECT>', flashFile);
    };

    var dlg = new ModalDialog();
    var flashModal = $("#flash-modal");
    $("a.flash-demo-link").click (function () {
        flashModal.css (this.getAttribute ("youtube_id") ? {"height": "520px", "width": "770px"} : {"height": "650px", "width": "800px"});
        dlg.show (flashModal);
        var flashElt = $("#flash-content")[0];
        flashElt.innerHTML = '<img src="/img/ec/tour/loading.gif" />';
        flashElt.innerHTML = getFlashHTML (this);
        try {
            pageTracker._trackPageview ("/pages/ec/tour/" + this.getAttribute ("for"));
        } catch (e) {
        }
    });
    $("#close-modal").click (function () { 
        if ($.browser.msie) {
            try { var p = document.getElementById("video_player_embed"); p.sendEvent("STOP"); p.controls.stop();} catch (e) {};
        }
        dlg.hide(); 
    });
};


function createVideoWidgets (){
    var dlg = new ModalDialog();
    var modal = $("#video-modal-div");
    $(".vid-wrap").each (function () {
        var html = '<div title="Click to see video" style="opacity:0.4;filter:alpha(opacity=40);width: 120px; height: 75px; text-align: center;background: #ccc url(/img/ec/doc/import-cats-vid-tn.jpg) no-repeat;"></div><img title="Click to see video" border="0" src="/img/video-icon.png" style="position: absolute;top: 10px; left: 30px;z-index:1;"  /></div>';
        this.innerHTML = html;
        var videoTitle = this.title;
        var youtubeId = this.getAttribute ("youtube_id");
        var flashHTML = String.format ('<object width="768" height="480"><param name="movie" value="http://www.youtube.com/v/{0}&hl=en&fs=1&hd=1&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed  id="video_player_embed" src="http://www.youtube.com/v/{0}&hl=en&fs=1&hd=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="768" height="480"></embed></object>',youtubeId);
        $(this).click (function() {
            modal.css ({"height": "520px", "width": "770px"});
            var flashElt = $("#flash-content")[0];
            flashElt.innerHTML = '<img src="/img/ec/tour/loading.gif" />';
            flashElt.innerHTML = flashHTML;
            dlg.show (modal);
            try {
                pageTracker._trackPageview ("/doc/videos/" + videoTitle);
            } catch (e) {
            }
        });
    });
    $("#video-modal-close").live ("click", function () { 
        if ($.browser.msie) {
            try { var p = document.getElementById("video_player_embed"); p.sendEvent("STOP"); p.controls.stop();} catch (e) {};
        }
        dlg.hide(); 
    });
}
