(function ($) {
Drupal.behaviors.hegreCovers = {
  attach: function (context, settings) {
    var box = $("#cover-box");
    
    if (!box.length && typeof Drupal.settings.hegre == 'object') {
      box = $(Drupal.settings.hegre.coverbox);
      $('body').append(box);
    }
    
    $('.field-name-coverl a:not(".hegre-covers-processed")').each( function() {
      var link = $(this);
      
      link.click( function() {
        var image = link.attr('rel');
        var url = link.attr('href');
        var title = link.find('img').attr('title');
        
        //box.find('.title').innerHtml(title);
        var img = box.find('img');
        
        img.attr('src', image).load( function() {
          box.find('.cover-image a').attr('href', url);
          //box.find('.cover-image img').attr('src', image);
          box.show();
          $.colorbox({transition:"elastic",opacity:".7",inline:true, href:"#cover-box", onClosed:function(){ box.hide(); img.attr('src', '').unbind('load'); }});
        });
        
        
        return false;
      })
    }).addClass("hegre-covers-processed");
  },
  detach: function (context, settings) {
  
  }
};

})(jQuery);;
(function ($) {
Drupal.behaviors.hegrePreviewGalleryLinks = {
  attach: function (context, settings) {
    $('.preview-link:not(".hegre-preview-processed")').each( function() {
      var box = $(this);
      var container = box.closest('div.node-grid');      
      box.addClass('js');
      container.find('.content').eq(0).append(box);
      
      container.hover(
        function() {
          box.fadeIn("fast");
        },
        function() {
          box.fadeOut("fast");
        }
      );
      
      
    }).addClass("hegre-preview-processed");
  },
  detach: function (context, settings) {
  
  }
};

})(jQuery);;
(function ($) {
Drupal.behaviors.hegreFeatured = {
  attach: function (context, settings) {
    $("#block-hegre-hegre-latest #hegre-featured:not('.hegre-processed')").each( function() {
      var featured = $(this);
      var meta =$("#featured-meta");
      
      $('#feature-board a').click( function() {
        meta.fadeIn("slow");
        return false;
      });
      
      featured.mouseleave( 
        function() {
          meta.fadeOut("slow");
        }
      );
      
      meta.click( function() {
        meta.fadeOut("slow");
      });
      
    }).addClass('hegre-processed');
    
    $("#featured-models:not('.hegre-processed')").scrollable({ vertical: true, mousewheel: true }).addClass('hegre-processed');
  },
  detach: function (context, settings) {
  
  }
};

})(jQuery);;

