/* ----------------------------------
 * Nike.Plugins
 * ---------------------------------- */

/* @Events, @Views, and @Paths (Constants) */

;(function($) {

  $.Events = {
  
    // UTILITY 
    FILTER: 'filter',
    FILTER_COMPLETE: 'filter_complete',
    
    VIEW: 'view',
    VIEW_COMPLETE: 'view_complete',
    
    SCROLL: 'scroll_page',
    SCROLLTO: 'scroll_to',
    SCROLL_COMPLETE: 'scroll_page_complete',

    UTILITY_COUNT: 'utility_count',
        
    // KEYBOARD 
    KEY_UP: 'key_up',
    KEY_DOWN: 'key_down',
    KEY_LEFT: 'key_left',
    KEY_RIGHT: 'key_right',
    KEY_ENTER: 'key_enter',
    KEY_ESC: 'key_esc',
    KEY_RELEASE: 'key_release',
    
    // DETAIL 
    DETAIL_INIT: 'detail_init',
    DETAIL_OPEN: 'detail_open',
    DETAIL_CLOSE: 'detail_close',
    DETAIL_COMPLETE: 'detail_complete',
    DETAIL_SEEK: 'detail_seek',
		DETAIL_SEEK_COMPLETE: 'detail_seek_complete',
        
    // BROWSE
    BROWSE_DETAIL: 'browse_detail',

    // SECTIONS
    EXPAND: 'expand',
    
    // SHADE
    SHADE: 'shade',
    SHADE_OPEN: 'shade_open',
    SHADE_CLOSE: 'shade_close',
    SHADE_CLOSE_COMPLETE: 'shade_close_complete',
    
    // PRODUCTS
    DETAIL_IMAGE: 'detail_image',
    
    // UTILITY
    SECTION_SEEK: 'section_seek'
  
  } // Events  
  
  $.Views = {
  
    BROWSE: '_browse',
    GRID: '_grid',
    DETAIL: '_detail',
    LARGE: '_large',
    MEDIUM: '_medium',
    XSMALL: '_xsmall',
    SEARCH: '_search',
    _1024: '_1024',
    SHADE: '_shade'
  
  }; // Views 

	$.Paths = {
		BASE: 'http://www.nikesnowboarding.com/',
		ASSETS: 'http://assets/',
		MEDIA: 'http://media/',
		VIDEO_PLAYER: 'http://media/video/'
	};
   
  
})(jQuery);

/* ---------------------------------- */

/* @isIpad Utility Function */

;(function($) {
  
  $.isIPad = function() {
    if(navigator && navigator.platform && navigator.platform.match(/^(iPad)$/)) {
      return true;
    }
    return false;
  };
  
})(jQuery);


/* ---------------------------------- */

/* @Instantiate */

;(function($) {

  $.fn.Instantiate = function(settings) {
     
    var config = {};
 
    if (settings)
      $.extend(config, settings);

    this.each(function() { 

        var $self = $(this),
            $auto = $self.attr('data-auto'),
            $controller = $self.attr('data-controller');
        
        // Add a conditional for the Product controller, since we're doing it manually with ProductsManager
        if ($auto!='false' && $controller != 'Product') {
          eval('$self.'+$controller+'()');
        }
            
    });
      
  };//NIKE

})(jQuery);


/* ---------------------------------- */

/* @Shake and @ShakeManager */

;(function($){
  
  $.fn.arrayCompare = function(arr) {
    if(this.length != arr.length) return false;
    
    for (var i=0; i < this.length; i++) {
      if(this[i] !== arr[i]) return false;
    };
    
    return true;
  };

  $.fn.ShakeManager = function(settings) {

    var config = $.extend({}, $.fn.ShakeManager.defaults, settings);

    return this.each(function(){
      
      var $self = $(this),
          $win = $(window),
          $body = $('body'),
          _combos = [
                      [83, 72, 65, 75, 69], // shake
                      [83, 84, 79, 80] // stop
                    ],
          _comboNames = [
                      'shake',
                      'stop'
                    ],
          _shortestCombo = 4,
          _longestCombo = 5,
          _lastKeys = [];
      
      // Method for checking key combinations
      $win.keydown(function(e){
        
        _lastKeys.push(e.which);
        if(_lastKeys.length > _longestCombo) {
          _lastKeys.splice(0, 1);
        }
        
        if(_lastKeys.length >= _shortestCombo) {
          var l = _combos.length;
          while(l--) {
            var combo = _combos[l];
            var last = _lastKeys.slice(_lastKeys.length - combo.length);
            if( $(last).arrayCompare(_combos[l]) ) {
              $body.triggerHandler('shake', _comboNames[l]);
              break;
            };
          }
        }
        
      });

    });

  };

  $.fn.ShakeManager.defaults = {
    
  };
  
  $.fn.Shake = function(settings) {
  
    var config = $.extend({}, $.fn.Shake.defaults, settings);
  
    return this.each(function(){
    
      var $self = $(this),
          $body = $('body'),
          _isShaking = false,
          _origin = {
                      x: parseInt( $self.css('margin-left') ),
                      y: parseInt( $self.css('margin-top') )
                    },
          _shakeInv = -1;
          
      function onShakeCombo(e, comboName) {
        
        switch(comboName) {
          case 'shake':
            start();
            break;
          case 'stop':
            stop();
            break;
        }
        
      };
      
      function doShake(){
        var newX = _origin.x + (Math.random() * config.maxDist - config.maxDist / 2);
        var newY = _origin.y + (Math.random() * config.maxDist - config.maxDist / 2);
        $self.css({
          marginLeft: newX + 'px',
          marginTop: newY + 'px'
        });
      };
      
      function start(){
        if(_shakeInv == -1) {
          $self.css({
            marginLeft: _origin.x + 'px',
            marginTop: _origin.y + 'px'
          });
          _shakeInv = setInterval(doShake, 1000 / 30);
        }
      };
      
      function stop(){
        if(_shakeInv != -1) {
          $self.css({
            marginLeft: _origin.x + 'px',
            marginTop: _origin.y + 'px'
          });
        
          clearInterval(_shakeInv);
          _shakeInv = -1;
        }
      };
          
      $body.bind('shake', onShakeCombo);
      
      if(config.shakeOnStart) {
        start();
      }
    
    });
  
  };

  $.fn.Shake.defaults = {
  
    maxDist: 2,
    shakeOnStart: false
  
  };
  
})(jQuery);


/* ---------------------------------- */

/* @ProductsManager, @Product, @ProductItem, and @ProductTitle */

