/*!
 * jQuery customExpose Plugin
 * plugin extends http://flowplayer.org/tools/expose.html
 * Version: 1.0 (13-JUN-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: jQuery v1.3.1 or later
 *
 */
(function($){ //jQuery.noConflict()compliant 
   $.fn.customExpose = function(options) { 
   
      // build main options before element iteration
      //----------------------------------------------------------------------
      var s = $.extend({}, $.fn.customExpose.defaults, options);
      
      // loop through each tab and enable analytics 
      return this.each(function() 
      {
        
         var _obj = $(this);
           
         _obj.expose({ 
            //api: true,
            loadSpeed: s.loadSpeed,
            closeSpeed: s.closeSpeed,
            color: s.color, 
            //color: null, 
            opacity: s.opacity,
          
            onBeforeLoad: function(){
               
               _el = this.getExposed();

               //recupero posizione elemento
               _elPosition = null;
               _elPosition = _el.position();        

               var scrollTop = $('#wrap').scrollTop();
                                          
               _el.find(s.hideBoxClass).hide();
               //_el.find('.b-hover').show(); 
               _el.find(s.showBoxClass).show();       
               
               
               //recupero dimensione titlolo+testo
               //var textHeight = _el.find('.b-gutter').height();
               var textHeight = _el.find('.b-gutter h2').height() + _el.find('.b-gutter p').height();
               
               textHeight = (textHeight + 30) + 'px';
               //jQuery(obj).offset().top
               _top = (_el.offset().top - 15 + scrollTop) + "px";
               _left = (_el.offset().left - 15) + "px";   
                                   

               _el.css({   
                  position: 'absolute',
                  width: '22.375em',
                  height: textHeight,//'6em',
                  top:  _top,
                  left: _left,
                  border: '1px solid #505141',
                  zIndex: '9999'                             
               });   

            },
             
            onBeforeClose: function(){
               _el = this.getExposed();
               
               _el.find(s.hideBoxClass).show();  
               _el.find(s.showBoxClass).hide(); 

               _el.css({       
                  position: 'relative',
                  width: '20.625em',
                  height: '3.437em',
                  top: 'auto',
                  left: 'auto',
                  border: 'none',
                  zIndex: '9990'
               }); 
            }
         });  //end init expose
         
         _obj.hover(
            function(){
               jQuery(this).expose().load();   
            },
            function(){  
               jQuery(this).expose().close();  
            }
         );

      }); 
   };
   
   $.fn.customExpose.defaults = {
         hideBoxClass : '.hide-hover',
         showBoxClass : '.show-hover',
         color: '#000',
         opacity: 0.4,
         loadSpeed: '0',
         closeSpeed: '0'
    };
    
})(jQuery);