Drupal.behaviors.wall89 = function(context) {
  var wallhover   = $('.wall89-hover', context),
      container   = wallhover.children('.container'),
      div_content = container.children('.bubble').children('.content'),
      div_title   = div_content.children('.title'),
      div_text    = div_content.children('.text'),
      div_arrow   = container.children('.arrow'),
      div_cached  = $('#wall89-grid .cached_texts'),
      image_top   = $('#wall89-grid', context)[0].offsetTop,
      image_left  = $('#wall89-grid', context)[0].offsetLeft,
      image_width = $('#wall89-grid', context)[0].offsetWidth,
      boundary_w  = image_left + (image_width / 2),
      bubble_top  = 0,
      refresh_top = function() {
        var wallhover_height = parseInt(wallhover.height()),
            wallhover_top    = image_top + bubble_top - wallhover_height;
      
        wallhover.css('top',  wallhover_top  + 'px');
        
        setTimeout(refresh_top, 500);
      };
  
  $('#wall89-grid a', context).each(function() {
    $(this).hover(
      function() {
        var element = $(this),
            left    = parseInt($(this).css('left')),
            width   = parseInt($(this).css('width')),
            brick   = $(this).attr('class').split('-')[1],
            cached  = div_cached.children('.brick-' + brick);
        
        bubble_top = parseInt($(this).css('top'));
        
        div_title.text(cached.children('.title').text());
        div_text.text(cached.children('.text').text());
        
        var wallhover_left = image_left + left;
        
        if (wallhover_left > boundary_w) {
          wallhover_left = wallhover_left + width - 300;
          
          div_arrow.addClass('arrow-right');
        }
        else {
          div_arrow.addClass('arrow-left');
        }
        
        wallhover.css('left', wallhover_left + 'px');
        wallhover.show();
      },
      function() {
        wallhover.hide(); div_title.text(''); div_text.text('');
        div_arrow.removeClass('arrow-left');
        div_arrow.removeClass('arrow-right');
      }
    );
  });

  wallhover.bind('mouseenter', function() { $(this).hide; } );
  refresh_top();
}