;(function($) {
  
  // ProductsManager instantiates all Product controllers
  // and manages active sections for keyboard handling.
  var ProductsManagerMethods = {
    
    // -------------------------------------------------------------------------
    init: function(options) {
      
      // Handle the options.
      options = $.extend({}, $.fn.ProductsManager.defaults, options);
      
      return this.each(function(){
        
        var $this = $(this),
            $body = $('body'),
            $productGroups = $this.find('section[data-controller=Product]'),
            $firstProductItem = $this.find('article.product-item').first(),
            $win = $(window),
            $scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
            productItemHeight = $firstProductItem.outerHeight(true),
            startY = $firstProductItem.offset().top,
            offsetY = 110,
            productControllersTable = {},
            productControllersRowCount = [],
            currProductRow = -1,
            currProductGroupingIndex = -1,
            isAutoScrolling = false,
            currController = null;
        
        function onDetailOpen(event, productElem) {
          currController = $(productElem);
          
          // Update the current product row to be this grouping.
          $productGroups.each(function(index){
            if($(this).Product('getCategory') == currController.Product('getCategory')) {
              currProductGroupingIndex = index;
              currProductRow = 0;
            }
          });
          
        };
        
        function onDetailClose(event, productCategory) {
          // Check to see if this is matching the current active controller.
          if(currController != null) {
            if(currController.Product('getCategory') == productCategory) {
              currController = null;
            }
          }
        };
        
        function recalculateCurrentRow() {
          
          var newGroupingIndex = -1;
          var newProductRow = -1;
          
          // Recalculate where we are.
          var top = $win.scrollTop() + 110;
          var $group;
          $productGroups.each(function(index){
            $group = $(this);
            if(top >= $group.offset().top)
              newGroupingIndex = index;
          });
          
          if(newGroupingIndex > -1) {
            // Figure out the row.
            $group = $productGroups.eq(newGroupingIndex);
            newProductRow = Math.ceil((top - $group.offset().top) / productItemHeight);
            
            if(newGroupingIndex != currProductGroupingIndex) {
              currProductGroupingIndex = newGroupingIndex;
            }
            if(newProductRow != currProductRow) {
              currProductRow = newProductRow;
            }
          }
        };
        
        function onKeyUp(event) {
          if(!$body.hasClass($.Views.BROWSE)) {
          
            if(currController == null) {
              
              if(!isAutoScrolling)
                recalculateCurrentRow();
            
              if(currProductGroupingIndex != -1) {
            
                currProductRow--;
                if(currProductRow < 0) {
                  currProductGroupingIndex--;
                  if(currProductGroupingIndex < 0) {
                    currProductGroupingIndex = 0;
                    currProductRow++;
                  } else {
                    currProductRow = productControllersRowCount[currProductGroupingIndex] - 1;
                  }
                }
            
                scrollToNewRow();
            
              }
              
            } else {
            
              // Check to make sure we're not already at 0.
              if(currProductGroupingIndex > 0) {
              
                currController.Product('close');
                // Now do the auto-scroll to the next position.
                currProductGroupingIndex--;
                currProductRow = 0;
                isAutoScrolling = true;
                $productGroups.eq(currProductGroupingIndex).Product('openFirstProductDetail');
              
              }
            
            }
          
          }
        };
        
        function onKeyDown(event) {
          if(!$body.hasClass($.Views.BROWSE)) {
            
            if(currController == null) {
              
              if(!isAutoScrolling)
                recalculateCurrentRow();
              
              if(currProductGroupingIndex == -1) {
                currProductGroupingIndex = 0;
                currProductRow = -1;
              }
            
              currProductRow++;
              if(currProductRow >= productControllersRowCount[currProductGroupingIndex]) {
                currProductGroupingIndex++;
                if(currProductGroupingIndex >= productControllersRowCount.length) {
                  currProductRow--;
                  currProductGroupingIndex = productControllersRowCount.length - 1;
                } else {
                  currProductRow = 0;
                }
              }
            
              scrollToNewRow();
            
            } else {
            
              // Check to make sure we're not already at the last grouping.
              if(currProductGroupingIndex < $productGroups.length - 1) {
              
                currController.Product('close');
                // Now do the auto-scroll to the next position.
                currProductGroupingIndex++;
                currProductRow = 0;
                isAutoScrolling = true;
                $productGroups.eq(currProductGroupingIndex).Product('openFirstProductDetail');
              
              }
            
            }
            
          }
        };
        
        function onKeyEnter(event) {
          
          if(!$body.hasClass($.Views.BROWSE)) {
          
            if(currController == null) {            
              // Open up the first item in the current row of the current product grouping.
              var $productGrouping = $productGroups.eq(currProductGroupingIndex);
              // Figure out which item is first in this row.
              var $productItems = $productGrouping.find('article.product-item');
              var productIndex = currProductRow * 4;
              $productGrouping.Product('openProductDetail', productIndex);
            }
          
          }
          
        };
        
        function scrollToNewRow() { 
          // First, figure out which productController grouping we're in.
          var $productGrouping = $productGroups.eq(currProductGroupingIndex);
          var groupingY = $productGrouping.offset().top;
          var destScroll = groupingY + currProductRow * productItemHeight;
          
          isAutoScrolling = true;
          $body.triggerHandler($.Events.SCROLLTO, destScroll);
        };
        
        function onScrollComplete(event) {
          isAutoScrolling = false;
        };
        
        // Store all our Product controllers.
        var totalProductsHeight = 0; 
        $productGroups.each(function(){
          
          var $productController = $(this).Product( {owner: $this} );
          var cat = $(this).Product( 'getCategory' );
          productControllersTable[cat] = $productController;
          $productController.bind($.Events.DETAIL_CLOSE, onDetailClose);
          $productItems = $productController.find('article.product-item');
          var numRows = Math.ceil($productItems.length / 4);
          productControllersRowCount.push(numRows);
          totalProductsHeight += numRows * productItemHeight;
          
        });
        
        if(!GLOBAL_IS_MOBILE) {
          // Bind our events.
          $this.bind($.Events.DETAIL_OPEN, onDetailOpen);
          $body
            .bind($.Events.KEY_UP, onKeyUp)
            .bind($.Events.KEY_DOWN, onKeyDown)
            .bind($.Events.KEY_ENTER, onKeyEnter)
            .bind($.Events.SCROLL_COMPLETE, onScrollComplete);
            
          // Do the Shake functionality
          $body.ShakeManager();
          $('article.product-item').Shake();
          
        }
        
      });
      
    }
    
  };
  
  
  $.fn.ProductsManager = function(method) {
    
    if( ProductsManagerMethods[method] ) {
      
      return ProductsManagerMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
      
    } else if ( typeof method === 'object' || !method ) {
      
      return ProductsManagerMethods.init.apply( this, arguments );
      
    } else {
      
      $.error( 'The method named "' + method + '" does not exist on jQuery.ProductsManager.');
      
    }
    
  };
  

  // Default Options
  $.fn.ProductsManager.defaults = {
    plugin: 'ProductsManager'
  };
  
  
  /****************************************
   *
   * Product Controller
   *
   ****************************************/
  var ProductMethods = {
    
    init: function(options) {
      
      options = $.extend({}, $.fn.Product.defaults, options);
      
      return this.each(function(){
        
        // --------------------------------
        // Private variables
        // --------------------------------
        var $self = $(this),
            $body = $('body'),
            $owner = options.owner,
            $products = $self.find('article[data-parent=Product]'),
            $_category = $self.attr('data-category'),
            $_height = $self.outerHeight(),
            $keyboard = $('<mark/>').addClass('keyboard').appendTo($self),
            $close = $('<a/>').addClass('close-button').attr('href','#/close').html('close').appendTo($self),
            $left = $('<a/>').addClass('arrow-left').attr('href','#/previous').appendTo($self),
            $right = $('<a/>').addClass('arrow-right').attr('href','#/next').appendTo($self),
            $touchwipe = null,
            _active = 0,
            _keyboard = false,
            _isOpen = false,
            // DETAIL VIEW          
            $_active_products = [],
            _active_index = 0;
            
        // Establish the data.
        var data = $self.data('Product');
        if( !data ) {
          
          $self.data('Product', {
            
            category: $_category
            
          });
          data = $self.data('Product');
          
        }
        
        // Do initialization.
        if(GLOBAL_IS_MOBILE) {
          $keyboard.css({display: 'none'});
        }
        
        $keyboard.KeyboardTooltip();

        _calibrate();

        $('<section/>').Shade({owner:$self});

        $products.ProductItem({owner:$self});

        $body
          .bind($.Events.FILTER,on_filter)
          .bind($.Events.DETAIL_OPEN,on_detail_open)
          .bind($.Events.SHADE_OPEN,on_shade_open)
          .bind($.Events.SHADE_CLOSE,on_shade_close)
          .bind($.Events.VIEW,_close)
          .bind($.Events.SECTION_SEEK,_close);

        $self
          .bind($.Events.DETAIL_INIT,on_detail_init)
          .bind('oncloserequest',_close);

        $close.click(_close);
        $left.click(on_key_left);
        $right.click(on_key_right);

        $(window).bind('resize',on_resize);
        

        // -------------------------------------------------
        // Private Event Handlers
        // -------------------------------------------------
        function on_detail_init(e,product_id) {
          
          debug.log("Product :: on_detail_init() :: " + product_id);
          
          _active_index = _get_index(product_id);

          $owner.triggerHandler($.Events.DETAIL_OPEN, [this]);
          $body.triggerHandler($.Events.DETAIL_OPEN, $_category);

          _seek();

          e.preventDefault();

        };

        function on_key_right(e) {

          _active_index++;

          if (_active_index>=$_active_products.length)
            _active_index = $_active_products.length-1;

          _seek();

        };

        function on_key_left(e) {

          _active_index--;

          if (_active_index<0)
            _active_index = 0;

          _seek();

        };
        
        function on_key_esc(e) {

          _close();

        };

        function on_resize(e) {

          if($self.hasClass($.Views.DETAIL)) {

            var viewwidth = ($(window).width() > 1000) ? $(window).width() : 1000;

            $self.stop().css({marginLeft:-viewwidth*_active_index});

          }

          _calibrate();

        };

        function on_detail_open(e,category) {

          if($_category==category) {

            _open();

          } else {

            _close();

          }

        };

        function on_filter(e,filter) {

          var c = 0;

          if (filter!='All') {

            _set_active_products(filter);

            $products.each(function() {  

              if ($(this).attr('data-filter')==filter)
                c++;

            });

          } else {

            c = $products.length

            _set_active_products();

          }

          $body.triggerHandler($.Events.UTILITY_COUNT,[$_category,c])

          if ($self.hasClass($.Views.DETAIL))
            _close();

        };

        // ---------------------------------------------------------
        // Private methods
        // ---------------------------------------------------------

        function _get_index(product_id) {

          for (var i=0;i< $_active_products.length; i++) {

            if ($_active_products[i].attr('data-id')==product_id)
              return i;

          }

          return -1;

        };

        function _get_product_id(index) {

          return $_active_products[index].attr('data-id');

        };

        function _seek() {

          var viewwidth = ($(window).width() > 1000) ? $(window).width() : 1000;

          $self.stop().animate({marginLeft:-viewwidth*_active_index},550,'easeOutQuart',function(){
    				$self.triggerHandler($.Events.DETAIL_SEEK_COMPLETE);
    			});

          $self.triggerHandler($.Events.DETAIL_SEEK,_get_product_id(_active_index));

          _calibrate();

        };

        function _set_active_products(f) {

          $_active_products = new Array();

          $products.each(function(i) {  

            //DEBUG: $(this).html(i)

            if (f) {
              if ($(this).attr('data-filter')==f)
                $_active_products.push($(this));
            } else {
              $_active_products.push($(this));
            }

          });

        };

        function _close() {
          if(_isOpen) {
            _isOpen = false;

            _disable_touch_events();

            //remove inline styles so CSS can control
            $self.each(function(i,e){
              e.style.width = '';
              e.style.maxWidth = '';
            })

            _active = 0

            _disable_keyboard();

            $self
              .removeClass($.Views.DETAIL)
              .stop()
              .animate({marginLeft:0},0,'easeOutQuart')
              .triggerHandler($.Events.DETAIL_CLOSE, $_category);

          }
        };

        function _open(i) {
          _isOpen = true;

          if(!$self.hasClass($.Views.DETAIL))
            $body.triggerHandler($.Events.SCROLL,$_category);

          _active = i;

          _enable_touch_events();

          if (!_keyboard) {

            _enable_keyboard();

            _keyboard = true;

          }

          $self.addClass($.Views.DETAIL);

          $self.triggerHandler($.Events.DETAIL_COMPLETE);
        };

        function _enable_touch_events() {

          if(GLOBAL_IS_IOS) {
            if($touchwipe != null) {
              _disable_touch_events();
            }
            $touchwipe = $self.touchwipe({
              wipeLeft: function() { on_key_right(); },
              wipeRight: function() { on_key_left(); },
              min_move_x: 200,
              preventDefaultEvents: false
            });
          }

        };

        function _disable_touch_events() {

          if(GLOBAL_IS_IOS) {
            if($touchwipe != null) {
              $touchwipe.touchwipe('destroy');
              $touchwipe = null;
            }
          }

        };

        function _enable_keyboard() {

          $body
          .bind($.Events.KEY_RIGHT,on_key_right)
          .bind($.Events.KEY_LEFT,on_key_left)
          .bind($.Events.KEY_ESC,on_key_esc);

        };

        function _disable_keyboard() {

          $body
          .unbind($.Events.KEY_RIGHT,on_key_right)
          .unbind($.Events.KEY_LEFT,on_key_left)
          .unbind($.Events.KEY_ESC,on_key_esc);

          _keyboard = false;

        };

        function on_shade_open() {
          if(_isOpen) {
            _disable_keyboard();
            _disable_touch_events();
          }
        };

        function on_shade_close() {
          if(_isOpen) {
            _enable_keyboard();
            _enable_touch_events();
          }
        };

        function _calibrate() {

          if($self.hasClass($.Views.DETAIL)) {

            var w = $(window).width() * ($products.length+1);

            $self.css({width: w, maxWidth: w });

          } 

        };
          
      }); // End jQuery.each
      
    }, // End init() method
    
    getCategory: function() {
      
      var data = this.data('Product'),
          category = data.category;
      
      return category;
      
    }, // End getCategory() method
    
    close: function() {
      
      this.triggerHandler('oncloserequest');
      
    },
    
    openFirstProductDetail: function() {
      
      this.find('article[data-parent=Product]').first().click();
      
    },
    
    openProductDetail: function(index) {
      
      this.find('article[data-parent=Product]').eq(index).click();
      
    }
    
  }; // End ProductMethods
  
  
  $.fn.Product = function(method) {
    
    if( ProductMethods[method] ) {
      
      return ProductMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
      
    } else if ( typeof method === 'object' || !method ) {
      
      return ProductMethods.init.apply( this, arguments );
      
    } else {
      
      $.error( 'The method named "' + method + '" does not exist on jQuery.Product.');
      
    }
    
  }; // End Product Plugin  
  
  $.fn.ProductItem = function(settings) {
     
    var config = $.extend({}, settings);
    
    var $body = $('body');
      
    return this.each(function(index) {
      
      var $self = $(this),
          $owner = config.owner,
          $a = $self.find('a'),
          $header = $self.find('header'),
          $title = $header.find('h3 a').ProductTitle(),
          $figure = $self.find('figure'),
          $img = $figure.find('img'),
          $_id = $self.attr('data-id'),
          $_filter = $self.attr('data-filter'),
          $_category = $self.attr('data-category'),
          _loaded_detail = false,
          _loading = false,
          _name = $self.attr('data-name'),
          _id = $self.attr('data-id'),
					_isSeekComplete = false;
      
      /* ---------------------------------- */
      
      /* REGISTER EVENTS */
          
      $self
        .bind('click',on_click);

      $a
        .bind('click',on_click);
      
      $owner
        .bind($.Events.DETAIL_SEEK,on_detail_seek)
        .bind($.Events.DETAIL_CLOSE,on_detail_close)
        .bind($.Events.DETAIL_COMPLETE,on_detail_complete)
        .bind($.Events.DETAIL_SEEK_COMPLETE,on_detail_seek_complete);
      
      $body
        .bind($.Events.FILTER,on_filter)
        .bind($.Events.DETAIL_OPEN,on_detail_open);
      
      $figure.Preload({image:'img'});        
      
      $(window).bind('resize',on_resize);
      
      /* ---------------------------------- */
       
      function on_resize(e) {
        
        _calibrate_width();
        
      } //resize
      
      function on_filter(e,filter) {

        if (filter != $_filter && filter!='All') {
          $self.addClass('filter-inactive');
        } else {
          $self.removeClass('filter-inactive');
        }
       

      } //filter
      
      /* ---------------------------------- */
       
      function on_detail_seek(e,product_id) {

        if ($_id == product_id) {

          _isSeekComplete = false;
          
          $self.addClass('active');

          _load();

        } else {

          if ($self.hasClass('active')) {
            $self.find('[data-controller=Expandable]').each(function(){
              $(this)
              .removeClass('active')
              .height('auto')
              .css({overflow: 'auto'});
            });
            $self.removeClass('active');
          }

        }

      }

      function on_detail_seek_complete() {

        if($self.hasClass('active')) {

          _isSeekComplete = true;

          // Make the details stuff expandable.
          if(_loaded_detail == true)
            $header.find('[data-controller=Expandable]').each(function(){$(this).Expandable();});

          // Omniture
          $.SiteModel.setDetailID(_id);
          $.SiteModel.setDetailName(_name);
          var result = $.AutoTracker.v();
          result['pageName'] = 'products>detail>inline>' + _id + '>' + _name;
          // result['props']['prop17'] = 'inline content';
          $.tracker.track(result['pageName'], result['props']);

        }

      }
      
      function on_detail_open(e,category) {
      
      }
    
      function on_detail_close(e,category) {
      
        // Always reset after close.
        _reset();
        /*
        if (category != $_category)
           _reset(); 
        */
      }
      
      function on_detail_complete(e) {
        _calibrate_width();
      }
      
      function on_click(e) {
      
        if (!$body.hasClass($.Views.BROWSE) && !$self.hasClass('active')) { 
          
          e.stopImmediatePropagation();
          e.preventDefault();
          $owner.triggerHandler($.Events.DETAIL_INIT,$_id);
        
        }
      
      }
      
      /* ---------------------------------- */
      
      function _reset() {

          $self
           .stop()
           .removeClass('active')
           .css({opacity:1,minWidth:'140px'});
           
      }
      
      function _calibrate_width() {
        
        var viewwidth = $(window).width() > 1000 ? $(window).width() : 1000;
        
        if ($owner.hasClass($.Views.DETAIL))
          $self.css({minWidth:viewwidth});
        
      }
      
      /* ---------------------------------- */
      
      /* LOAD DETAIL */
      
      function _load() {
                
        if (!_loaded_detail && !_loading){
          var jsonURL = $.Paths.BASE + 'products/item/id/' + $_id + '/request/ajax';

          $.ajax({
              dataType:'json',
              beforeSend: _before_send,
              error: _on_error,
              success: _on_success,
              data:{
                xmlhttp: true
              },
              url: jsonURL
            });
        }
      
      }
      
      function _before_send() {
        
        _loading = true
        
      }
      
      function _on_error() {
        
      }
      
      function _on_success(response) {
        
        if(response) {
      
          $self.removeClass('loading');
        
          var $section = $('<section/>').addClass('description');
        
          if($.browser.msie)
            $section.append( $(innerShiv(response.description), false) );
          else
            $section.html(response.description);
        
          $section.find('[data-controller=ShadeProxy]').each(function(){$(this).ShadeProxy({owner:$owner})});
        
          // Omniture
          $.SiteModel.setDetailID(_id);
          $.SiteModel.setDetailName(_name);
          $section.find('[data-controller=ShareTracking]').each(function(){$(this).ShareTracking();});
          $section.find('[data-controller=ProductStoreTracking]').each(function(){$(this).ProductStoreTracking();});
        
          $header.append($section);
        
          $img = $(response.detailimage).appendTo($figure);
        
          $figure.Preload({image:'img.product-view'});
        
          _loading = false;
        
          _loaded_detail = true;
        
          $self.ProductDetail({inline:true});
      	
          // Make the details stuff expandable.
          if(_isSeekComplete == true)
            $header.find('[data-controller=Expandable]').each(function(){$(this).Expandable();});
          
        }
      }

    }); 
   
  }  // ProductItem 
      

  $.fn.ProductTitle = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      var titles = {
    
      'Pierrefond': '<span>Pierre<mark>-</mark></span>fond',
      'Lauralhurst': '<span>Laural<mark>-</mark></span>hurst',
      'Beaconsfield': '<span>Bacons<mark>-</mark></span>field',
      'Pepperbush': '<span>Pepper<mark>-</mark></span>bush'
  
      }

      this.each(function() { 

         var $self = $(this),
             _display = $self.html();
         
         for (var title in titles) {
         
          if (_display.indexOf(title)>-1) {
            
            var d = _display.split(title).join(titles[title]);
           
            $self.html(d);
            
          }
          
         }
         
      });
      
  }//NIKE
    
})(jQuery); 

/* ---------------------------------- */

/* @Archive */

