jQuery(document).ready(function($){
    var flowplayerSwf   = 'flowplayer/flowplayer.3.1.4.swf';
    var playerId        = 'colorbox-video-container';
    
    $("a[href*=.flv]").click(function(e) {
        
        $("<div>", {
            id: playerId
        }).appendTo("body");
        
        var target = e.currentTarget;
        
        if( $(target).is("#cboxClose") )
        {
            console.log('is outside');
            return false;
        }
        
        var clip_url = $(this).attr('href');
        
        var player = flowplayer(playerId, flowplayerSwf, {
            wmode: 'window',
            cachebusting: true,
            clip: {
                scaling: "orig",
                url: clip_url, 
                autoPlay: true
            } 
        });
        
        $.fn.colorbox({ 
            inline:     true, 
            href:       '#' + playerId,
            width:      "600",
            height:     "600",
            onCleanup:   function() {
                $('#'+playerId).remove();
            }
        });
        
        return false;
    });

});