   $(function()
            {
                // This script checks the page for any links to a flickr
                // users tags page, for example
                // http://flickr.com/photos/user/tags/tagname/
                // it then fetches the users photos with those tags
                // and puts thumbnails on the page, and 'lightboxes' them
            
                // Replace this with your own api key, which you can get from
                // http://www.flickr.com/services/api/keys/apply/
                var api_key    = "53307cf845cf001ff8dc1bc7c117d8af";
                
                // Set this to the maximum number of photos to show, 
                // -1 for no limit
                var num_photos = 6;
                
                var api_url    = "http://api.flickr.com/services/rest/?method=";               
                var json       = "&format=json&jsoncallback=?";

                // Grab links that point to flickr
                $("a[href^=http://www.flickr.com/],a[href^=http://flickr.com/]").each(function()
                {
                    var split_url = $(this).attr("href").split("/");
                    var link = this;
                    var tag  = split_url[6];
                   
                    if(split_url.length > 6 && split_url[5] == "tags")
                    {               
                        var gallery = $("<div class='flickr_set' />").insertAfter($(link));
                        
                        // Looks up the user_id from the url to flickr
                        var lookup_url = api_url+"flickr.urls.lookupUser&api_key="
                            + api_key + "&url=" + this + json;
            
                        $.getJSON(lookup_url, function(data)
                        {                           
                            var search_url = api_url+"flickr.photos.search&api_key="+api_key
                                + "&user_id="+data.user.id+"&tags="+tag+json;

                            $.getJSON(search_url, function(data)
                            {  
                                $.each(data.photos.photo, function(i,item) 
                                {
                                    var image_url = "http://farm"+item.farm+".static.flickr.com/"
                                        +item.server+"/"+item.id+"_"+item.secret;
                    
                                     gallery.append($("<a href='"+image_url+".jpg' title='"+item.title+"'>"
                                        +"<img src=\""+image_url+"_s.jpg\" alt=\""+item.title+"\" /></a>")); 
									
									
									
                                    if(num_photos != -1 && (num_photos-1) == i)
                                        return false;
                                });
                                
                                gallery.children("a").lightBox();
                                gallery.append($("<br />")).append(link);
                            });
                        });
                    }
                });
            });   