;(function($) {

  // Handles Archive up / down slat and state handling
  $.fn.Archive = function(settings) {
    
    var options = $.extend({}, $.fn.Archive.defaults, settings);
    
    return this.each(function(){
      
      // Private variables ---------------
      var $self = $(this),
          $body = $('body'),
          $win = $(window),
          $scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
          _currView = options.defaultView,
          _privateVar = false,
          _offset = 110,
          _currRowIndex = 0,
          _currRowHeight = 0,
          _totalRows = 0,
          _isAutoScrolling = false,
    

      // Private methods -----------------
      _onViewChange = function(e, viewId) {
        if(viewId != _currView) {
          _currView = viewId;
          _calcRowHeight();
        }
      },
    
      _calcRowHeight = function() {
        // Figure out how many <article>s there are per row, based on view type.
        _currRowHeight = $self.find('section section article:first').outerHeight(true);
        var $sections = $self.find('section section');
        // Figure out the height of each total.
        var totalSectionsHeight = 0;
        $sections.each(function() {
          totalSectionsHeight += $(this).height();
        });
        _totalRows = totalSectionsHeight / _currRowHeight;
        // Get the current row based on the scroll...
        _updateCurrentRowIndex();
      },
    
      _getSupposedCurrentRowIndex = function() {
        return Math.round($scroll.scrollTop() / _currRowHeight);
      },
    
      _updateCurrentRowIndex = function() {
        _currRowIndex = Math.round($scroll.scrollTop() / _currRowHeight);
      },
    
      _onKeyUp = function(e) {
        e.preventDefault();
        // See if this is different than the actual current row index.
        if(_getSupposedCurrentRowIndex() != _currRowIndex && !_isAutoScrolling) {
          _updateCurrentRowIndex();
        }
      
        if(_currRowIndex > 0) {
          _currRowIndex--;
          _scrollToNewRow();
        }
      },
    
      _onKeyDown = function(e) {
        e.preventDefault();
      
        if(_getSupposedCurrentRowIndex() != _currRowIndex && !_isAutoScrolling) {
          _updateCurrentRowIndex();
        }
      
        if(_currRowIndex < _totalRows - 1) {
          _currRowIndex++;
          _scrollToNewRow();
        }
      },
    
      _scrollToNewRow = function() {
        var destScroll = _currRowIndex * _currRowHeight;
        destScroll += _offset;
        _isAutoScrolling = true;
        $body.triggerHandler($.Events.SCROLLTO, destScroll);
      },
    
      _onScrollComplete = function() {
        _isAutoScrolling = false;
      };
      
      // Finally, initialize our object.
      if(!GLOBAL_IS_MOBILE) {
      
        _calcRowHeight();
    
        // Bind the view change events.
        $body
          .bind($.Events.VIEW, _onViewChange)
          .bind($.Events.KEY_UP, _onKeyUp)
          .bind($.Events.KEY_DOWN, _onKeyDown)
          .bind($.Events.SCROLL_COMPLETE, _onScrollComplete);
      }
      
    });
    
  };

  // Default Options
  $.fn.Archive.defaults = {
    defaultView: 'XSMALL'
  };

})(jQuery);
  
/* ---------------------------------- */

/* @ArchiveItem */

;(function($) {

  $.fn.ArchiveItem = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 

          var $self = $(this),
              $body = $('body'),
              $figure = $self.find('figure'),
              $title = $self.find('h3').ProductTitle(),
              $_lrg_img = $figure.attr('data-large'),
              $_img = $('<img/>').addClass('large'),
              _loading = false,
              _loaded = false;
              
          $body
          .bind($.Events.VIEW,on_view);
          
          $figure.Preload({image:'img'});
         
          function on_view(e,v) {
          
            if ($.Views[v]) {
        
              if (!_loading && !_loaded && $_lrg_img)
                _load();
              
            } else {
            
            
            }
          
          }
          
          function _load() {
          
            
            $figure.addClass('loading');
            
            $_img
            .bind('load',on_img_load)
            .attr('src',$_lrg_img);
            
            _loading = true;
            
          
          }
          
          function on_img_load(e) {
          
            $_img
            .appendTo($figure)
            .animate({opacity:1},1000,'easeInOutQuart');
            
            _loading = false;
            
            _loaded = true;
          
          }
          

              
      });
      
  }//NIKE
    
  

})(jQuery);

/* ---------------------------------- */

/* @KeyboardTooltip */

;(function($){
  
  $.fn.KeyboardTooltip = function(options) {
    
    var config = $.extend({}, options);
    
    return this.each(function(){
      
      var $self = $(this),
          $wrapper = $('#wrapper'),
          $win = $(window),
          _w = 634,
          _h = 371,
          $tooltip = $('<div id="keyboard-tooltip"/>').css({opacity: 0});
      
      $self.mouseover(function(e){
        
        var targetX = (($win.width() - _w) / 2);
        var targetY = (($win.height() - _h)  / 2);
        
        $tooltip
          .css({left: targetX + 'px', top: targetY + 'px'})
          .appendTo($wrapper)
          .stop()
          .animate({opacity: 1}, 1000, 'easeOutExpo');
      });
      
      $self.mouseout(function(e){
        $tooltip
          .stop()
          .animate({opacity: 0}, 400, 'easeOutExpo', function(){
            $(this).detach();
          });
      });    
      
    });
    
  };
  
})(jQuery);

/* ---------------------------------- */

/* @Utility */

;(function($) {

  $.fn.Utility = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 
      
        var $self = $(this),
            $body = $('body'),
            $nav = $('#navigation'),
            $scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
            $filters = $self.find('li[data-filter]'),
            $views = $self.find('li[data-view]'),
            $sections = $self.find('li[data-section]'),
            $ul = $self.find('ul'),
            $_navs = $self.find('nav'),
            $_autohide = $self.attr('data-autohide'),
            _active_filter = '',
            _mouse = false,
            _timeout = 0,
            _speed = 350,
            _active = true,
            __MAX_TOP = 100,
            __MIN_TOP = ($_autohide=='false') ? __MAX_TOP : $_navs.length>1 ? -50 : 70,
            $keyboard = null;
            
        // Add a keyboard mark if not mobile.
        if(!GLOBAL_IS_MOBILE) {
          // Only append keyboard in specific instances.
          var s = $.SiteModel.getSection(),
              ss = $.SiteModel.getSubsection();
          
          if( (s == $.SiteModel.SECTION_PRODUCTS && ss == '') ||
              (s == $.SiteModel.SECTION_TEAM && ss == '') ||
              (s == $.SiteModel.SECTION_ARCHIVE) ||
              (s == $.SiteModel.SECTION_FAMILY && ss == '') )
          {
            var $firstNav = $self.find('nav.utility:first-child');
            $keyboard = $('<mark/>').addClass('keyboard').css({
                                                                    display: 'inline',
                                                                    position: 'absolute',
                                                                    right: parseInt($firstNav.css('padding-left')) + 20,
                                                                    top: 4
                                                                    });
            $keyboard.appendTo($firstNav);
            $keyboard.KeyboardTooltip();
          }
        }
        
        $sections.each(function(i){ new UtilitySection($(this),i)});

        
        init();
        
        
        
        /* ---------------------------------- */
       
        /* REGISTER EVENTS */
        
        $(window)
        .bind('scroll',on_scroll);
        
        $nav
        .bind('mouseenter',nav_on_mouseenter)
        .bind('mouseleave',nav_on_mouseleave);
          
        /* ---------------------------------- */
        
        function init() {
            
          _clearTimer();
            
          _setTimer();
        
        }
        
        function on_scroll(e) {
          
          if ($(window).scrollTop()==0) {
          
            _open();
            
            init();
            
          } else { 
          
            if (!_mouse && _active) {
          
             _hide();
            
            }
          
          }
          
        }
        
        function nav_on_mouseenter(e) {

          _mouse = true;
          
          _open();
                    
          _clearTimer();
          
        }
        
        function nav_on_mouseleave(e) {
         
         _mouse = false;
          
         _hide();         
         
          
        }
         
        /* ---------------------------------- */
        
        function _open() {
          
          _active = true;
          
          _seek(__MAX_TOP,1);
          
        }
        
        function _hide() {
          
          _clearTimer();
          
          _active = false;
          
          _seek(__MIN_TOP,0);
          
        }
        
        function _seek(top,opacity) {
        
          $self.stop().animate({top:top},_speed,'easeInOutQuart');
          
          $ul.stop().animate({opacity:opacity},_speed,'easeInOutQuart');
          
          if (opacity<1){
            $self.addClass('_collapse');
          } else {
            $self.removeClass('_collapse');
          }
          
          if($keyboard) {
            $keyboard.stop().animate({opacity:opacity}, _speed, 'easeInOutQuart');
          }
        
        }
        
        function _setTimer() {
        
          if (!_mouse) {
            
            _timeout = setTimeout(function() {_hide();},2000);
            
          }
        
        }
        
        function _clearTimer() {
          
            clearTimeout(_timeout);
          
            _timeout = 0;
        
        }
        
        
        function _top() {
          
          
          var scrollTop = $(window).scrollTop();
          
          var top = (scrollTop>350) ? __MAX_TOP - (scrollTop-350) : __MAX_TOP;
        
          if (top<__MIN_TOP) 
            top = __MIN_TOP;
          
          return top;
        
        }
        
        function _opacity() {
        
          var scrollTop = $(window).scrollTop();
          
          return (scrollTop>350) ? 1 - (scrollTop-350)/100 : 1;
          
        }
          
        function UtilitySection($section,i) {

          var $span = $section.find('span'),
              $_id = $section.attr('data-section'),
              $section = $('#' + $_id),
              $_top = 0,
              _count = 0,
              _counting = 0,
              _countdir = 1,
              _intervalrate = 30 + 20*i,
              _interval;
          
          _detect_top();

          /* ---------------------------------- */
          
          /* REGISTER EVENTS */
          
          $body
          .bind($.Events.UTILITY_COUNT,on_section_count)
          .bind($.Events.SECTION_SEEK,on_section_seek)
          .bind($.Events.FILTER,on_filter)
          .bind($.Events.VIEW,on_filter);
          
          /* ---------------------------------- */
          
          function on_section_count(e,id,index) {
         
            if (id==$_id) {
    
              _calibrate(index);
              
            }
          
          }
          
          function on_section_seek(e,pathname) {
            
            if (pathname == $_id) {
              setTimeout(function(){$body.triggerHandler($.Events.SCROLLTO,$_top);},2);
            }
          }
          
          function on_filter(e) {
             
            setTimeout(function(){_detect_top();},1);
          
          }
          
          /* ---------------------------------- */
          
          /* UTILITIES */
          
          function _detect_top() {
            
             if ( $section.length>0 )
              $_top = $section.offset().top;
            
          
          }
          
          function _calibrate(c) {
        
            if (c!=_count) {
            
                _countdir = (c > _count) ? 1 : -1;
                        
                _count = c;
              
                clearInterval(_interval);
               
                _interval = setInterval(_tick,_intervalrate);
            
              
            
            } else {
              
            }
          
          }
          
          function _clear() {
          
            clearInterval(_interval)

          }
          
          function _tick() {
          
            _counting+=_countdir;
            
            if (_counting<=0)
              _counting = 0;
            
            if (_counting == _count || _counting == 0)
              clearInterval(_interval);
            
            $span.html(_counting.toString());
            
          
          }
        
        } // UtilitySection
        
       
        
        /* ------------------------------------ */ 
        
        function UtilityFilter($filter) {
        
          var $a = $filter.find('a'),
              $data = $filter.attr('data-filter'),
              $default = $filter.attr('data-default'),
              $_rel = $a.attr('rel');
          
          //$filter.bind('click',on_click)
          
          function on_click(e) {
          
            $body.triggerHandler($.Events.FILTER,$data);
            
            $body.triggerHandler($.Events.FILTER_COMPLETE,$data);
            
            e.preventDefault();
            
          
          }
          
        
        } // UtilityFilter
        
        
        function UtilityView($view) {
        
          var $a = $view.find('a'),
              $default = $view.attr('data-default'),
              $_rel = $a.attr('rel');
        
          //$view.bind('click',on_click);
          
          function on_click(e) {
          
            $body.triggerHandler($.Events.VIEW,$view.attr('data-view'));
            
            e.preventDefault();
            
          }

        } // UtilityView

      });
      
  }//NIKE
    
  

  $.fn.UtilityProducts = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 
      
      
        var $self = $(this),
            $navs_filters = $self.find('li[data-filter]'),
            $navs_views = $self.find('li[data-view]')
            $default_filter = $self.find('li[data-filter][data-default]'), 
            $default_view = $self.find('li[data-view][data-default]'), 
            $mens = $self.find('li[data-filter=Mens]'),
            $womens = $self.find('li[data-filter=Womens]'),
            //$all = $self.find('li[data-filter=All]'),
            //$grid = $self.find('li[data-view=Grid]'),
            $browse_button = $self.find('li[data-view=BROWSE]'),
            _view = '',
            _filter = '';
          
        if(GLOBAL_IS_MOBILE) {
          // Hide browse for mobile OSes.
          $browse_button.css({display: 'none'});
        }

        
        $.address.bind('change',on_address_change);
        
        
        function on_address_change(e) {
        
          var pathNames = e.pathNames,
              _key = pathNames.toString().split(':')[0],
              _value = pathNames.toString().split(':')[1];
              
          if (pathNames.length>0) {
          
            if(_key=='view') {

              _filter = ''; 
              
              /*
              DEPRECATED             
              if(_value=='BROWSE') {
                //_disable($womens)
                //_disable($mens)
              } else {
                //_enable($womens)
                //_enable($mens)
              }*/
              
              _view = _value;
              
            }
            
            if(_key=='filter') {
            
              _filter = _value;
              
            }
               
          }
          
        
          $navs_filters.each(function(){
          
            if ($(this).attr('data-filter')==_filter)
              $(this).find('a').addClass('active');
            else
              $(this).find('a').removeClass('active');
          
          });
          
          $navs_views.each(function(){    
            if ($(this).attr('data-view')==_view)
              $(this).find('a').addClass('active');
            else
              $(this).find('a').removeClass('active');
          })


        
          if (_filter=='')
            $default_filter.find('a').addClass('active');


          if (_view=='')
            $default_view.find('a').addClass('active');
   
           
       
        
        }
        
        

              
      });
      
  }
    
  

  

})(jQuery);  

