/*
 * 
 * YCodaFlickr plugin 2.0
 * $Date:2008-05-18 12:40:29 +0200 (dom, 18 mag 2008) $
 * $Rev:83 $
 * @requires jQuery v1.2.3
 * @requires YCodaSlider v2.0
 * @requires Lazy YCodaSlider plugin 2.0
 * @requires Gallery YCodaSlider plugin 2.0
 * 
 * @optional Easing v1.3
 * 
 * Copyright (c) 2008 Massimiliano Balestrieri
 * Examples and docs at: http://maxb.net/blog/
 * Licensed GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 * 
 */
YCodaSlider.Flickr = {
    init     : function(options, callback)
    {
        options = jQuery.extend({
                 proxy   :    "../exe/feed.php",
                 http_proxy : false,
                 height  :    "470",
                 lazy    :    true
              }, options);
        
        return this.each(
            function(nr)
            {
                var that = this;
                var panel = jQuery(that);
                var url = jQuery("a",this).get(0);
                var data = 'url=' + url;
                if(options.http_proxy)
                    data += '&proxy=' + options.http_proxy;
                //scarica il feed
                jQuery.ajax({
                    dataType : 'xml',
                    url      : options.proxy,
                    data     : data,
                    success: function(rss){
                        var jImages = jQuery(rss).find("entry>link[@type=image/jpeg]");
                        jImages.each(function(nr){
                            var href = jQuery(this).attr("href");
                            var attr = "original";
                            var current = location.hash ? (location.hash.slice(1) - 1) : 0;
                            if(!options.lazy || typeof(callback) !== "function")
                               attr = "src";
                            if(nr === current) 
                               attr = "src";
                            panel.append('<img '+attr+'='+ href +' style="height:'+options.height+'px" alt="" />');
                        });
                        
                        jQuery("a",that).remove();
                        if(callback)
                           callback();
                    }
                 });     
        
            }
        );
    }
};
jQuery.fn.ycodaflickr = YCodaSlider.Flickr.init;