$.expr[':'].swf= function(obj){
    return obj.href.match('^.*\.(swf)$');
};
$.fn.fancyboxSWF = function(){
    return this.each(function(){
    $(this).unbind('click');
    $(this).click(function(){
        $(this).attr('href');
        $(this).append("<div id='popup' style='display:none'><div id='replace'></div></div><a href='#popup' class='fancybox-swf-holder' style='display:none'></a>");
            
        var width = parseInt($(this).css('max-width'));
        var height = parseInt($(this).css('max-height'));
        var wHeight = $(window).height()-60;
        var wWidth = $(window).width()-60;
        var ratio = height/width;
        
        if(height > wHeight){
            width = Math.round(width*(wHeight/height));
            height = wHeight;
        }else if(width > wWidth){
            height = Math.round(height*(wWidth/width));
            width = wWidth;
        }
        
        swfobject.embedSWF($(this).attr('href'),'replace',width,height,'9','','',{wmode:'opaque'});
        
        $(this).find('.fancybox-swf-holder').fancybox({
            'frameHeight':height,
            'frameWidth':width
        });

        $(this).find('.fancybox-swf-holder').click();
        $(this).remove('#popup');
        return false;
    });
});
}