/* ---------------------------------- */

/* @Nike */

;(function($) {

  $.fn.Nike = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 
      
        var $body   = $('body'),
            $scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
            _view = '',
            _filter = '',
            _offset = 110,//140,
            _scrolling = false,
            _initialized = false;
        
        if(GLOBAL_IS_MOBILE) {
          _offset = 0;
          // Adjust the utilty nav so that we don't have keyboarding stuff.
          $('._browse nav.utility:first-child').css({backgroundImage: 'none'});
        }
            
        /* ---------------------------------- */
                
        // Initialize the Omniture tracker
        var browser = yourBro[2].toUpperCase(),
		    flVer = '';
    		if(FlashDetect.installed === true)
    		{
    			flVer = browser + ' ' + FlashDetect.major + ',' + FlashDetect.minor + ',' + FlashDetect.revision;
    		}
        var trackerPrefix = 'USSNW>',
            trackerGlobals = {
    			channel: 'nikesnowboardingus',
    			server: 'nikesnowboarding',
    			pageType: '',
    			prop2: flVer,
    			prop13: 'us',
    			prop14: 'us',
    			prop15: 'en_us',
    			prop21: 'brand',
    			prop22: 'non-id',
    			prop23: 'content'
    		};
    		trackerGlobals.evar8 = trackerGlobals.prop27 = trackerGlobals.prop13+'|'+trackerGlobals.prop14+'|'+trackerGlobals.prop15;
    	
    		$.tracker.init(trackerPrefix, trackerGlobals);
        
        // See if we need to track a 404.
        var track404 = false;
        if(typeof GLOBAL_PAGE_IS_404 != 'undefined') {
          if(GLOBAL_PAGE_IS_404 == true) {
            track404 = true;
          }
        }
        
        if(track404 == false) {
      		// Initialize the SiteModel section state.
      		$.SiteModel.update();
      		// Track the page view.
      		$.AutoTracker.t();
      		// Set up navigation tracking links.
      		$body.find('a[data-link-track]').LinkTracking();
    		} else {
    		  $.tracker.track('', {pageType: '404'});
    		}
		
        /* ---------------------------------- */
        
        // Check to see if this is the archive, and if so, we need to set the _view
        if($.SiteModel.getSection() == $.SiteModel.SECTION_ARCHIVE) {
          if($body.hasClass($.Views.XSMALL)) {
            _view = $.Views.XSMALL;
          }
        }
        
        if (!$body.hasClass($.Views.SEARCH))
          $body.Keyboard();
        
        $.ajaxSetup({
           cache: false,
           dataType: 'html',
           global: false,
           timeout: 5000           
        });
        
        if(!GLOBAL_IS_MOBILE) {
          setTimeout('scrollTo(0,0)',2);
        } else {
          setTimeout('scrollTo(0,1)', 50);
        }
        
        _calibrate();
        
        if ($.browser.msie) IE();
    
        /* ---------------------------------- */
        
        /* REGISTER EVENTS */
        
        $body
        .bind($.Events.SCROLL,on_scroll)
        .bind($.Events.SCROLLTO,on_scrollto)
        .bind($.Events.FILTER,on_filter)
        .bind($.Events.VIEW,on_view)
        .bind('mousewheel',on_mouse_wheel);
        
        $(window).bind('resize',_calibrate);
        
        $.address.bind('externalChange',on_address_change);
        $.address.bind('internalChange',on_address_change);
        
        $('section.container header h2').Top();
        
        /* ---------------------------------- */
        
        function _calibrate(e) {
        
          if ($(window).width()<=1024 + 100) 
            $body.addClass($.Views._1024);
          else
            if ($body.hasClass($.Views._1024))
              $body.removeClass($.Views._1024);
            
        }
        
        function on_address_change(event) {
          
          var pathNames = _parsePath(event.pathNames);
          
          if(pathNames.VIEW) {
            $body.triggerHandler($.Events.VIEW,pathNames.VIEW);
            $body.triggerHandler($.Events.FILTER,'All');
          }
            
          if(pathNames.FILTER)
            $body.triggerHandler($.Events.FILTER,pathNames.FILTER);
            
          if(pathNames.SECTION) 
            $body.triggerHandler($.Events.SECTION_SEEK,pathNames.SECTION);
          
          // Omniture
          if(typeof event.pathNames != 'undefined' && event.pathNames != '')
          {
            switch($.SiteModel.getSection())
            {
              case $.SiteModel.SECTION_PRODUCTS:
                $.SiteModel.setDetailID('');
                $.SiteModel.setDetailName('');
                var t = $.AutoTracker.v();
                t['props']['prop17'] = ($.SiteModel.getView() == 'grid' || $.SiteModel.getView() == '') ? 'product grid' : 'product list';
                if(pathNames.VIEW) {
                  // debug.log("NEW VIEW CHANGE: " + $.SiteModel.getView());
                  t['pageName'] += '>mode>' + $.SiteModel.getView();
                  $.tracker.track(t['pageName'], t['props']);
                } else if (pathNames.FILTER) {
                  // debug.log("NEW FILTER CHANGE: " + $.SiteModel.getFilter());
                  t['pageName'] += '>filter>' + $.SiteModel.getFilter();
                  $.tracker.track(t['pageName'], t['props']);
                } else if (pathNames.SECTION) {
                  // debug.log("NEW SECTION CHANGE: " + pathNames.SECTION);
                  t['pageName'] += '>category>' + pathNames.SECTION;
                  $.tracker.track(t['pageName'], t['props']);
                }
                break;            
              case $.SiteModel.SECTION_ARCHIVE:
                if(pathNames.SECTION){
                  var t = $.AutoTracker.v();
                  t['pageName'] += '>category>' + pathNames.SECTION;
                  t['props']['prop19'] = pathNames.SECTION;
                  $.tracker.track(t['pageName'], t['props']);
                } else if (pathNames.VIEW){
                  var t = $.AutoTracker.v();
                  t['pageName'] += '>grid>' + pathNames.VIEW.toLowerCase();
                  $.tracker.track(t['pageName'], t['props']);
                }
                break;
            }
          }
              
          if (!_initialized) {
             
             if (!pathNames.FILTER)
              $body.triggerHandler($.Events.FILTER,'All'); 
             
             _initialized = true;
          }
                  
        }
        
        function _parsePath(pathNames) {
        
          
          var pathData = [];
          
          for (var i=0;i<pathNames.length;i++) {
          
            var data = pathNames[i].split(':');
            
            pathData[data[0].toUpperCase()] = data[1];
          
          }
          
          return pathData;
        
        }
        
        
        
        function on_scroll(e,id) {
          
          var delay = 50;
        
          setTimeout(function() {
            
            var top = $('#'+id).offset().top - _offset;
            
            if($.isIPad()) {
              // Get the additional current scroll offset.
              top -= window.pageYOffset;
            }
          
            _scroll(top);
            
          }, delay);
        
        }
        
        function on_scrollto(e,top) {
        
          _scroll(top-_offset);
        
        }
        
        function on_filter(e,id) {
        
          $body
          .removeClass(_filter)
          .addClass('filter-'+id);
          
          _filter = 'filter-' + id;
          
          if($.SiteModel.getSection() == $.SiteModel.SECTION_PRODUCTS) {
            $.SiteModel.setFilter(id.toLowerCase());
            // debug.log("FILTER CHANGE :: view [" + $.SiteModel.getView() + "] | filter [" + $.SiteModel.getFilter() + "]");         
          }

        }
        
        function on_view(e,id) {
          
          $body
          .removeClass(_view)
          .addClass($.Views[id]);
          
          _view = $.Views[id];
          
          // Omniture
          // Figure out what the body class is.
          if($.SiteModel.getSection() == $.SiteModel.SECTION_PRODUCTS) {
            var isBrowse = $body.hasClass('_browse');
            $.SiteModel.setView(isBrowse ? 'browse' : 'grid');
            // debug.log("VIEW CHANGE :: view [" + $.SiteModel.getView() + "] | filter [" + $.SiteModel.getFilter() + "]");
          }
        }
        
             
        /* ---------------------------------- */
        
        /* UTILITIES */
        
    
    
        function IE() {
        
          $('*:last-child').addClass('_last');
          $('*:first-child').addClass('_first');
          
        }
    
        
        function _scroll(scrollTop) {
        
          _scrolling = true;
          
          $scroll.stop().animate({scrollTop:scrollTop},750,'easeInOutQuart',function(){ _scrolling=false; $body.triggerHandler($.Events.SCROLL_COMPLETE); });
          
        }
        
        function on_mouse_wheel(e){
        
          if (_scrolling) {
          
            $scroll.stop();
            
            _scrolling = false; 
          }
        
        }
        
      

              
      });
      
  }; //NIKE
    
  
})(jQuery);    

/* ---------------------------------- */

/* @Keyboard */

;(function($) {

  $.fn.Keyboard = function(settings) {

    var config = {};

    if (settings) $.extend(config, settings);

    return this.each(function() {

      var $self = $(this),
          $owner = config.owner,
          $body = $('body'),
          isAltCommandDown = false;

      $(document)
        .bind('keydown',on_keydown)
        .bind('keyup',on_keyup);

      function on_keyup(e) {

        var key = e.which;
        if(key == 18 || key == 224) {
          if(isAltCommandDown) {
            isAltCommandDown = false;
          }
        }

        $self.triggerHandler($.Events.KEY_RELEASE);

      };

      function on_keydown(e) {

        // var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        var key = e.which;

        if(key == 18 || key == 224) {
          isAltCommandDown = true;
        }

        switch(key) {

          case 38: //top

            $self.triggerHandler($.Events.KEY_UP);
            if ($body.hasClass($.Views.BROWSE) || $body.hasClass('_archive') || $body.hasClass('_products')) {
              e.preventDefault();
            }
            break;

          case 39: //right

            if(!isAltCommandDown) {
              $self.triggerHandler($.Events.KEY_RIGHT);
              if($.SiteModel.getSection() != $.SiteModel.SECTION_STORE_LOCATOR) {
                e.preventDefault();
              }
            }
            break;

          case 40: ///bottom

            $self.triggerHandler($.Events.KEY_DOWN);
            if ($body.hasClass($.Views.BROWSE) || $body.hasClass('_archive') || $body.hasClass('_products')) {
              e.preventDefault(); 
            }
            break;

          case 37: //left

            if(!isAltCommandDown) {
              $self.triggerHandler($.Events.KEY_LEFT);
              if($.SiteModel.getSection() != $.SiteModel.SECTION_STORE_LOCATOR) {
                e.preventDefault();
              }
            }
            break;

          case 13: // enter

            if($.SiteModel.getSection() != $.SiteModel.SECTION_STORE_LOCATOR) {
              e.preventDefault();
            }
            $self.triggerHandler($.Events.KEY_ENTER);
            break;

          case 27: // esc

            $self.triggerHandler($.Events.KEY_ESC);
            e.preventDefault();
            break;

        }//switch
          
      }; // End on_keydown()
      
    }); // End jQuery.each();

  }; // End jQuery.Keyboard plugin

})(jQuery);

/* ---------------------------------- */

/* @Browse */

;(function($) {

  $.fn.Browse = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      var _total = this.length,
          $content = $('#content'),
          _adjustedHeight = false;
      
      //to make sure browse mode has enough height to autoscroll

      if (this.length>0 && !_adjustedHeight) {
        
        $content.css({minHeight: $content.outerHeight()+$(window).height()});
      
        _adjustedHeight = true;
        
        $('[data-browse]:last-child').addClass('_borderfix');
        
      }
      
      
      
      this.each(function(index) { 

        var $self = $(this),
            $body = $('body'),
            $scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
            $_top = $self.offset().top,
            $links = $self.find('a'),
            _linkIsExternal = false,
            _destURL = '',
            _detectTop = 400,
            _navoffset = 120,
            _detectTopOffset = 0,
            _detectHeight = 200,
            _active = 0;
        
        $links.each(function() {
          var href = $(this).attr('href');
          if(href != '#' && href != '') {
            if(_destURL == '') {
              _destURL = href;
              if(_destURL.indexOf(window.location.host) < 0) {
                _linkIsExternal = true;
              }
            }
          }
        });
        
        if ($('section.container')) {
          
          _detectTop = $('section.container:first-child').offset().top - 50;
         
        } 

        /* ---------------------------------- */
        
        /* REGISTER EVENTS */
        
        $(window)
        .bind('scroll',on_scroll);
        
        $body
        .bind($.Events.BROWSE_DETAIL,on_browse_detail)
        .bind($.Events.KEY_RIGHT,on_key_down)
        .bind($.Events.KEY_DOWN,on_key_down)
        .bind($.Events.KEY_UP,on_key_up)
        .bind($.Events.KEY_LEFT,on_key_up)
        .bind($.Events.VIEW,on_view_change)
        .bind($.Events.KEY_ENTER,on_key_enter);
        
        $self
        .bind('click',on_click);
        
        function on_scroll(e) {
          
          //DBUG: $self.html($self.offset().top + " : "+ $(window).scrollTop() + " : " + ($self.offset().top-$(window).scrollTop()))
          
          var adjusted_y = ($self.offset().top-$(window).scrollTop());
          
          if ($body.hasClass($.Views.BROWSE)) {
            if (adjusted_y > (_detectTop + _detectTopOffset) && adjusted_y < (_detectTop+_detectHeight)) {
              $self.addClass('active');
              
            } else {
              
              if (adjusted_y <_detectHeight || adjusted_y > _detectTop ) {
                $self.removeClass('active'); 
              }
              
            }
            
          }
        }
        
        function on_key_down(e) {
          
          _active++;
          
          if (_active>=_total)
            _active = _total;
          
          if (_active==index)
            _scroll();
            
        }
        
        function on_key_up(e) {
          
          _active--;
          
          if (_active<0)
            _active = 0;
          
          if (_active==index)
            _scroll();
            
        }
        
        function on_key_enter(e) {
          
          if($body.hasClass($.Views.BROWSE)) {
            if($self.hasClass('active')) {
              window.location = _destURL;
            }
          }
          
        }
        
        function on_browse_detail(e,id) {
          if (id==index) {
            $self.addClass('active');
          } else {
            $self.removeClass('active');
          }
        }
        
        function on_click(e) {

          if ($body.hasClass($.Views.BROWSE))
            _scroll();
          
          if (!$self.hasClass('active'))
            e.preventDefault();
        }
        
        function on_view_change(e,view) {
        
          if ($body.hasClass($.Views.BROWSE)){
          
            setTimeout(
              function(){
                $_top = $self.offset().top;
              },1);
          
          }
        
        }
        

        /* ---------------------------------- */
        
        function _scroll() {        
          if ($body.hasClass($.Views.BROWSE)) {
            $scroll.stop().animate({scrollTop:$_top-_navoffset},750,'easeOutQuart');
          }
        }
              
      });
      
  }//NIKE
    
  

})(jQuery); 


