(function($) {

  Drupal.behaviors.marqueeLinks = {
    attach: function(context, setting) {
      $('#imagewks_marquee-1 li.marquee-frame').click(function() {
        var link = $(this).find('a.marquee-study-link');
        if (link.length > 0) {
          window.location = link.attr('href');
        }
      });
    }
  }

  Drupal.imagewks = Drupal.imagewks || {
    marqueePreviewFormatter: function(index, panel) {
      var nav = panel.find('.navigation-preview');
      var img = nav.find('.preview-image');
      var body = nav.find('.preview-summary');
      nav.hover(
        function() {
          $(this).animate({ width: '100px', marginRight: '2px' }, 250, 'linear');
          img.animate({ width:'100px'}, 250, 'linear');
          body.slideDown('fast');
        },
        function() {
          body.hide('fast');
          img.animate({ width:'56px'}, 'fast');
          $(this).animate({ width: '56px', marginRight: '24px'}, 'fast');
        });
      return nav;
    }
  }

}(jQuery));;

(function ($) {
  Drupal.Panels = {};

  Drupal.Panels.autoAttach = function() {
    if ($.browser.msie) {
      // If IE, attach a hover event so we can see our admin links.
      $("div.panel-pane").hover(
        function() {
          $('div.panel-hide', this).addClass("panel-hide-hover"); return true;
        },
        function() {
          $('div.panel-hide', this).removeClass("panel-hide-hover"); return true;
        }
      );
      $("div.admin-links").hover(
        function() {
          $(this).addClass("admin-links-hover"); return true;
        },
        function(){
          $(this).removeClass("admin-links-hover"); return true;
        }
      );
    }
  };

  $(Drupal.Panels.autoAttach);
})(jQuery);
;
/**
 * @file marquee_view.js
 *  Define Drupal JS behaviors that creates the slider elements.
 */

(function($) {
  
  /**
   * Drupal behavior to turn all Views generated marquees into sliders.
   *  Works by searching for marquee settings keyed by view name and
   *  applying those settings to a HTML element with that ID.
   *  
   *  This way we can have multiple sliders from different views on the
   *  same page.
   */
  Drupal.behaviors.marqueeViewSlider = {
    attach: function (context, settings) {
      if (!settings.marqueeView) {
        return;
      }
      
      // Ensure that all marquee frames are visible, and attach slider
      for (var key in settings.marqueeView) {
        var slider = $("#" + key);
        if (slider.children('li.marquee-frame').show().length > 1) {
          var marquee = new Drupal.marquee(slider, settings.marqueeView[key]);
          marquee.init();
        }
      }
    }
  };
  
  /**
   * Constructor and prototype for building our custom slider wrappers
   *  Also manage our custom settings and configurations.
   */
  Drupal.marquee = Drupal.marquee || function(slider, settings) {
    // Pass along behavior settings to the slider controls
	this.slider = slider;
	this.arrowControls = settings.arrowControls;
	this.navigationFormatter = settings.navigationFormatter;
	
	this.props = settings.properties;
    this.props.hashTags = false;
	
    // Determine what FX are valid and should be stored for this slider. 
    this.fx = {};
    if (settings.FX !== undefined) {
      for (var selector in settings.FX) {
        // Only add FX that are actually used.
        if (slider.find(selector).length > 0) {
          if (settings.customFX[selector]) {
        	if (!this.fx.inFx) {
        	  this.fx.inFx = {};
        	  this.fx.outFx = {};
        	}    	 
            this.processCustomFX(selector, settings.FX[selector], this.fx);
          }
          else {
        	this.fx[selector] = settings.FX[selector];
          }
        }
      }
    }
  }

  /**
   * Initialization function, can't be called in constructor
   *  due to a required reference to the object instance.
   */
  Drupal.marquee.prototype.init = function() {
    this.props.onInitialized = $.proxy(this, 'onInitialized');
    this.slider.anythingSlider(this.props);
    
    // Check if there are any FX settings in effect, only only add if there are.
    if (!$.isEmptyObject(this.fx)) {
      this.slider.anythingSliderFx(this.fx);
    }
  }
  
  /**
   * Called when the Anything Slider is properly initialized.
   */
  Drupal.marquee.prototype.onInitialized = function(event, slider) {
	var marquee = this;	// save the marquee wrapper for accessibility.
	
	// if we have assigned a special navigation callback, let's rebuild the navigation controls.
    if (this.navigationFormatter) {
      var index = 0;
      var formatter = eval(marquee.navigationFormatter);
	  var panel = slider.$el.children('li:not(.cloned)').first();
      slider.$controls.find('li a').each(function() {
        $(this).empty();
        $(this).append(formatter(index, panel));
        $(this).hover(
          function() { $(this).addClass('nav-hover'); },
          function() { $(this).removeClass('nav-hover'); }
        );
        
        ++index;
        panel = panel.next(':not(.cloned)');
      });
    }
    // Clean-up whether or not we use them, at this point they don't belong in the panels.
    slider.$el.find('.navigation-preview').empty().detach();
    
    // Add arrow controls around the navigation thumbnails.
    if (this.arrowControls) {
      var prev = $('<a class="prev" href="#">previous</a>').click(function() { slider.goBack(); return false; })
      var next = $('<a class="next" href="#">next</a>').click(function() { slider.goForward(); return false; })
      
      slider.$controls.prepend(prev);
      slider.$controls.append(next);
      prev.wrap('<ul><li class="prev-arrow-wrapper">');
      next.wrap('<ul><li class="next-arrow-wrapper">');
    }
  }

  // Allow some variable replacement for custom FX, only supports 1 replacement for now. 
  Drupal.marquee.prototype.processCustomFX = function(selector, fx) {
    var element = this.slider.find(selector);
    var sliderWidth = this.slider.width();
    var sliderHeight = this.slider.height();
    var elWidth = element.width();
    var elHeight = element.height();
    var elTop = element.css('top');
    var elLeft = element.css('left');
   
    if (!elTop || elTop == "auto")   elTop = 0;
    if (!elLeft || elLeft == "auto") elLeft = 0;
    
	var add = { duration: fx[2], easing: fx[3] };
	
	var match, regexp = /\[([^\]]*)\]/;
	var type, types = ['inFx', 'outFx'];
	while (type = types.pop()) {
	  this.fx[type][selector] = fx[0][type];
      for (var i in this.fx[type][selector]) {
    	var val = this.fx[type][selector][i];
        if (match = regexp.exec(val)) {
          this.fx[type][selector][i] = val.replace(regexp, eval(match[1]));
        }
	  }
      $.extend(this.fx[type][selector], add);
	}
  }

  // Formatter that moves panel navigational preview into the navigation controls area
  //  initially these live in the panel, to keep their association to the panel
  Drupal.marquee.prototype.navPreviewHTML = function(index, panel) {
    return panel.find('.navigation-preview');
  }
  
  // Formatter that relies on CSS and the shared hover event
  Drupal.marquee.prototype.navPreviewCSS = function(index, panel) {
    return null;
  }

}(jQuery));;

