(function($){
  
  var HomeSection = function(elem) {
    
    var $this = $(elem),
	      $body = $('body'),
      	$features = $('#features'),
      	_features = null,
      	_isActive = false;
    
    // ----------------------------------------------------------------
    
    function _init() {
      debug.log("HomeSection :: initialized");
			
			// init styled links
			$this.find('.rounded-link').roundedLink();
			$this.find('.box-link').boxLink();
			$this.find('.block-text').blockText();
								
			// start HomeFeatures plugin
			_features = $features.homeFeatures().data('HomeFeatures');
			
			// Make the buttons work.
			$('#learn-more-link').bind('click', _onLearnMoreLinkClick);
			
			// update background
			var backgroundURI = $features.data('background-uri');
			var backgroundColor = $features.data('background-color');
			MomentumWW.backgroundManager.updateBackground(backgroundColor, backgroundURI);
			
    }; // _init()
    
    // ----------------------------------------------------------------

		function _activate() {
			document.title = "MomentumWW / Home";
			debug.log("HomeSection :: _activate()");
			_isActive = true;
			
			_features.activate();
		};
    
		function _deactivate() {
			debug.log("HomeSection :: _deactivate()");
			_isActive = false;
			
			_features.deactivate();
		};
		
		function _onLearnMoreLinkClick(e) {
			e.preventDefault();
			$.address.value("about");
		}
		
    _init();
    
    return {
      			
			activate: function () {
			 if (_isActive) {
          return;
        }
        
				_activate();
			},
			
			deactivate: function () {
			  if (!_isActive) {
          return;
        }
        
				_deactivate();
			}
    };
    
  };
  
  // ==================================================================
  
  $.fn.homeSection = function() {
    
    var pluginName = "HomeSection";
       
    return this.each(function(){
      
      var $this = $(this);
      
      if($this.data(pluginName)) {
        return;
      }
      
      // No JavaScript plugin instance exists, so add it as data attribute.
      var pluginInstance = new HomeSection(this);
      $this.data(pluginName, pluginInstance);
      $this.data('sectionController', pluginInstance);
    });
    
  };
  
  // ====================================================================
  
  
  // ==================================================================
  // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  // ==================================================================

  /*
    @HomeFeatures plugin
  */  
  var HomeFeatures = function(options, elem) {
    
    var $this = $(elem),
        $win = $(window),
        $featureContainer = $this.find('#feature-container'),
        $featureTitle = $this.find('#features-header h3'),
        $featureItems = $this.find('.feature-item'),
        $featuresPos = null,
        $featuresNeg = null,
        $detailContainer = null,
        $videoContainer = null,
        $closeButton = null,
        $ctaCopy = null,
        $prevBtn = null,
        $nextBtn = null,
        _numItems = $featureItems.length,
        _thumbSpacingX = $featureItems.outerWidth(true),
        _thumbSpacingY = $featureItems.outerHeight(true),
        _rowOffset = -_thumbSpacingY,
        _displayRows = 2,
        _displayCols = 6, // this initial value allows for covering a minimum 1920px wide area
        _displayColStart = -2, // columns have their own id with 0 being where the "start" of the centered content area is 
        _displayColEnd = _displayColStart + _displayCols - 1,
        _destPositionIndex = null,
        _curPositionOffset = 0,
        _curFeatureContainerOffset = 0,
        _isShifting = false,    
        _isSelectingItem = false,   
        _detailStates = {
          OPEN: 'open',
          CLOSED: 'closed',
          OPENING: 'opening',
          CLOSING: 'closing'
        },
        _detailState = _detailStates.CLOSED,
        _detailOpenWidth = 0,
        _detailOpenDuration = 500,
        _detailOpenEase = 'easeInOutExpo',
        _detailCloseDuration = 500,
        _detailCloseEase = 'easeInOutExpo',
        _videoController = null
        _isActive = false;
        
    // ----------------------------------------------------------------
    
    function _init() {
            
      // detach original featureItem elements, they will be used as a pool to clone items from to populate the grid
      $featureItems.bind('click', _onFeatureItemClick);
      $featureItems.bind('mouseenter', _onFeatureItemRollover);
      $featureItems.bind('mouseleave', _onFeatureItemRollout);
            
      $featureItems.each(function () {
        
        var $item = $(this),
            $title = $item.find('.feature-title');
            
        $title.css({
          bottom: -$title.outerHeight()
        });
        
      });
      $featureItems.detach();
            
      // create containers for positive and negatively positioned items, 
      // will be used to "break" apart the grid when the video expoands
      $featuresPos = $.shiv('<div id="features-pos"></div>');
      $featuresNeg = $.shiv('<div id="features-neg"></div>');
      var cssObj = {
        'position':'absolute',
        top:0,
        left:0
      };
      $featuresPos.css(cssObj);
      $featuresNeg.css(cssObj);
            
      $featureContainer.append($featuresPos)
        .append($featuresNeg);
          
      _addDisplayColumns(_displayColStart, _displayColEnd) 
      
      // add detail container
      $detailContainer = $.shiv('<div id="detail-container"></div>');
      $videoContainer = $.shiv('<div class="feature-video"></div>');
      $this.append($detailContainer);
      $detailContainer.append($videoContainer);
      _detailOpenWidth = $detailContainer.outerWidth();
      
      $closeButton = $.shiv('<a class="close-button" href="#">x close video</a>');
      $this.append($closeButton);
      $closeButton.bind('click', _onCloseClick);
      $closeButton.css({
        'visibility':'hidden',
        'opacity':'0'
      });
      
      var ctaStr = (MomentumWW.IS_IPAD) ? 
        'swipe to scroll and select image to view featured work' :
        'scroll and select image to view featured work';
      $ctaCopy = $.shiv('<p class="cta">'+ctaStr+'</p>');
      $this.append($ctaCopy);
      
      var $featureNavigation = $.shiv(
        '<div id="feature-navigation">'+
          '<a class="prev" href="#"></a>'+
          '<a class="next" href="#"></a>'+
        '</div>');
      $this.append($featureNavigation);
      $prevBtn = $this.find('#feature-navigation a.prev');
      $nextBtn = $this.find('#feature-navigation a.next');
      
      $featureTitle.css('opacity','0');
      
      if (MomentumWW.IS_IPAD) { // gpu transforms on ipad
        $featureContainer.css({
          '-webkit-transition-property': '-webkit-transform',
          '-webkit-transform': 'translate3d(0px, 0px, 0px)',
          '-webkit-transition-duration': '0ms'
        });
        
        $featuresPos.css({
          '-webkit-transition-property': '-webkit-transform',
          '-webkit-transform': 'translate3d(0px, 0px, 0px)',
          '-webkit-transition-duration': '0ms'
        });
        
        $detailContainer.css({
          '-webkit-transform-origin': '0 0',
          '-webkit-transition-property': '-webkit-transform',
          '-webkit-transform': 'scaleX(0)',
          '-webkit-transition-duration': '0ms'
        });
        
        $featureContainer.touchSwipe({
          swipeLeft:_onPrevClick,
          swipeRight:_onNextClick
        });
      } else {
        $detailContainer.css('width', 0);
      }
      
      
      
      //$win.bind('resize', _onResize);
          
    }; // _init()
    
    // ----------------------------------------------------------------
    
    function _activate() {
      _isActive = true;
      
      $prevBtn.bind('click', _onPrevClick);
      $nextBtn.bind('click', _onNextClick);
    }
    
    function _deactivate() {
      _isActive = false;
      
      $prevBtn.unbind('click', _onPrevClick);
      $nextBtn.unbind('click', _onNextClick);
      
      if (_detailState === _detailStates.OPEN) {
        
        // remove selected state from item so it can be reopened
        var $oldSelectedItem = $featureContainer.find('.feature-item.selected');
        if ($oldSelectedItem.length > 0) {
          $oldSelectedItem.removeClass('selected');
          _doFeatureItemRollout($oldSelectedItem);
        }
        
        _closeDetail();
      }
      
    }
    
    // ----------------------------------------------------------------
    
    function _onPrevClick(e) {
      if (typeof e !== 'undefined') {
        e.preventDefault();
      }
      
      _isSelectingItem = false;
      _prevFeature();
    }
    
    function _onNextClick(e) {
      if (typeof e !== 'undefined') {
        e.preventDefault();
      }
      
      _isSelectingItem = false
      _nextFeature();
    }
    
    function _nextFeature() {
      _setPosition(2);
    }
    
    function _prevFeature() {
      _setPosition(-2);
    }
    
    function _onFeatureItemTap(e) {
      //debug.log("_onFeatureItemTap");
      var $item = $(this);
  
      _selectItem($item);
    }
    
    function _onFeatureItemClick(e) {
      _selectItem($(this));
    }
    
    function _selectItem($featureItem) {
      var positionIndex = $featureItem.data('position-index');
      
      if ($featureItem.hasClass('selected')) {
        debug.log("item already selected");
        return;
      }
      
      _isSelectingItem = true;
      _setPosition(positionIndex);
    }
        
    function _onFeatureItemRollover() {
      var $item = $(this);
          
      if (
        !_isShifting
        && _detailState != _detailStates.OPENING 
        && _detailState != _detailStates.CLOSING
      ) {
        _doFeatureItemRollover($item);
      }
    }
    
    function _doFeatureItemRollover($item) {
      
      var $title = $item.find('.feature-title');
      $title.animate({bottom:-7}, 350, 'easeOutBack');
      
    }
    
    function _onFeatureItemRollout() {
      var $item = $(this);
          
      if (!$item.hasClass('selected')) {
        _doFeatureItemRollout($item);
      }
    }
    
    function _doFeatureItemRollout($item) {
      
      var $title = $item.find('.feature-title');
      $title.animate({bottom:-$title.outerHeight()}, 150, 'easeOutQuad');
      
    }
    
    // ----------------------------------------------------------------
    
    function _onCloseClick(e) {
      e.preventDefault();
      
      if (_detailState != _detailStates.OPEN) {
        return;
      }
      // remove selected state from item so it can be reopened
      var $oldSelectedItem = $featureContainer.find('.feature-item.selected');
      if ($oldSelectedItem.length > 0) {
        $oldSelectedItem.removeClass('selected');
        _doFeatureItemRollout($oldSelectedItem);
      }
      
      _closeDetail();
    }
    
    // ----------------------------------------------------------------
    
    function _setPosition(positionIndex) {
               
      if (_isShifting) {
        debug.log("already shifting items");
        return;
      }
      
      var $oldSelectedItem = $featureContainer.find('.feature-item.selected');
          $destItem = null;
          
      $featureContainer.find('.feature-item').each(function(){
        var $item = $(this),
            itemPositionIndex = $item.data('position-index');
            
        if (positionIndex === itemPositionIndex) {
          $destItem = $item;
        }
      });
      
      if ($oldSelectedItem.length > 0) {
        $oldSelectedItem.removeClass('selected');
        _doFeatureItemRollout($oldSelectedItem);
      }
      
      if (_isSelectingItem) {
        $destItem.addClass('selected');
        _doFeatureItemRollover($destItem);
      }
            
      _destPositionIndex = positionIndex;
      
      // close detail if its open
      if ((_detailState === _detailStates.OPEN) || (_detailState === _detailStates.OPENING)) {

        _closeDetail();
        
      } else if (_detailState === _detailStates.CLOSED) {
        _shiftToDestPosition();
      }
            
    }
    
    // ----------------------------------------------------------------

    function _shiftToDestPosition() {

      var col = Math.floor(_destPositionIndex / _displayRows),
          row = Math.abs(_destPositionIndex % _displayRows),
          offsetX = -((col * _thumbSpacingX) + (row * _rowOffset));

      _isShifting = true;

      // add extra columns on the end that "origin" is being shifted towards
      // eg: dest col -1 means add 1 col to left
      if (col < 0) {
        _addDisplayColumns(_displayColStart + col, _displayColStart - 1);
      } else {
        _addDisplayColumns(_displayColEnd + 1, _displayColEnd + col);
      }

     if (offsetX !== _curFeatureContainerOffset) {
        if (MomentumWW.IS_IPAD) {
          $featureContainer[0].addEventListener('webkitTransitionEnd', _shiftComplete, false);
          $featureContainer.css({
            '-webkit-transition-duration': '700ms',
            '-webkit-transform': 'translate3d('+offsetX+'px, 0px, 0px)'
          });
        } else {
          $featureContainer.animate({left:offsetX}, 700, "easeInOutExpo", _shiftComplete);
        }

        _curFeatureContainerOffset = offsetX;
      } else {
        _shiftComplete();
      }

    }

    function _shiftComplete() {
      //debug.log("shiftComplete");
      
      var $items = $featureContainer.find('.feature-item'),
          offset = -Math.abs(_destPositionIndex % _displayRows) * _rowOffset,
          colsShifted = Math.floor(_destPositionIndex / _displayRows);

      if (MomentumWW.IS_IPAD) {
        $featureContainer[0].removeEventListener('webkitTransitionEnd', _shiftComplete);
        $featureContainer.css({
          '-webkit-transition-duration': '0ms',
          '-webkit-transform': 'translate3d('+offset+'px, 0px, 0px)'
        });
      } else {
        $featureContainer.css('left', offset+'px');
      }

      _curFeatureContainerOffset = offset;

      // update position indexes and positions on items
      $items.each(function () {

        var $item = $(this),
            newPositionIndex = $item.data('position-index') - _destPositionIndex + Math.abs(_destPositionIndex % _displayRows),
            col = Math.floor(newPositionIndex / _displayRows),
            row = Math.abs(newPositionIndex % _displayRows),
            x = (row * _rowOffset) + (col * _thumbSpacingX),
            y = row * _thumbSpacingY;

        $item.data('position-index', newPositionIndex).detach();

        if (MomentumWW.IS_IPAD) {
          $item.css({
            '-webkit-transform': 'translate3d('+x+'px, '+y+'px, 0px)'
          });
        } else {
          $item.css({
            top:y,
            left:x
          });
        }

        // re-attach to appropriate container depending if its newPosition is on the positive or negative side of the "split" line
        if (newPositionIndex >= 0) {

          if ((newPositionIndex == 1) && (offset == 0)) {
            $featuresNeg.append($item);
          } else {
            $featuresPos.append($item);
          }

        } else {
          $featuresNeg.append($item);
        }

      });

      // update position offset used to get correct item index when adding new columns
      _curPositionOffset += (_destPositionIndex - Math.abs(_destPositionIndex % _displayRows));
      _curPositionOffset %= _numItems;

      // remove extra columns from the end that "origin" was shifted away from
      if (colsShifted < 0) {
        _removeDisplayColumns(_displayColEnd + 1, _displayColEnd - colsShifted);
      } else {
        _removeDisplayColumns(_displayColStart - colsShifted - 1, _displayColStart - 1);
      }

      _isShifting = false;
      _destPositionIndex = null;

      // open detail
      if (_isSelectingItem) {
        _openDetail();
      }
    }

    // ----------------------------------------------------------------

    function _addDisplayColumns(colStart, colEnd) {

      var x = 0,
          y = 0,
          positionIndex = 0,
          offsetPositionIndex = 0,
          itemIndex = 0,
          $item = null;

      for (var i=colStart; i <= colEnd ; i++) {
        for (var j=0; j < _displayRows; j++) {
          // find positionIndex based on row(j), col(i) 
          // (can be negative, this is used in order to pull items starting from the last item in the array, 
          // working backwards from the "start" position at the left edge of the centered content area)
          positionIndex = (i * _displayRows) + j;

          // keep track of the offset
          offsetPositionIndex = (positionIndex + _curPositionOffset) % _numItems;
          // use position index to correlate with an itemIndex to pull from the set of $featureItems 
          itemIndex = ( offsetPositionIndex < 0 ) ? _numItems + (offsetPositionIndex) : offsetPositionIndex;

          // find absolute position values
          x = (j * _rowOffset) + (i * _thumbSpacingX);
          y = j * _thumbSpacingY;

          $item = $featureItems.eq(itemIndex).clone(true);
          $item.data('position-index', positionIndex);

          if (MomentumWW.IS_IPAD) {
            $item.touchTap();
            $item.bind('tap.touchtap', _onFeatureItemTap);
            
            $item.css({
              'position':'absolute',
              '-webkit-transform': 'translate3d('+x+'px, '+y+'px, 0px)'
            });
          } else {
            $item.css({
              'position':'absolute',
              top:y,
              left:x
            });
          }

          // append item to appropriate container depending if its on the positive or negative side of the "split" line
          if (positionIndex >= 0 && positionIndex != 1) {
            $featuresPos.append($item);
          } else {
            $featuresNeg.append($item);
          }

        }
      }

    }

    // ----------------------------------------------------------------

    function _removeDisplayColumns(colStart, colEnd) {

      var $items = $featureContainer.find('.feature-item'),
          positionIndex = 0;

      for (var i=colStart; i <= colEnd ; i++) {
        for (var j=0; j < _displayRows; j++) {
          positionIndex = (i * _displayRows) + j;

          $items.each(function(){
            var $item = $(this),
                itemPositionIndex = $item.data('position-index');

            if (positionIndex === itemPositionIndex) {
              
              if (MomentumWW.IS_IPAD) {
                $item.unbind('tap.touchtap', _onFeatureItemTap);
              }
              
              $item.remove();
            }
          });
        }
      }

    }
  
    // ----------------------------------------------------------------
    
    function _openDetail() {
            
      var $selectedItem = $featureContainer.find('.feature-item.selected'),
          $videoPoster = null,
          $videoPosterImg = null;
      
      _detailState = _detailStates.OPENING;
      
      // update feature header with project title and fade in
      $featureTitle.text($selectedItem.attr('data-title'));
      $featureTitle.animate({opacity:1}, 550);
            
      // hide cta copy
      $ctaCopy.animate({opacity:0}, 250, 'easeOutQuad', function() {
        $ctaCopy.css('visibility','hidden');
      });      
      
      // animate video box open to where it "hits" the respective client logo for the detail 
      if (MomentumWW.IS_IPAD) {
                
        $detailContainer[0].addEventListener('webkitTransitionEnd', _openDetailAnimationEnd, false);
        $detailContainer.css({
          '-webkit-transition-duration': '250ms',
          '-webkit-transition-timing-function':'ease-in',
          '-webkit-transform': 'scaleX('+(305/_detailOpenWidth)+')'
        });
        
      } else {
        $detailContainer.animate({width:305}, 500, 'easeInExpo', _openDetailAnimationEnd );
      }
    
    }
    
    function _openDetailAnimationEnd() {
      
      // animate video box the rest of the way open and slide respective client logo for the detail with it
      if (MomentumWW.IS_IPAD) {
        $detailContainer[0].removeEventListener('webkitTransitionEnd', _openDetailAnimationEnd);
        $detailContainer[0].addEventListener('webkitTransitionEnd', _onOpenDetailComplete, false);
        
        $featuresPos.css({
          '-webkit-transition-duration': '250ms',
          '-webkit-transition-timing-function':'ease-out',
          '-webkit-transform': 'translate3d(238px, 0px, 0px)'
        });
        
        $detailContainer.css({
          '-webkit-transition-duration': '250ms',
          '-webkit-transition-timing-function':'ease-out',
          '-webkit-transform': 'scaleX(1)'
        });
      } else { 
        $featuresPos.animate({left:238}, 500, 'easeOutExpo');
        $detailContainer.animate({width:_detailOpenWidth}, 500, 'easeOutExpo', _onOpenDetailComplete);
      }
      
    }
    
    function _onOpenDetailComplete() {
      
      if (MomentumWW.IS_IPAD) { 
        $detailContainer[0].removeEventListener('webkitTransitionEnd', _onOpenDetailComplete);
      }
                
      _detailState = _detailStates.OPEN;
      
      // display close button
      $closeButton.css('visibility','visible')
        .animate({opacity:1}, 250);
                  
      _addVideoPlayer();
      
    }
    
    function _addVideoPlayer() {
      
      var $selectedItem = $featureContainer.find('.feature-item.selected'),
          $videoPoster = null,
          $videoPosterImg = null,
          $playIcon = null;
          
      if (MomentumWW.IS_IPAD) {
        
        $videoContainer.css('opacity', 1);
        
        // for ipad we're attaching the poster image first
        $videoPoster = $.shiv('\
            <div class="feature-video-poster">\
              <img src="'+$selectedItem.data('video-poster-uri')+'" >\
              <div class="video-play-icon"></div>\
            </div>');

        $playIcon = $videoPoster.find('.video-play-icon');
        $playIcon.css('opacity', '0');
        $videoPosterImg = $videoPoster.find('img');
        $detailContainer.append($videoPoster);
        $videoPosterImg.bind(MomentumWW.events.PRELOAD_COMPLETE, _onVideoPosterLoaded);
        $videoPosterImg.preloadImg();
        
      } else {
        
        // for desktop attach the video and start playing
        $videoContainer.embedVideo($selectedItem.attr('data-video-uri'), 542, 305);
        if (_videoController == null) {
          _videoController = $videoContainer.videoController().data('videoController');
        } else {
          _videoController.reset();
        }
        
        _videoController.play();
      }
      
    }
    
    function _onVideoPosterLoaded() {
      
      var $selectedItem = $featureContainer.find('.feature-item.selected'),
          $videoPoster = $detailContainer.find('.feature-video-poster'),
          $videoPosterImg = $videoPoster.find('img'),
          $playIcon = $videoPoster.find('.video-play-icon');
      
      $videoPosterImg.unbind(MomentumWW.events.PRELOAD_COMPLETE, _onVideoPosterLoaded);
      
      $playIcon.animate({opacity:1}, 500);
      
      $videoContainer.embedVideo($selectedItem.attr('data-video-uri'), 542, 305);
      
      if (_videoController == null) {
        _videoController = $videoContainer.videoController().data('videoController');
      } else {
        _videoController.reset();
      }
      
      if (MomentumWW.IS_IPAD) {
        _videoController.getVideoElement().addEventListener('play', _onVideoPlay, false);
      }
      
    }
    
    function _onVideoPlay(e) {
      
      //remove event handler
      _videoController.getVideoElement().removeEventListener('play', _onVideoPlay);
      
      var $videoPoster = $detailContainer.find('.feature-video-poster');
      
      $videoPoster.animate({opacity:0}, 300, "easeOutQuad", function() {
        $videoPoster.addClass('hidden');
      });

    }
    
    function _closeDetail() {
      
      if (_detailState === _detailStates.OPENING) {
        $featuresPos.stop();
        $detailContainer.stop();
      }
      
      // fade out feature header
      $featureTitle.animate({opacity:0}, 250);
           
      _detailState = _detailStates.CLOSING;
      
      // hide close button
      $closeButton.animate({opacity:0}, 250, 'easeOutQuad', function() {
        $closeButton.css('visibility','hidden');
      });
     
      if (MomentumWW.IS_IPAD) {
        // fade video/poster out
        var $videoPoster = $detailContainer.find('.feature-video-poster');
        $videoPoster.animate({opacity:0}, 500, "easeOutQuad");
        $videoContainer.animate({opacity:0}, 500, 'easeOutQuad', _closeDetailVideoFadeComplete);
      } else {
        $featuresPos.animate({left:0}, 300, 'easeInExpo');
        $detailContainer.animate({width:305}, 300, 'easeInExpo', _closeDetailAnimationEnd);
      }
    }
    
    function _closeDetailVideoFadeComplete() {
      if (MomentumWW.IS_IPAD) {
                
        $featuresPos.css({
          '-webkit-transition-duration': '150ms',
          '-webkit-transition-timing-function':'ease-in',
          '-webkit-transform': 'translate3d(0px, 0px, 0px)'
        });
        
        $detailContainer[0].addEventListener('webkitTransitionEnd', _closeDetailAnimationEnd, false);
        $detailContainer.css({
          '-webkit-transition-duration': '150ms',
          '-webkit-transition-timing-function':'ease-in',
          '-webkit-transform': 'scaleX('+(305/_detailOpenWidth)+')'
        });
        
        $videoContainer.empty();
      }
    }
    
    function _closeDetailAnimationEnd() {
      
      if (MomentumWW.IS_IPAD) {
        $detailContainer[0].removeEventListener('webkitTransitionEnd', _closeDetailAnimationEnd);
        $detailContainer[0].addEventListener('webkitTransitionEnd', _onCloseDetailComplete, false);
        
        $detailContainer.css({
          '-webkit-transition-duration': '150ms',
          '-webkit-transition-timing-function':'ease-out',
          '-webkit-transform': 'scaleX(0)'
        });
        
      } else {
        $detailContainer.animate({width:0}, 300, 'easeOutExpo', _onCloseDetailComplete);
      }
      
    }
    
    function _onCloseDetailComplete() {
      
      if (MomentumWW.IS_IPAD) {
        $detailContainer[0].removeEventListener('webkitTransitionEnd', _onCloseDetailComplete);
      }
      
      _detailState = _detailStates.CLOSED;
      
      $videoContainer.empty();
            
      $detailContainer.find('.feature-video-poster').remove();
      
      $ctaCopy.css('visibility','visible')
        .animate({opacity:1}, 350);
      
      if (_destPositionIndex !== null) {
        _shiftToDestPosition();
      }
    }
    
    // ----------------------------------------------------------------
        
    function _onResize() {
      
      // debounce resize event
      $.doTimeout( 'homefeatures-resize', 250, function(){
        debug.log("resize: "+$win.width());
      });
    }
    
    // ----------------------------------------------------------------
    
    _init();
    
    return {
      activate: function () {
			 if (_isActive) {
          return;
        }
        
				_activate();
			},
			
			deactivate: function () {
			  if (!_isActive) {
          return;
        }
        
				_deactivate();
			}
    };
    
  };
  
  // ==================================================================
  
  $.fn.homeFeatures = function(options) {
    
    var pluginName = "HomeFeatures";
    
    options = $.extend({}, $.fn.homeFeatures.defaults, options);
    
    return this.each(function(){
      
      var $this = $(this);
      
      if($this.data(pluginName)) {
        return;
      }
      
      // No JavaScript plugin instance exists, so add it as data attribute.
      var pluginInstance = new HomeFeatures(options, this);
      $this.data(pluginName, pluginInstance);
      
    });
    
  };
  
  // ==================================================================
  
  $.fn.homeFeatures.defaults = {
    
  };
  
})(jQuery);