/* ---------------------------------- */

/* @Shade and @ShadeProxy */

;(function($) {

 $.fn.ShadeProxy = function(settings) {
     

    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 

        var $self = $(this),
            $_id = $self.attr('data-id'),
            $body = $('body');
            
        $self.bind('click',
        
          function(e) {

            config.owner.triggerHandler($.Events.SHADE,$_id);
            
            e.preventDefault();
            
        })
              
      });
      
  }//NIKE

 $.fn.Shade = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      var $body = $('body');
      
      this.each(function(index) { 
      
        var $self = $(this),
            $galleryId = -1,
            $owner = config.owner,
            _active = false,
            _prev_height = 0,
            $activeSlideshow = null;
        
        init();
        
        /* ---------------------------------- */
        
        /* REGISTER EVENTS */
            
        $owner
        .bind($.Events.SHADE,on_shade);
        
        $body
        .bind($.Events.DETAIL_OPEN,on_detail_close)
        .bind($.Events.VIEW,on_detail_close)
        // IN PROGRESS
        .bind($.Events.FILTER,on_detail_close)
        .bind($.Events.KEY_ESC,on_esc);
        //.bind($.Events.SECTION_SEEK,on_detail_close);
        
        /* ---------------------------------- */
        
        function init() {

          $self.addClass('shade');
        
          $self.prependTo($owner);
          
          if (config.mode)
            $self.addClass(config.mode);
          
        }
        
        function on_shade(e,index) {
          $galleryId = index;

          $body.triggerHandler($.Events.SHADE_OPEN);
          
          $self.addClass('loading');
          
          _active = true;
          
          $self.animate({height:'100%'},1000,'easeInOutQuart',_load);
          
          $body.triggerHandler($.Events.SCROLLTO,$self.offset().top);
        
        }
        
        function on_esc(e) {
          if(_active) {
            _close();
          }
        }
        
        function on_detail_close(e) {
          
          if (_active) {
            _close();
          }
        
        }
        
        function on_close(e) {
          
          _close();
         
          e.preventDefault();
        }
        
        
        function _close() {
        
          $body.triggerHandler($.Events.SHADE_CLOSE);
          
          if($activeSlideshow != null) {
            $activeSlideshow.destroy();
            $activeSlideshow = null;
          }
          
          _active = false;
          
          $owner.css({height:'auto'});
          
          $self.animate({height:'0'}, 750, 'easeInOutQuart', function(){
            $self.html('');
            $body.triggerHandler($.Events.SHADE_CLOSE_COMPLETE);
          });
          
        }
        
        function _load(e) {
          
          var ajaxURL = $.Paths.BASE + 'gallery/view/id/' + $galleryId + '/request/ajax';
          $.ajax({
              beforeSend: _before_send,
              error: _on_error,
              success: _on_success,
              data:{
                xmlhttp: true
              },
              url: ajaxURL
            });
        
        }
        
        function _before_send() {
 
        }
        
        function _on_error() {}
        
        function _on_success(response) {
          
          $self.removeClass('loading');
          
          
          if ($.browser.msie)
            $self.html( $(innerShiv(response), false) );
          else
            $self.html(response);
          
          $slideshow = $self.find('[data-controller=Slideshow]');
          
          $activeSlideshow = $slideshow.Slideshow({inline:true,container:$self});
          
          var $close = $('<a/>').addClass('shade-close').attr('href','#/close').html('close').bind('click',on_close).appendTo($self);
          
          
          if ($slideshow) {
            
            if ( $slideshow.attr('data-height') ) {
              
              var slideshow_height = parseInt($slideshow.attr('data-height'));
              
              if ($owner.height() < slideshow_height) {
            
                _prev_height = $owner.height();
                
                $owner.animate({height:slideshow_height},450,'easeInOutQuart');
              
            
              }
              
            }
          
          }
          
        
        }
        
              
      });//Shade
  }

})(jQuery);  


/* ---------------------------------- */

/* @Slideshow and @SlideshowSlide */

;(function($) {
  
  $.fn.Slideshow = function(settings) {
    var config = {};

    if (settings) $.extend(config, settings);
    
    // Handle multiple slideshow elements
    if(this.length > 1) {
      this.each(function(){
        $(this).Slideshow(config);
      });
      return this;
    }
    
    // Now handle the individual ones.
    var $self = $(this),
        $body = $('body'),
        $figures = $self.find('figure'),
        $img = $self.find('figure img'),
        $slides = $self.find('.slides'),
        $keyboard = $('<mark/>').addClass('keyboard'),
        $left = $('<a/>').addClass('arrow-left').attr('href','#/previous'),
        $right = $('<a/>').addClass('arrow-right').attr('href','#/next'),
        $_content_height = parseInt( $self.attr('data-height') ),
        $touchwipe = null,
        _min_height = 500,
        _active = 0,
        _name = $self.attr('data-name'),
        _id = $self.attr('data-id'),
        _trackingPrefix = '>gallery>' + _id + '>' + _name + '>media>';

    /* ---------------------------------- */
    
    this.initialize = function() {
      
      $(window).bind('resize', _calibrate);

      if (isNaN($_content_height))
        $_content_height = _min_height;

      if (config.inline == true) {
        if (config.container.height() > $_content_height)
          $_content_height = config.container.height();
      } else {
        $keyboard.css({right: 20});
      }

      if ($figures.length>1) {
        $left.appendTo($self);
        $right.appendTo($self);
        $keyboard.appendTo($self);
      }

      $slides.css({height: $_content_height});

      $self.css({height:$_content_height});

      $figures.SlideshowSlide({parent_height:$_content_height});

      // Omniture
      // Track the first gallery image view.
      $.SiteModel.setGalleryName(_name);
      $.SiteModel.setGalleryID(_id);
      $.SiteModel.setMediaID('0');
      $.SiteModel.setMediaType($figures.first().attr('data-type'));
      var result = $.AutoTracker.v();
      result['props']['prop17'] = 'gallery';
      $.tracker.track(result['pageName'] + _trackingPrefix + $.SiteModel.getMediaType() + '>' + $.SiteModel.getMediaID(),
                      result['props']);

      _calibrate();

      /* ---------------------------------- */
      // Bind all interaction events.
      
      $body
      .bind($.Events.KEY_RIGHT,on_right)
      .bind($.Events.KEY_LEFT,on_left);
        
      $left.bind('click', on_left);
      $right.bind('click', on_right);
      
      $keyboard.KeyboardTooltip();
      
      if(GLOBAL_IS_MOBILE) {
        $keyboard.css({display: 'none'});
      }
      
      if(GLOBAL_IS_IOS) {
        $touchwipe = $self.touchwipe({
          wipeLeft: function() {
            _seek(1);
          },
          wipeRight: function() {
            _seek(-1);
          },
          min_move_x: 40,
          preventDefaultEvents: false
        });
      }
      
      return this;
    };
    
    this.destroy = function() {
      
      // Unbind everything.
      
      $body
      .unbind($.Events.KEY_RIGHT, on_right)
      .unbind($.Events.KEY_LEFT, on_left);
        
      $left.unbind('click', on_left);
      $right.unbind('click', on_right);
      
      $(window).unbind('resize', _calibrate);
      
      if(GLOBAL_IS_IOS) {
        if($touchwipe != null) {
          $touchwipe.touchwipe('destroy');
          $touchwipe = null;
        }
      }
      
    };
    
    /* -----------------------------------
       Begin private methods
       ----------------------------------- */

    var on_left = function(e) {

      _seek(-1);

      e.preventDefault();

    };

    var on_right = function(e) {

      _seek(1);

      e.preventDefault();

    };

    var _seek = function(dir) {

      _active+=dir;

      if (_active<0) _active = $figures.length-1;

      if (_active>=$figures.length) _active = 0;

      $slides.stop().animate({marginLeft:-_active*$(window).width()},750,'easeInOutQuart',function(){

        // Omniture
        $.SiteModel.setMediaID(_active.toString());
        $.SiteModel.setMediaType($figures.eq(_active).attr('data-type'));
        var result = $.AutoTracker.v();
        result['props']['prop17'] = 'gallery';
        $.tracker.track(result['pageName'] + _trackingPrefix + $.SiteModel.getMediaType() + '>' + $.SiteModel.getMediaID(),
                        result['props']);

      });

    };

    var _calibrate = function() {

      $figures.each( function(index) {
        var w = $(window).width();
        $(this).css({position:'absolute',display:'block',left:w*index,top:0,width: w});
      });
      
      $slides.stop().css({marginLeft:-_active*$(window).width()});

    };
    
    return this.initialize();
    
  };
  
  $.fn.SlideshowSlide = function(settings) {

    var config = {};

    if (settings) $.extend(config, settings);

    this.each(function() { 

      var $self = $(this),
      $img = $self.find('img'),
      $loader = $('<img/>').one('load',on_load),
      $figcaption = $self.find('figcaption'),
      _imgHeight = 0,
      _loaded = false,
      _isVideo = false,
      _hasEmbeddedVideo = false;
      
      if($self.attr('data-type') == 'video') {
        _isVideo = true;
      }

      $(window).bind('resize',_calibrate);

      $img.css({opacity:0});

      if ($figcaption.length>0)
      $figcaption.css({opacity:0});

      $loader.attr('src',$img.attr('src'));

      $self.addClass('_preload');
      if($.SiteModel.getSection() == $.SiteModel.SECTION_NEWS || $.SiteModel.getSection() == $.SiteModel.SECTION_TEAM) {
        $self.css({marginTop: -75});
      } else {
        $self.css({marginTop: -140});
      }

      function on_load() {

        $self.removeClass('_preload');
        _imgHeight = $img.height();
        _loaded = true;

        setTimeout(function(){_calibrate()},1);

      }

      function _calibrate() {

        if (_loaded) {
          
          var content_height = 0;
          
          if(!_isVideo) {
            content_height = $img.height();

            if ($figcaption.length>0) {
              $figcaption.css({width: $img.width(),margin:'10px auto'});
              content_height += $figcaption.height();
            }
          
            $img.animate({opacity:1},750,'easeInOutQuart');
            $figcaption.animate({opacity:1},900,'easeInOutQuart');
            
          } else {
            
            if(!_hasEmbeddedVideo) {
              content_height = $img.height();
              _hasEmbeddedVideo = true;
              // Embed the video.
              var brightcoveId = $self.attr('data-brightcove');
              var imageId = $img.attr('id');
              var mediaId = $img.attr('alt');
              var videoName = $self.attr('data-videoname');
            
            	var v = $.AutoTracker.v();
            	$.video.embed(	imageId, 
                    					brightcoveId,
                    					mediaId,
                    					videoName,
                    					s_account,
                    					v['props']['prop18'],
                    					v['props']['prop19'],
                    					$img.width(),
                    					$img.height(),
                    					false,
                    					false,
                    					false,
                    					false
                    					);
            } else {
              content_height = $self.find('object').attr('height');
            }
            
          }          
          
          // Position the media.
          if($.SiteModel.getSection() == 'products') {
          	$self.css({marginTop:( config.parent_height - content_height ) / 7 });
		      } else {
            $self.css({marginTop:( config.parent_height - content_height ) / 4 });
          }

        }

      }

    });

  };//NIKE

})(jQuery); 


/* ---------------------------------- */

/* @Expandable */

;(function($) {

  $.fn.Expandable = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
    this.each(function() { 
      
      var $self = $(this),
          $a = $self.find('a.title'),
          $content = $self.find('.expand-content'),
          _startH = $a.height(),
          _expanded = false;

      $self.addClass('active');
      // Check if there are images inside of here.
      var imgs = $self.find('img');
      var _targetH = $content.height() + _startH;
      if(imgs.length > 0) {
        // _targetH = parseInt(imgs.first().attr('height')) + _startH;
        _targetH = _startH + 84;
      }
      $self.css('overflow', 'hidden');
      $self.height(_startH);
    	$content.css({opacity: 0});
      $self.removeClass('active');
      $a.bind('click', function on_click(e){
          if(!_expanded){
            // Omniture
            if($self.attr('data-type') == 'technical-specs') {
              var result = $.AutoTracker.v();
              result['pageName'] += '>techspecs';
              $.tracker.track(result['pageName'], result['props']);
            }
            $self.addClass('active');
          	$content.stop().animate({opacity: 1}, 750);
            $self.stop().animate({height: _targetH + 'px'}, 750, 'easeInOutExpo');
        
          } else {
            $content.stop().animate({opacity: 0}, 250);
            $self.stop().animate({height: _startH + 'px'}, 500, 'easeInOutExpo', function(){
              $self.removeClass('active');
            });
          }
          _expanded = !_expanded;
          e.preventDefault();
      });
      
    });
      
  }; // End jQuery.Expandable plugin

})(jQuery); 
    

/* ---------------------------------- */

/* @TeamDetail */

