jQuery(document).ready(function() {

    jQuery('.fancybox_content a.sourceLink').each(function() {
        if (jQuery(this).attr('href').length == 0)
            jQuery(this).remove();
    });

    jQuery('.fancybox_content .fancybox_attach').each(function() {
        var pop = jQuery(this).parent().parent().parent().find('.fancybox_pop');
        if (hasContent(pop.html()))
            jQuery(this).attr('href', '#' + pop[0].id);
        else
        {
            if (jQuery(this).parent().hasClass('sf_readMore'))
                jQuery(this).remove();
        }
    });
    
    jQuery('.fancybox_attach').fancybox({
		'hideOnContentClick': true
	});

});

function hasContent(str)
{
    str = str.replace(/&nbsp;/g, '');
    return str.match(/\w/g) != null;
}

