jQuery.fn.photogallery = function(remote_address)
{
    if (!remote_address)
    {
        return;
    }
    
    var id = jQuery(this).attr('id');
    
    
    
    // Force the ID for the element
    if (!id)
    {
        var date = new Date();
        jQuery(this).attr('id', date.getTime());
        var id = jQuery(this).attr('id');
    }
    
    jQuery(this).find('div.org_openpsa_qbpager_pages a').click(function()
    {
        // Store the link for a while
        var link = jQuery(this).attr('href');
        
        // Set to point to the target
        jQuery(this).attr('href', '#' + id);
        
        var pages = link.match(/org_openpsa_qbpager_org_routamc_photostream_photo_page=([0-9]+)/);
        
        if (!pages[1])
        {
            return;
        }
        
        page = pages[1];
        
        // alert(remote_address + '?ajax=true&org_openpsa_qbpager_org_routamc_photostream_photo_page=' + page);
        
        jQuery('#' + id)
            .addClass('loading')
            .load(
                remote_address + '?ajax=true&org_openpsa_qbpager_org_routamc_photostream_photo_page=' + page,
                {},
                function(data)
                {
                    jQuery('#' + id)
                        .removeClass('loading')
                        .photogallery(remote_address);
                }
            );
        
        return false;
    });
}
