(function($){
  Drupal.behaviors.MyBehavior = {
    attach: function(context) {
            
      // Add target="_blank" to external links.
      $("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])")
      .addClass("external")
      .attr("target","_blank");
      
      // Hover effect on video images
      $(".view-id-videos .view-content > div").hover(function() {
        $(this).find("img").addClass("hover");
        $(this).find(".play").addClass("hover");
      });
      $(".view-id-videos .view-content > div").mouseleave(function() {
        $(this).find("img").removeClass("hover");
        $(this).find(".play").removeClass("hover");
        
      });
      
      // Slideshow
//      $('.field-slideshow-controls .prev').hover(function() {
//        $(this).addClass('hover');
//      });      
//      $('.field-slideshow-controls .prev').mouseout(function() {
//        $(this).removeClass('hover');
//      });
//      $('.field-slideshow-controls .next').hover(function() {
//        $(this).addClass('hover');
//      });      
//      $('.field-slideshow-controls .next').mouseout(function() {
//        $(this).removeClass('hover');
//      });
      
      $('.field-slideshow .field-slideshow-slide img').bind('click', function() {
        $(this).parent().parent().parent().find('.field-slideshow-controls .next').trigger('click');
      });
      
      
      // Move caption inside div tag for images
      // THIS IS A REALLY BAD SOLUTION AND DOES NOT WORK AT ALL TIMES
      // FIX IT (html)!
//      $(".field-name-field-image-caption").each(function() {
//        $(this).appendTo($(this).parent().find(".image-with-caption"));
//      });      
      
    },
    detach: function(context) {
     //code to run when elements are removed
    }
  }
})(jQuery)
;

