/**
 * @file
 * JS behaviors to manipulate the blog blocks (on the front page)
 */
// $Id:$

// Encapsulate for jQuery
(function ($) {
	
	// Attach our behavior to the drupal namespace
    Drupal.behaviors.ials_blogblockitems = {
      attach: function(context, settings) {
    	// Call our function
    	  ialsBlogBlockItems.init();
      }
    };
    
    var ialsBlogBlockItems = function(){
        var pub = {};

        
        /**
         * Init function
         */
        pub.init = function() {
          // Remove any problematic binds that date still has on here?
          pub.debug('called ialsBlogBlockItems.init');
          
          // Get all instances of aggregator blocks and then the ul lists in them
          var $blockElem = $(".block-aggregator");
          var $ulElem = $(".content .item-list", $blockElem);
          var $liElems = $("li", $ulElem);
          
          // Add the "read article" div
          $liElems.append('<div class="read-article-lnk">Read Article &raquo;</div>');
          
          // Add the hover listener to the whole element
          $liElems.hover(
            function() {
              $(this).css('cursor','pointer');
              $(".read-article-lnk", $(this)).css('text-decoration', 'underline');
              $("a", $(this)).css('text-decoration', 'underline');
            },
            function() {
              $(this).css('cursor','auto');
              $(".read-article-lnk", $(this)).css('text-decoration', 'none');
              $("a", $(this)).css('text-decoration', 'none');
            }
          );
          
          // Add the click listener to the whole element
          $liElems.click(function() {
            // Get the a tag
            var itemHref = $("a", $(this)).attr('href');
            //window.location = itemHref;
            window.open(itemHref);
            return false;
          });
        };
        
        
        /**
         * Debug wrapper
         */
        pub.debug = function(sMessage, oObject) {
          if (typeof console !== 'undefined' && 'log' in console) {
            console.log(sMessage, oObject);
          }
        };
        
        // Return our namespaced objects and functions
        return pub;
    }();

})(jQuery);
;

