/**
 * Theme-specific funtions.
 */
var PlanAndDrawingsTheme = {
  /**
   * Look for suitable blocks, and make the entire body a link.
   * Also add hover state to these blocks.
   */
  activateBlocks : function() {
    // Activate each block.
    $('main').select('.image-text-block').each(function(block) {
      // Only do so if we have a button though.
      var button = block.down('.block-buttons a.button');
      
      // Which we have here.
      if(button) {
        var blockBody = block.down('.block-body');
        
        // We copy the button URL...
        var buttonUrl = button.href;
        // ...to the body's click handler.
        blockBody.observe('click', function() {
          window.open(buttonUrl);
        });
        
        // Indicate that the body is clickable.
        blockBody.setStyle({cursor: 'pointer'});
        
        // Add hover state, both in...
        block.observe('mouseover', function(e) {          
          block.addClassName('block-hover');
        });
        // ...and out.
        block.observe('mouseout', function(e) {
          block.removeClassName('block-hover');
        });
      }
    });
  }  
}

// Activate blocks on window load.
Event.observe(window, 'load', function() {
  PlanAndDrawingsTheme.activateBlocks();
});