;(function($) {

  $.fn.TeamDetail = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
    this.each(function() { 

      var $self = $(this),
      $shadeproxy = $self.find('[data-controller=ShadeProxy]'),
      $body = $('body'),
      $teamDetail = $self.find('article.team-detail'),
      $prevLink = $teamDetail.find('a.arrow-left'),
      $nextLink = $teamDetail.find('a.arrow-right'),
      $keyboard = $self.find('mark.keyboard'),
      _prevUrl = $prevLink.attr('href'),
      _nextUrl = $nextLink.attr('href'),
      _isShadeOpen = false;

      if(GLOBAL_IS_MOBILE) {
        $keyboard.css({display: 'none'});
      }
      
      $keyboard.KeyboardTooltip();

      $('<section/>').Shade({owner:$self,mode:'light'});

      $shadeproxy.ShadeProxy({owner:$self});

      // Enable left/right arrow keys, and listen for the shade events so we know when to activate/deactivate them.
      $body
      .bind($.Events.SHADE_OPEN, on_shade_open)
      .bind($.Events.SHADE_CLOSE_COMPLETE, on_shade_close)
      .bind($.Events.KEY_LEFT, on_key_left)
      .bind($.Events.KEY_RIGHT, on_key_right)
      .bind($.Events.KEY_ESC, on_key_esc);

      function on_key_left() {
        if(!_isShadeOpen) {
          window.location = _prevUrl;
        }
      }

      function on_key_esc(e) {
        if(_isShadeOpen == false) {
          window.location = $.Paths.BASE + 'team';
        }
      }

      function on_key_right() {
        if(!_isShadeOpen) {
          window.location = _nextUrl;
        }
      }

      function on_shade_close() {
        _isShadeOpen = false;
      }

      function on_shade_open() {
        _isShadeOpen = true;
      }

    });
      
  }//TeamDetail
  
  
})(jQuery);


/* ---------------------------------- */

/* @ProductDetail */

;(function($) {

  $.fn.ProductDetail = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      
      this.each(function() { 

         var $self = $(this),
             $shadeproxy = $self.find('[data-controller=ShadeProxy]'),
             $figure = $self.find('figure'),
             $img = $figure.find('img.product-view'),
             $images = $self.find('a[data-parent=ProductDetail]'),
             $body = $('body'),
             $image_loader = $('<img/>'),
             _activeimage = $img.attr('src'),
             _loading = false,
             _shade = false;
         
         $self
         .bind($.Events.DETAIL_IMAGE,on_detail);
         
         
         if (!config.inline===true)
          $('<section/>').Shade({owner:$self,mode:'light'});
         
         $shadeproxy.ShadeProxy({owner:$self});
         
         $images.DetailImage({owner:$self});
         
         $image_loader.bind('load',on_load);
         
         function on_detail(e,path,index) {
         
           if (_activeimage != path && !_loading) {
           
            _activeimage = path;
            
            _loading = true;
            
            $img.stop().animate({opacity:0},600,'easeInOutQuart',function(){_load()})

           } 
           
         }
         
         function _load() {
            $img// = $('<img/>')
             .css({opacity:0})
             .one('load',on_load)
             .attr('src',_activeimage)
             .prependTo($figure);
         }
         
         function on_load() {

           _loading = false;
           
           $img.stop().animate({opacity:1},600,'easeInOutQuart');

           _trackDetailView();
         }

         function _trackDetailView() {
           // Omniture
           // Figure out which image this is.
           var src = $img.attr('src');
           var imgIndex;
           $images.each(function(index){
             var imgHref = $(this).attr('href');
             if(src == imgHref){
               imgIndex = index;
             }
           });
           // Invert this from the number of images.
           imgIndex = ($images.length - 1) - imgIndex;
           var result = $.AutoTracker.v();
           result['pageName'] += '>images>' + imgIndex;
           // result['props']['prop17'] = 'inline content';
           $.tracker.track(result['pageName'], result['props']);
         }

         
      });
      
  }//ProductDetail
  
  $.fn.DetailImage = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function(index) { 

         var $self = $(this),
             $_path = $self.attr('href'),
             $body = $('body');
         
         $self.bind('click',on_click);
         
         function on_click(e) {
         
          config.owner.triggerHandler($.Events.DETAIL_IMAGE,[$_path,index]);
          
          e.preventDefault();
         
         }
         
         
      });
      
  }//DetailImage
  
  
    
  

})(jQuery);
  
/* ---------------------------------- */

/* @Top */

;(function($) {

  $.fn.Top = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 

         var $self = $(this),
             $body = $('body');
         
         $self.bind('click',on_click);
         
         function on_click(e) {
         
            $body.triggerHandler($.Events.SCROLL,'wrapper');
            
            e.preventDefault();
         
         }
         
      });
      
  }//NIKE
    
  

})(jQuery);  

/* ---------------------------------- */

/* @Entry */

;(function($) {

  $.fn.Entry = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
    return this.each(function() { 
      
      var $preroll = $('#preroll'),
          $win = $(window),
          $a = $('a.next'),
          $body = $('body'),
          $navigation = $('nav#main'),
          $utility = $('#navigation-utility'),
          $wrapper = $('#wrapper').css({position: 'fixed', top: $win.height()}),
          $entry = $('#entry'),
          $enterButton = $('#enter-button'),
          $big_img = $('#preroll>img'),
          $big_img_w = $big_img.attr('width'),
          $big_img_h = $big_img.attr('height'),
          $stripes = $('#stripes'),
          $pattern = $('#pattern'),
          $overlay = $('#overlay'),
          $enter_site = $('#enter-site'),
          $scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $body,
          $cta = $('#cta'),
          _ctaHeight = $cta.height(),
          $backButton = $('<div id="back-button"/>').appendTo($wrapper);
          $backLink = $('<a href="#back" id="back-to-feature">Back</a>').appendTo($backButton),
          _scrollPoints = [200,2600],
          _offsetTop = 175,
          _entered = false,
          _isIE7 = ($.browser.msie && parseFloat($.browser.version) <= 7.0),
          $pane1 = $('<div class="intro-pane"/>').css({backgroundColor: '#000'}), // Black
          $pane2 = $('<div class="intro-pane"/>').html('<div class="pattern"></div>'), // Stripes
          $pane3 = $('<div class="intro-pane"/>').css({backgroundColor: '#1d1d1d'}); // Dark grey
      
      $wrapper.css({overflow: 'hidden'});
      on_resize();
      init();
              
      function init(){
        
        $pane3.prependTo($entry);
        $pane2.prependTo($entry);
        $pane1.prependTo($entry);
        
        // Do the resize to get the splash proportioned correctly.
        $win.bind('resize', on_resize);
        
        $a.click(function(e){
          
          // Omniture ***
          var result = $.AutoTracker.v();
          result['pageName'] += '>splash>button>continue';
          $.tracker.track(result['pageName'], result['props']);
          
          $scroll.scrollTop(GLOBAL_IS_MOBILE ? 1 : 0);
          _entered = true;
          $win.unbind('resize', on_resize);
          
          var inc = 300,
              dur = 800,
              delay = 0,
              winH = $win.height(),
              ease = 'easeInExpo',
              finalEase = 'easeInOutExpo';
          
          $preroll.animate({top: -$win.height()}, dur, ease);
          
          $.doTimeout(200, function(){
            $a.animate({bottom: -$a.height()}, 600, 'easeInOutExpo');
          });
          
          delay += inc;
          $.doTimeout(delay, function(){ $pane3.animate({top: -winH}, dur, ease); });
          
          delay += inc;
          $.doTimeout(delay, function(){ $pane2.animate({top: -winH}, dur, ease); });
          
          delay += inc*2;
          $.doTimeout(delay, function(){
            $pane1.animate({top: -winH}, dur, finalEase);
            $wrapper.css({top: winH}).animate({top: 0}, dur, finalEase, function(){
              $entry.detach();
              $wrapper.css({overflow: 'auto', height:'auto', position: 'static'});
              if(GLOBAL_IS_MOBILE) {
                revealBackButton();
              }
            });
            
            if(!GLOBAL_IS_MOBILE) {
              $.doTimeout(dur * .5, revealBackButton);
            }
            
          });
          
          e.preventDefault();
          $a.unbind('click');
          
        }); // End click() bind
        
      }; // End init()
      
      function revealBackButton(){
        $backButton.css({display: 'block'});
        
        if(GLOBAL_IS_MOBILE) {
          
          $backButton.css({position:'absolute', top: $wrapper.outerHeight() - $backButton.height()});
          $backLink.click(onBackLinkClick);
          
        } else {
          
          $backLink
            .css({bottom: -$backLink.height()})
            .animate({bottom:0}, 600, 'easeInOutExpo', function(){
              $backLink.click(onBackLinkClick);
            });
        }
      };
      
      function onBackLinkClick(e) {
        // Omniture ***
        var result = $.AutoTracker.v();
        result['pageName'] += '>button>back_to_feature';
        $.tracker.track(result['pageName'], result['props']);
        
        if(GLOBAL_IS_MOBILE) {
          
          // Reset everything.
          _entered = false;
          e.preventDefault();
          $backLink.unbind('click');
          $scroll.scrollTop(1);
          $wrapper.css({overflow: 'hidden', position: 'fixed', top: 0});
          $wrapper.css({height: $win.height() + 'px'});
          $entry.prependTo($body);
          $pane1.css({top: 0});
          $pane2.css({top: 0});
          $pane3.css({top: 0});
          $preroll.css({top: 0});
          $a.animate({bottom: 0}, 600, 'easeInOutExpo');
          init();
    
        } else {
          
          var inc = 300,
              dur = 800,
              delay = 0,
              winH = $win.height(),
              ease = 'easeInExpo',
              finalEase = 'easeInOutExpo';
          _entered = false;

          // Get the panels and the preroll off-screen.
          $pane1.css({top: winH});
          $pane2.css({top: winH});
          $pane3.css({top: winH});
          $preroll.css({top: winH});

          on_resize();

          $entry.prependTo($body);

          if(!GLOBAL_IS_MOBILE) {
            $.doTimeout(200, function(){
              $backLink.animate({bottom: -$backLink.height()}, 600, 'easeInOutExpo');
            });
          }

          $pane1.animate({top: 0}, dur, ease);

          delay += inc;
          $.doTimeout(delay, function(){ $pane2.animate({top: 0}, dur, ease); });

          delay += inc;
          $.doTimeout(delay, function(){ $pane3.animate({top: 0}, dur, ease); });

          delay += inc * 2;
          $.doTimeout(delay, function(){
            $preroll.animate({top: 0}, dur, finalEase);
            $wrapper.css({overflow: 'hidden', height: winH + 'px', position: 'fixed', top: 0});
            $.doTimeout(dur * .5, function(){
              $a.animate({bottom: 0}, 600, 'easeInOutExpo', function(){
                $scroll.scrollTop(0);
                init();
              });
            });
          });

          e.preventDefault();
          $backLink.unbind('click');
          
        }
      }; // End onBackLinkClick()
      
      function on_resize(){
                    
        if(!_entered) {
          var win_w = $win.width(),
              win_h = $win.height();
        
          // Make the wrapper's content hidden and height be the window height.
          if($wrapper.css('overflow') == 'hidden')
            $wrapper.css({height: win_h});
        
          // Basic idea is resize the image to fit.
          // First scale based on the width.
          $cta.css({ 
                    top: Math.floor((win_h - _ctaHeight) / 2.5)
                    });
          var dest_w = win_w;
          var dest_h = dest_w * ($big_img_h / $big_img_w);
          if(dest_h < win_h) {
            // need to scale it back up.
            dest_h = win_h;
            dest_w = dest_h * ($big_img_w / $big_img_h);
          }
        
          $big_img.attr('width', dest_w);
          $big_img.attr('height', dest_h);
        
          // Offset the margin.
          if(dest_w > win_w) {
            $big_img.css({marginLeft: Math.floor((dest_w - win_w) / -2)});
          } else {
            $big_img.css({marginLeft: 0});
          }
          if(dest_h > win_h) {
            $big_img.css({marginTop: Math.floor((dest_h - win_h) / -2)});
          } else {
            $big_img.css({marginTop: 0});
          }
        
        }
        
      }; // End on_resize()
      
    }); // End jQuery.each() loop
      
  }; // End jQuery.Entry plugin

})(jQuery);


/* ---------------------------------- */

/* @Shell */

;(function($) {

  $.fn.SHELL = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 

              
      });
      
  }//NIKE
    
  

})(jQuery);   


/* ---------------------------------- */

/* @Preload */

;(function($) {

  $.fn.Preload = function(settings) {

    var config = {};

    if (settings) $.extend(config, settings);

    this.each(function() { 

      var $self = $(this),
          $img = $self.find(config.image),
          $preload = $('<img/>');

      $self.addClass('_preload');
      
      $img.css({opacity:0});
      $preload.one('load', function() {
          $self.removeClass('_preload');
          $img.animate({opacity:1},500,'easeInOutQuart', function(){
            if($.browser.msie) {
              // $img.css({filter:'none'});
            }
          });
        })
      .attr('src',$img.attr('src'));

    });

  }//NIKE

})(jQuery);   

/* ---------------------------------- */

/* @Search */

