/*
 * 
 * YCodaFrame plugin 2.0
 * $Date$
 * $Rev$
 * @requires jQuery v1.2.3
 * @requires YCodaSlider v2.0
 * @optional Lazy 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.Frame = {
    init     : function(options, callback)
    {
        options = jQuery.extend({
           height  : 438,
           width   : 650,
           keypress: true,
           lazy    : true
              }, options);
              
        var cnt = this.size();
        return this.each(
            function(nr)
            {
                var that = this;
                var jLinks = jQuery('a', that);
                var size = jLinks.size();
                if(size > 0 && options.height){
                    jQuery("a", this).wrap('<div class="yslider-panelwrapper">');
                    //jQuery(".yslider-panelwrapper", this).wrap('<div class="yslider-panel">');
                    jQuery(".yslider-panelwrapper a").each(function(nr){
                      jQuery(this).parent().attr("title", jQuery(this).text());//sul panel
                    });
                    jQuery("a", this).each(function(nr){
                      var href = jQuery(this).attr("href");//Lazy si occupa di visualizzare
                      var attr = "original";
                      var current = YCodaSlider.Frame.current(size);
                      //console.log("Frame :" + current + " " + size);
                      
                      if(nr == current) 
                         attr = "src";
                      if(!options.lazy || typeof(callback) !== "function")
                         attr = "src";
                                
                      
                      jQuery(this).wrap('<iframe id="GB_frame" '+attr+'="'+href+'" id="GB_frame" style="width:'+ options.width + ';height:'+ options.height + ';">');
                      var jIframe = jQuery(this).parent();
                      jIframe.empty();
                      if(nr === current){
                        if(options.lazy){
                            if(!jIframe.attr("src"))
                              jIframe.attr("src",jIframe.attr("original"));
                            else
                              jIframe.show();
                        }
                      }
                      if(callback)
                           callback();
                    });
                }
            }
        );
    },
    current  : function(cnt){
        return location.hash &&  (location.hash.slice(1) - 1) <= cnt 
               ? (location.hash.slice(1) - 1)  
               : 0;
    }
};
jQuery.fn.ycodaframe = YCodaSlider.Frame.init;