$().ready( function () {
    readyEmbedVideos();
});

function readyEmbedVideos() {
    hideVideos();
    $('a.embed_video').click( toggleVideo );
}

function getFlashObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    } else {
        return document.getElementById(movieName);
    }
}
function hideVideos() {
    $('div.embed_video:visible').each( function () {
        var $this = $(this);
        $this.hide();
        if ($.browser.msie) {
    /* Can't get stop to work for some reason...
            document.getElementById('flash_' + $this.attr('flash')).SetVariable("player:jsStop", "");
            */
        }
    });
}

function toggleVideo() {
    var id = $(this).attr('flash');
    var $video = $('#embed_' + id );
    var visible = $video.is(':visible');

    hideVideos();
    if (!visible) {
        $video.show();
        var uri = 'http://www.inficon.com/flash.html?'+ encodeURI($video.attr('flash_args'));
        $video.find('div').html( '<iframe src="' + uri +'" frameborder="0" border="0" cellspacing="0"></iframe>' );
    }
    else {
        $video.find('div').html('');
    }

    return false;
}