;(function($) {

  $.fn.Search = function(settings) {
     
    var config = {};
 
    if (settings) $.extend(config, settings);
  
      this.each(function() { 

        var $self = $(this),
            $input = $self.find('input'),
            $body = $('body').addClass('_search'),
            $content =  $('[data-parent=Search]'),
            $autocomplete = $self.find('.autocomplete'),
            $auto = { faux: $self.find('.search-auto .faux') , complete: $self.find('.search-auto .complete') },
            _keywords_loaded = false,
            _searching = false,
            _keywords = new Array();

        $input.val('');
        $input.focus();

        //AUTOCOMPLETE
        init();

        $input.bind('focus',on_focus);
        $input.bind('keydown',on_key);
        // AUTOCOMPLETE
        $input.bind('keyup',on_key_up);

        /* ---------------------------------- */
         
        function init() {

          _keywords = global_search_tags;

          $input.val('');
          $input.focus();

          if ($.browser.webkit)
            $autocomplete.css({marginTop:7});

        } 
        
        function _is_empty(val)
        {
          var re = /^\s{1,}$/g; //match any white space including space, tab, form-feed, etc.
          if ((val.length==0) || (val==null) || (val=='') || ((val.search(re)) > -1)) {
            return true;
          }
          return false;
        }
         
        function on_key(e) {
        
          var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    		  
          switch(key) {
            
            case 13: //enter
              
              if ( _match($input.val(),true) ) {
              
                $input.val( _match( $input.val() ) );
                
                _autocomplete($input.val());
                
              }
              
              // Only submit search if the query isn't empty.
              if(!_is_empty($input.val()))
                _search($input.val());
              
              e.preventDefault();
              
            break;
            
            case 27: //esc
            
              $self.removeClass('active');
              e.preventDefault();
            
            break;
            
            default:
            
              
              
            break;
            
            
            
          }
        
        }
        
        function _match(temp_string,check) {
        
            for (var i=0;i<_keywords.length;i++) {
                
                var keyword = _keywords[i].toUpperCase();
                
                if (keyword.indexOf(temp_string.toUpperCase()) === 0 && temp_string.length>0) {
                  
                  return check ? true : _keywords[i];
                }
                
              }
              
            return false;
        
        }
        
        function _autocomplete(temp_string) {
        
           var pos = $input.val().length;
                
           $auto.faux.html(temp_string.split(' ').join('&nbsp;')).css({opacity:0});
                
           $auto.complete.html( _match(temp_string).substring(pos,_match(temp_string).length).split(' ').join('&nbsp;') ).css({opacity:.25});
        
        }
        
        function on_key_up(e) {
        
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
              
              var character = String.fromCharCode(key);
              
              var temp_string = $input.val();// + character;
              
              if (_match(temp_string,true)) {
              
                _autocomplete(temp_string);
              
                
              } else {
              
                $auto.faux.html('');
                
                $auto.complete.html('');
                
              }
          
        
        }
        

        function on_focus() {

          $self.removeClass('active');

          // This causes recursion
          // $input.focus();
        }
        
        
        function _search($terms) {
          // Omniture
          var props = $.AutoTracker.v()['props'];
          var pageName = 'search>submit';
          props['events']= 'event2';
          props['prop11'] = $terms;
          props['eVar11'] = $terms;
          props['prop19'] = 'search';
          $.tracker.track(pageName, props);
          
          var queryUrl = $.Paths.BASE + 'search/query/request/ajax';

          $.ajax({
            dataType: 'json',
            beforeSend: _before_send,
            error: _on_error,
            success: _on_success,
            type: 'POST',
            data:{
              xmlhttp: true,
              terms: $terms
            },
            url: queryUrl
          });

        }
        
        function _before_send() {
        
          $input.blur();
          
          $self
          .addClass('active')
          .addClass('searching');
          
        }
        
        function _on_error() {
          // alert('ERROR');
        }
        
        function _on_success(response) {
        
          
          $self
          .removeClass('searching');
          
           if ($.browser.msie)
            $content.html( $(innerShiv(response.searchresults), false) );
          else
            $content.html(response.searchresults);
          
          if($.browser.msie)
            $content.find('section.container').each(function(){ $(this).css({backgroundColor:'#FFF'}); });
          $content.find('section.container').each(function(i){$(this).css({opacity:0}).animate({opacity:0},125*i).animate({opacity:1},450,'easeInOutQuart')});
          
          // Omniture
          var props = $.AutoTracker.v()['props'];
          var pageName = 'search>results';
          props['prop17'] = 'search: results';
          props['prop19'] = 'search: results';
          // Check to see if we have a no results search-alert element.
          var noResults = $content.find('.search-alert');
          if(noResults.length > 0) {
            props['prop10'] = $input.val();
          }
          $.tracker.track(pageName, props);
          
          // Scroll back up to the top.
          $body.triggerHandler($.Events.SCROLLTO, 0);
        
        }
              
      });
      
  }//NIKE
    
  

})(jQuery);  

/* ---------------------------------- */

/* @BlankLink */

;(function($) {

  
   $.fn.BlankLink = function() {
   
     this.each(function() { 
      
        var $self = $(this);
            
        $self
        .attr('target','_blank')
        .bind('click',on_click);
        
        function on_click(e){
        
        }
            
     });
     
    }
    
   
    
})(jQuery);

/* ---------------------------------- */

/* @serverTime */

;(function($) {
    
    $.serverTime = (function() {
        
        var _globalStartDate = new Date(),
		    _pageStartDate = new Date();
        
        // We're looking for a GLOBAL_START_TIME variable, in the format of HH:MM:SS
        if(window.GLOBAL_START_TIME) {
          var gPieces = GLOBAL_START_TIME.split(':');
      		var gHH = gPieces[0];
      		var gMM = gPieces[1];
      		var gSS = gPieces[2];
      		_globalStartDate.setUTCHours(parseInt(gHH, 10));
      		_globalStartDate.setUTCMinutes(parseInt(gMM, 10));
      		_globalStartDate.setUTCSeconds(parseInt(gSS, 10));
        }
        
        return {
          now: function() {
  		      var nowDate = new Date();
    				var diff = nowDate.getTime() - _pageStartDate.getTime();
    				var nowServer = new Date();
    				nowServer.setTime(_globalStartDate.getTime() + diff);
    				var nowTime = this.getDateAsTimestamp(nowServer);
    				return nowTime;
          },
          getPageStartDate: function() {
              return _pageStartDate;
          },
          getServerStartDate: function() {
              return _globalStartDate;
          },
          getDateAsTimestamp: function(theDate) {
    			  var dHH = theDate.getUTCHours();
      			var theDateHH = dHH < 10 ? '0' + dHH : dHH.toString();
      			var dMM = theDate.getUTCMinutes();
      			var theDateMM = dMM < 10 ? '0' + dMM : dMM.toString();
      			var dSS = theDate.getUTCSeconds();
      			var theDateSS = dSS < 10 ? '0' + dSS : dSS.toString();
      			return theDateHH+':'+theDateMM+':'+theDateSS;
          }
        };
        
    })();
    
}(jQuery));

/* ---------------------------------- */

/* @SiteModel */

;(function($) {

  $.SiteModel = (function() {
    var _section = '',
    _subsection = '',
    _detailName = '',
    _detailID = '',
    _galleryName = '',
    _galleryID = '',
    _mediaType = '',
    _mediaID = '',
    _category = '',
    _filter = '',
    _view = '';

    return {
      MEDIA_IMAGE: 'image',
      MEDIA_VIDEO: 'video',
      SECTION_HOME: 'home',
      // Define the section constants
      SECTION_PRODUCTS: 'products',
      SECTION_TEAM: 'team',
      SECTION_FAMILY: 'family',
      SECTION_NEWS: 'news',
      SECTION_ARCHIVE: 'archive',
      SECTION_SEARCH: 'search',
      SECTION_STORE_LOCATOR: 'store_locator',
      SECTION_GIVEAWAY: 'giveaway',
      SECTION_VIDEO: 'video',
      SECTION_GALLERY: 'gallery',
      SECTION_FEATURES: 'feature',
      // Define all public methods
      reset: function(){
        _section = '';
        _subsection = '';
        _detailName = '';
        _detailID = '';
        _galleryName = '';
        _galleryID = '';
        _mediaType = '';
        _mediaID = '';
        _category = '';
        _filter = '';
        _view = '';
      },
      /*
      Figures out the state of the SiteModel based on the current URI.
      */
      update: function(){
        // Snag the URI and parse it.
        // Get the segment paths first:
        var path = window.location.pathname.toString();
        var hash = window.location.hash.toString();
        // Hash will == '' if not present.
        // Figure out if we're prefixed with /web
        if(path.indexOf('/web') > -1) {
          path = path.split('/web')[1];
        }
        // Now separate out the segments, taking off the leading / and trailing /
        if(path.charAt(0) == 'index.html') {
          path = path.substr(1, path.length - 1);
        }
        if(path.charAt(path.length - 1) == 'index.html') {
          path = path.substr(0, path.length - 1);
        }
        var section = '',
        subsection = '',
        segments = [],
        hashSegments = [],
        values = {},
        hashValues = {},
        haveValues = false,
        haveHashValues = false;
        if(path != '') {
          segments = path.split('index.html');
        }
        // Logic for figuring out the segments is this:
        // segment 1 = section
        // segment 2 = subsection
        // Additional segments are name value pairs.
        if(segments.length == 0) {
          section = this.SECTION_HOME;
        } else {
          section = segments[0];
        }
        this.setSection(section);
        if(segments.length > 1) {
          subsection = segments[1];
          this.setSubsection(subsection);
        }
        // Now determine the name/value pair mapping.
        if(segments.length > 2) {
          var valuesTemp = segments.slice(2);
          for(var i=0; i<valuesTemp.length; i+=2) {
            values[valuesTemp[i]] = valuesTemp[i+1];
          }
          haveValues = true;
        }
        // Now let's parse the hash values, if there are any.
        if(hash != '') {
          // Get rid of the hash and any leading slashes.
          if(hash.charAt(0) == '#') {
            hash = hash.substr(1, hash.length - 1);
          }
          if(hash.charAt(0) == 'index.html') {
            hash = hash.substr(1, hash.length - 1);
          }
          // Now see if we still have value.
          if(hash != '') {
            var hashValuesTemp = hash.split('index.html');
            for(var i=0; i<hashValuesTemp.length; i++) {
              var hashNameValPair = hashValuesTemp[i].split(':');
              hashValues[hashNameValPair[0]] = hashNameValPair[1];
            }
            haveHashValues = true;
          }
        }
        // Now start populating our SiteModel
        if(haveValues == true) {
          if(typeof values['id'] != 'undefined') {
            this.setDetailID(values['id']);
          }
          if(typeof values['name'] != 'undefined') {
            this.setDetailName(values['name']);
          }
          if(typeof values['title'] != 'undefined') {
            this.setDetailName(values['title']);
          }
        }
        if(haveHashValues == true) {
          if(typeof hashValues['section'] != 'undefined') {
            this.setCategory(hashValues['section']);
          }
          if(typeof hashValues['view'] != 'undefined') {
            this.setView(hashValues['view']);
          }
          if(typeof hashValues['filter'] != 'undefined') {
            this.setFilter(hashValues['filter']);
          }
        }
      },
      getSection: function(){
        return _section;
      },
      setSection: function(s){
        _section = s;
      },
      getSubsection: function(){
        return _subsection;
      },
      setSubsection: function(s){
        _subsection = s;
      },
      getDetailName: function(){
        return _detailName;
      },
      setDetailName: function(n){
        _detailName = n;
      },
      getDetailID: function(){
        return _detailID;
      },
      setDetailID: function(id){
        _detailID = id;
      },
      getGalleryName: function(){
        return _galleryName;
      },
      setGalleryName: function(n){
        _galleryName = n;
      },
      getGalleryID: function(){
        return _galleryID;
      },
      setGalleryID: function(id){
        _galleryID = id;
      },
      getMediaType: function(){
        return _mediaType;
      },
      setMediaType: function(t){
        _mediaType = t;
      },
      getMediaID: function(){
        return _mediaID;
      },
      setMediaID: function(id){
        _mediaID = id;
      },
      getCategory: function(){
        return _category;
      },
      setCategory: function(c){
        _category = c;
      },
      getFilter: function(){
        return _filter;
      },
      setFilter: function(f){
        _filter = f;
      },
      getView: function(){
        return _view;
      },
      setView: function(v) {
        _view = v;
      },
      debug: function(){
        /*
        debug.log("SiteModel :: END DEBUG OUTPUT ------------");
        debug.log("section ["+this.getSection()+"] | subsection ["+this.getSubsection()+"]");
        debug.log("detail name ["+this.getDetailName()+"] | detail ID ["+this.getDetailID()+"]");
        debug.log("gallery name ["+this.getGalleryName()+"] | gallery ID ["+this.getGalleryID()+"]");
        debug.log("media type ["+this.getMediaType()+"] | media ID ["+this.getMediaID()+"]");
        debug.log("category ["+this.getCategory()+"]");
        debug.log("SiteModel :: END DEBUG OUTPUT ------------");
        */
      }
    };
  })();
  
}(jQuery));

/* ---------------------------------- */

/* @AutoTracker */

;(function($){
	
	/* --------------------------------------------------

  	AutoTracker tracks pageViews based on SiteModel
  	state values. Always make sure the SiteModel is
  	correct before calling the t() method.

    -------------------------------------------------- */
	$.AutoTracker = ( function() {
		
		var _determineGridOrBrowse = function(){
			if ($.SiteModel.getView() != '') {
				if($.SiteModel.getView().toLowerCase() == 'grid') {
					return 'product grid';
				} else {
					return 'browse list';
				}
			}
			return '';
		};
		
		// Declare public methods.
		return {
			/* v() gets the values that would be sent to the tracker */
			v: function() {
				var returnObj = {},
					props = {},
					prop18 = $.SiteModel.getSection(),
					prop19 = '',
					prop17 = '',
					pageName = '';

				if($.SiteModel.getSubsection() == '') {
					// We're on a landing screen.
					switch($.SiteModel.getSection()) {
						case $.SiteModel.SECTION_HOME:
							prop19 = $.SiteModel.SECTION_HOME;
							break;
						case $.SiteModel.SECTION_PRODUCTS:
							break;
						case $.SiteModel.SECTION_ARCHIVE:
							prop19 = 'archive_landing';
							break;
						case $.SiteModel.SECTION_TEAM:
							prop19 = 'team_landing';
							break;
						case $.SiteModel.SECTION_FAMILY:
							prop19 = 'family_landing';
							break;
						case $.SiteModel.SECTION_NEWS:
							prop19 = 'news_landing';
							break;
						case $.SiteModel.SECTION_GIVEAWAY:
							break;
						case $.SiteModel.SECTION_SEARCH:
							prop19 = 'search';
							break;
						case $.SiteModel.SECTION_STORE_LOCATOR:
							prop19 = 'store_locator';
							break;
					}
				} else {
					switch($.SiteModel.getSection()) {
						case $.SiteModel.SECTION_HOME:
							prop19 = $.SiteModel.SECTION_HOME;
							break;
						case $.SiteModel.SECTION_PRODUCTS:
							prop19 = 'product_detail';
							break;
						case $.SiteModel.SECTION_ARCHIVE:
							prop19 = 'archive_landing';
							break;
						case $.SiteModel.SECTION_TEAM:
							prop19 = 'team_detail';
							// Figure out the team member's name here.
							if($.SiteModel.getDetailName() != '') {
								prop19 += '>' + $.SiteModel.getDetailName();
							}
							break;
						case $.SiteModel.SECTION_FAMILY:
							prop19 = 'family_detail';
							// Figure out the family member's name here.
							if($.SiteModel.getDetailName() != '') {
								prop19 += '>' + $.SiteModel.getDetailName();
							}
							break;
						case $.SiteModel.SECTION_VIDEO:
							prop19 = 'video_landing';
							break;
						case $.SiteModel.SECTION_GALLERY:
							prop19 = 'gallery_landing';
							break;
						case $.SiteModel.SECTION_NEWS:
							prop19 = 'news_item';
							break;
						case $.SiteModel.SECTION_GIVEAWAY:
							break;
						case $.SiteModel.SECTION_SEARCH:
							prop19 = 'search';
							break;
						case $.SiteModel.SECTION_STORE_LOCATOR:
							prop19 = 'store_locator';
							break;
						case $.SiteModel.SECTION_FEATURES:
						  prop18 = 'experience';
						  prop19 = $.SiteModel.getSubsection();
						  break;
					}
				} // End if / else for prop19

				// Now see what sort of page type we're on for prop17.
				switch($.SiteModel.getSection()) {
					case $.SiteModel.SECTION_HOME:
						prop17 = $.SiteModel.SECTION_HOME;
						break;
					case $.SiteModel.SECTION_ARCHIVE:
						prop17 = 'landing';
						break;
					case $.SiteModel.SECTION_PRODUCTS:
					case $.SiteModel.SECTION_TEAM:	
					case $.SiteModel.SECTION_FAMILY:
					case $.SiteModel.SECTION_NEWS:
					case $.SiteModel.SECTION_VIDEO:
					case $.SiteModel.SECTION_GALLERY:
						if($.SiteModel.getSubsection() == '') {
							prop17 = 'landing';
						} else {
							prop17 = 'detail page';
						}
						break;
					case $.SiteModel.SECTION_GIVEAWAY:
						switch($.SiteModel.getSubsection()) {
							case '':
								prop17 = 'landing';
								break;
							case 'login':
							case 'signup':
							case 'signup_success':
								prop17 = 'upm';
								break;
							case 'rules':
								prop17 = 'legal';
								break;
							case 'entered':
								prop17 = 'confirmation page';
								break;
						}
						break;
					case $.SiteModel.SECTION_SEARCH:
						prop17 = 'search';
						break;
					case $.SiteModel.SECTION_STORE_LOCATOR:
						prop17 = 'landing';
						break;
					case $.SiteModel.SECTION_FEATURES:
					  prop17 = 'experience';
					  break;
				} // End switch statement for prop17

				// Determine the pageName.
				pageName = $.SiteModel.getSection();
				if($.SiteModel.getSubsection() == '') {
					// Now check to see if we need to track any detail INLINE pages.
					switch($.SiteModel.getSection()) {
						case $.SiteModel.SECTION_HOME:
							
						break;
						case $.SiteModel.SECTION_PRODUCTS:
							if($.SiteModel.getDetailID() != '') {
								pageName += '>detail>inline>' + $.SiteModel.getDetailID() + '>' + $.SiteModel.getDetailName();
								prop17 = 'inline content';
								prop19 = 'product_detail';
							}
						break;
						case $.SiteModel.SECTION_TEAM:
							// Team doesn't have inline content, but it could have a deep link to a category. Though we don't care.
						break;
						case $.SiteModel.SECTION_ARCHIVE:
							// Need to check categories or grid size.
							if($.SiteModel.getCategory() != '') {
								pageName += '>category>' + $.SiteModel.getCategory().toLowerCase();
								prop19 = $.SiteModel.getCategory().toLowerCase();
							} else if ($.SiteModel.getView() != '') {
								pageName += '>grid>' + $.SiteModel.getView().toLowerCase();
							}
						break;
						case $.SiteModel.SECTION_FAMILY:
							// Family doesn't have inline content.
						break;
						case $.SiteModel.SECTION_SEARCH:
							// Search doesn't have any inline content.
						break;
						case $.SiteModel.SECTION_NEWS:
							if($.SiteModel.getDetailID() != '') {
								prop17 = 'inline content';
								prop19 = 'news_item';
								pageName += ">item>inline>" + $.SiteModel.getDetailID() + ">" + $.SiteModel.getDetailName();
							}
						break;
						case $.SiteModel.SECTION_STORE_LOCATOR:
							// Store locator doesn't have inline content.
							// But it does have a different prop23.
							props['prop23'] = 'tools';
						break;
						case $.SiteModel.SECTION_GIVEAWAY:
							// Giveaway doesn't have inline conent.
						break;
						case $.SiteModel.SECTION_VIDEO:
							// Video section doesn't have an index landing
						break;
						case $.SiteModel.SECTION_GALLERY:
							// Gallery section doesn't have an index landing
						break;
					}
				} else {
					// Track all detail pages (deep links)
					switch($.SiteModel.getSection()) {
						case $.SiteModel.SECTION_PRODUCTS:
							pageName += '>detail>page>' + $.SiteModel.getDetailID() + '>' + $.SiteModel.getDetailName();
							prop19 = 'product_detail';
						break;
						case $.SiteModel.SECTION_TEAM:
							pageName += '>detail>' + $.SiteModel.getDetailID() + '>' + $.SiteModel.getDetailName();
						break;
						case $.SiteModel.SECTION_ARCHIVE:
							// No archive deep links.
						break;
						case $.SiteModel.SECTION_FAMILY:
							pageName += '>detail>' + $.SiteModel.getDetailID() + '>' + $.SiteModel.getDetailName();
						break;
						case $.SiteModel.SECTION_SEARCH:
							// No search deep links.
						break;
						case $.SiteModel.SECTION_NEWS:
							pageName += ">item>page>" + $.SiteModel.getDetailID() + ">" + $.SiteModel.getDetailName();
						break;
						case $.SiteModel.SECTION_STORE_LOCATOR:
							// Store locator doesn't have detail pages.
						break;
						case $.SiteModel.SECTION_GIVEAWAY:
							switch($.SiteModel.getSubsection()) {
								case 'login':
									pageName += ">upm>login";
									props['prop23'] = 'tools';
									break;
								case 'signup':
									pageName += ">upm>signup";
									props['prop23'] = 'tools';
									break;
								case 'signup_success':
									pageName += ">upm>signup_success";
									props['prop23'] = 'tools';
									props['events'] = 'event5';
									break;
								case 'rules':
									pageName += ">rules";
									break;
								case 'entered':
									pageName += ">entered";
									break;
							}
						  break;
						case $.SiteModel.SECTION_VIDEO:
							pageName += ">" + $.SiteModel.getDetailID() + ">" + $.SiteModel.getDetailName() + ">deeplinked_page";
						  break;
						case $.SiteModel.SECTION_GALLERY:
							pageName += ">" + $.SiteModel.getDetailID() + ">" + $.SiteModel.getDetailName();
						  break;
						case $.SiteModel.SECTION_FEATURES:
						  pageName = "experience>" + $.SiteModel.getSubsection();
						  break;
					}
				} // End if/else on SiteModel subsection check.
				
				if(prop17 != '')
					props['prop17'] = prop17;
				if(prop18 != '')
					props['prop18'] = prop18;
				if(prop19 != '')
					props['prop19'] = prop19;
					
				returnObj['pageName'] = pageName;
				returnObj['props'] = props;
				return returnObj;
			},
			/* t() auto-tracks based on URI and SiteModel */
			t: function() {
				var trackerObj = this.v();
				$.tracker.track(trackerObj['pageName'], trackerObj['props']);
			}
		};
		
	})();
	
}(jQuery));

/* ---------------------------------- */

/* @LinkTracking*/

;(function($) {

  /**
    Tracks page automatically
    adding a delay between tracking the event and following the link.
    Looks for <a> tags with data-link-track attributes.
  */
  $.fn.LinkTracking = function(settings) {
     
    var config = {};
    if (settings)
      $.extend(config, settings);
    
    this.each(function() {
      var $self = $(this),
          $body = $('body'),
          _href = $self.attr('href'),
          _data = $self.attr('data-link-track'),
          _dataPieces = _data.split(';'),
          _data = {};
      if(_href.indexOf(window.location.host) < 0) {
        $self.attr('target', '_blank');
      }
      for(var i = 0; i < _dataPieces.length; i++) {
        var parts = _dataPieces[i].split(':');
        _data[parts[0]] = parts[1];
      }
      var pageName = _data['pageName'];
      var events = '';
      if(typeof _data['events'] != 'undefined') {
        events = _data['events'];
      }
      var props = $.AutoTracker.v()['props'];
      if(events != '') {
        props['events'] = events;
      }
      if(typeof _data['props'] != 'undefined') {
        // Format looks like this:
        // props:prop1=some_val,eVar3=another_val;
        var parts = _data['props'].split(',');
        for(var i = 0; i < parts.length; i++)
        {
          var nvpair = parts[i];
          var nvpairParts = nvpair.split('=');
          props[nvpairParts[0]] = nvpairParts[1];
        }
      }
      $self.bind('click',on_click);
      
      function on_click(e){
        $.tracker.track(pageName, props);
        if(_href.indexOf(window.location.host) >= 0) {
            $.doTimeout( 750, function(){
              window.location = _href;
            });
            if(typeof e != 'undefined')
              e.preventDefault();
        }
      }

    });

  };
    
})(jQuery);

/* ---------------------------------- */

/* @ShareTracking */

;(function($) {

  $.fn.ShareTracking = function(settings) {
     
    var config = {};
    if (settings)
      $.extend(config, settings);
    
    this.each(function() {
      var $self = $(this),
          _href = $self.attr('href'),
          _type = $self.attr('data-type');
          
      $self.attr('target', '_blank');
      var result = $.AutoTracker.v();
      result['pageName'] += '>share>' + _type;
      $self.bind('click', on_click);
      
      function on_click(e){
        $.tracker.track(result['pageName'], result['props']);
      }

    });

  };
    
})(jQuery);

/* ---------------------------------- */

/* @ProductStoreTracking */

;(function($) {

  $.fn.ProductStoreTracking = function(settings) {
     
    var config = {};
    if (settings)
      $.extend(config, settings);
    
    this.each(function() {
      var $self = $(this),
          _href = $self.attr('href'),
          _type = $self.attr('data-type');
      
      var result = $.AutoTracker.v();
      result['pageName'] += '>link>store_locator';
      result['props']['events'] = 'event7';
      $self.bind('click', on_click);
      
      function on_click(e){
        $.tracker.track(result['pageName'], result['props']);
        $.doTimeout( 750, function(){
          window.location = _href;
        });
        e.preventDefault();
      }

    });

  };
    
})(jQuery);

/* ---------------------------------- */

/* @FeatureTracking */

;(function($) {
  
  /**
   * Tracks the masthead feature clicks on Home / Products
   */
  $.fn.FeatureTracking = function(settings) {
     
    var config = {};
    if (settings) {
      $.extend(config, settings);
    }
    this.each(function() {
      
      var $self = $(this),
          $links = $self.find('a[data-feature-track]');
      
      $links.each(function(){
        var $link = $(this),
            _href = $link.attr('href'),
            data = $link.attr('data-feature-track'),
            featureName = '',
            buttonName = '';
          
        var dataParts = data.split(';');
        for(var i = 0; i < dataParts.length; i++){
          var segParts = dataParts[i].split(':');
          switch(segParts[0])
          {
            case 'name':
              featureName = segParts[1];
              break;
            case 'button':
              buttonName = segParts[1];
              break;
          }
        }
        var result = $.AutoTracker.v();
        result['pageName'] += '>feature>' + featureName + '>' + buttonName;
        result['props']['eVar13'] = 'pageName'; // tracking plugin takes care of assignment.
        if($.SiteModel.getSection() == $.SiteModel.SECTION_HOME) {
          result['props']['prop3'] = 'pageName'; // tracking plugin takes care of assignment.
        }
        $link.bind('click', on_click);

        function on_click(e){
          $.tracker.track(result['pageName'], result['props']);
          $.doTimeout( 750, function(){
            window.location = _href;
          });
          e.preventDefault();
        }
      }); // end links each() loop

    }); // end main each() loop

  };
    
})(jQuery);

/* ---------------------------------- */

/* @HomeTracking */

;(function($) {

  /**
   * Tracks the masthead feature clicks on Home / Products
   */
  $.fn.HomeTracking = function(settings) {
    
    var config = {};
    if (settings) {
      $.extend(config, settings);
    }
    
    this.each(function() {
      
      var $self = $(this),
          _href = $self.attr('href'),
          data = $self.attr('data-home-track'),
          featureName = '',
          buttonName = '';
      
      var dataParts = data.split(';');
      for(var i = 0; i < dataParts.length; i++){
        var segParts = dataParts[i].split(':');
        switch(segParts[0])
        {
          case 'name':
            featureName = segParts[1];
            break;
          case 'button':
            buttonName = segParts[1];
            break;
        }
      }
      var result = $.AutoTracker.v();
      result['pageName'] += '>splash>feature>' + featureName + '>' + buttonName;
      result['props']['eVar13'] = 'pageName'; // tracking plugin takes care of assignment.
      result['props']['prop3'] = 'pageName'; // tracking plugin takes care of assignment.
      $self.bind('click', on_click);

      function on_click(e){
        $.tracker.track(result['pageName'], result['props']);
        $.doTimeout( 750, function(){
          window.location = _href;
        });
        e.preventDefault();
      }

    }); // end main each() loop

  };
    
})(jQuery);


